Skip to content

Commit 343ee5e

Browse files
committed
added fixes for windows and serde
Signed-off-by: Michael Lodder <redmike7@gmail.com>
1 parent 046290f commit 343ee5e

4 files changed

Lines changed: 26 additions & 5 deletions

File tree

.github/workflows/cryptex.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
toolchain: stable
2828
components: clippy
2929
- run: cargo clippy --no-default-features --features linux-secret-service -- -D warnings
30+
- run: cargo clippy --no-default-features --features serde -- -D warnings
3031
- run: cargo clippy --no-default-features --features file -- -D warnings
3132
- run: cargo clippy --no-default-features --features "linux-secret-service,file" -- -D warnings
3233

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ file = ["argon2", "chacha20poly1305", "dirs", "rusqlite"]
2727
linux-secret-service = ["secret-service", "uzers"]
2828
macos-keychain = ["security-framework", "security-framework-sys", "core-foundation", "core-foundation-sys", "uzers"]
2929
windows-credentials = ["windows"]
30+
serde = ["dep:serde", "postcard"]
3031

3132
[dependencies]
3233
clap = "4"
3334
colored = "3.0"
3435
hex = "0.4"
3536
rpassword = "7"
37+
postcard = { version = "1", features = ["use-std"] , optional = true }
3638
serde = { version = "1", optional = true }
3739
subtle = "2"
3840
whoami = "2"
@@ -60,6 +62,5 @@ windows = { version = "0.62", features = [
6062
"Win32_Foundation",
6163
"Win32_Security_Credentials",
6264
"Win32_Security_Cryptography",
63-
"Win32_Storage_FileSystem",
6465
], optional = true }
6566

src/keyring/keyringsecret.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::error::KeyRingError;
1313
#[cfg(feature = "serde")]
1414
use serde::{
1515
Deserialize, Deserializer, Serialize, Serializer,
16-
de::{Error as DError, Visitor},
16+
de::{DeserializeOwned, Error as DError, Visitor},
1717
};
1818
use zeroize::Zeroize;
1919

@@ -65,6 +65,21 @@ impl KeyRingSecret {
6565
pub fn is_empty(&self) -> bool {
6666
self.0.is_empty()
6767
}
68+
69+
#[cfg(feature = "serde")]
70+
pub fn from_serde<S: Serialize>(input: S) -> Result<Self, KeyRingError> {
71+
Ok(Self(
72+
postcard::to_stdvec(&input).map_err(|e| KeyRingError::from(e.to_string().as_str()))?,
73+
))
74+
}
75+
76+
#[cfg(feature = "serde")]
77+
pub fn to_serde<D: DeserializeOwned>(&self) -> Result<D, KeyRingError> {
78+
Ok(
79+
postcard::from_bytes(&self.0)
80+
.map_err(|e| KeyRingError::from(e.to_string().as_str()))?,
81+
)
82+
}
6883
}
6984

7085
impl PartialEq for KeyRingSecret {

src/keyring/sqlcipher.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,19 @@ fn get_keyring_file(in_path: Option<PathBuf>) -> PathBuf {
125125

126126
#[cfg(target_os = "windows")]
127127
fn make_hidden(path: &Path) {
128-
use ::windows::Win32::Storage::FileSystem::{FILE_ATTRIBUTE_HIDDEN, SetFileAttributesW};
129-
use ::windows::core::PCWSTR;
130128
use std::ffi::OsStr;
131129
use std::iter::once;
132130
use std::os::windows::ffi::OsStrExt;
133131

132+
const FILE_ATTRIBUTE_HIDDEN: u32 = 0x2;
133+
134+
unsafe extern "system" {
135+
fn SetFileAttributesW(lpfilename: *const u16, dwfileattributes: u32) -> i32;
136+
}
137+
134138
let wide: Vec<u16> = OsStr::new(path).encode_wide().chain(once(0)).collect();
135139
unsafe {
136-
let _ = SetFileAttributesW(PCWSTR(wide.as_ptr()), FILE_ATTRIBUTE_HIDDEN);
140+
SetFileAttributesW(wide.as_ptr(), FILE_ATTRIBUTE_HIDDEN);
137141
}
138142
}
139143

0 commit comments

Comments
 (0)