Skip to content

Commit 4c804e6

Browse files
client: Use serde_bytes
As otherwise serde would serialize every byte individually, it has a huge impact particularly on large keyrings.
1 parent e14fa9f commit 4c804e6

8 files changed

Lines changed: 22 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ rust-version = "1.85"
2424
exclude = ["org.freedesktop.Secrets.xml"]
2525

2626
[workspace.dependencies]
27-
zvariant = { version = "5.8", default-features = false, features = ["gvariant"]}
27+
zvariant = { version = "5.8", default-features = false, features = ["gvariant", "serde_bytes"]}
2828
ashpd = {version = "0.12", default-features = false}
2929
endi = "1.1"
3030
clap = { version = "4.5", features = [ "cargo", "derive" ] }

client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ openssl = { version = "0.10", optional = true }
3838
pbkdf2 = { version = "0.12", optional = true }
3939
rand = { version = "0.9", default-features = false, features = ["thread_rng"] }
4040
serde.workspace = true
41+
serde_bytes = "0.11"
4142
sha2 = { version = "0.10", optional = true }
4243
subtle = { version = "2.5", optional = true }
4344
tokio = { workspace = true, features = [

client/src/dbus/api/secret.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use crate::{Key, Secret, crypto, dbus::Error, secret::ContentType};
1212
/// Same as [`DBusSecret`] without tying the session path to a [`Session`] type.
1313
pub struct DBusSecretInner(
1414
pub OwnedObjectPath,
15+
#[serde(with = "serde_bytes")]
1516
pub Vec<u8>,
17+
#[serde(with = "serde_bytes")]
1618
pub Vec<u8>,
1719
pub ContentType,
1820
);
@@ -104,8 +106,8 @@ impl Serialize for DBusSecret {
104106
{
105107
let mut tuple_serializer = serializer.serialize_tuple(4)?;
106108
tuple_serializer.serialize_element(self.session().inner().path())?;
107-
tuple_serializer.serialize_element(self.parameters())?;
108-
tuple_serializer.serialize_element(self.value())?;
109+
tuple_serializer.serialize_element(&serde_bytes::Bytes::new(self.parameters()))?;
110+
tuple_serializer.serialize_element(&serde_bytes::Bytes::new(self.value()))?;
109111
tuple_serializer.serialize_element(self.content_type().as_str())?;
110112
tuple_serializer.end()
111113
}

client/src/file/api/encrypted_item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{Key, Mac, crypto};
99
#[derive(Deserialize, Serialize, Type, Debug, Clone)]
1010
pub(crate) struct EncryptedItem {
1111
pub(crate) hashed_attributes: HashMap<String, Mac>,
12+
#[serde(with = "serde_bytes")]
1213
pub(crate) blob: Vec<u8>,
1314
}
1415

client/src/file/api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub(crate) static GVARIANT_ENCODING: LazyLock<Context> =
7373
#[derive(Deserialize, Serialize, Type, Debug)]
7474
pub struct Keyring {
7575
salt_size: u32,
76+
#[serde(with = "serde_bytes")]
7677
salt: Vec<u8>,
7778
iteration_count: u32,
7879
modified_time: u64,

client/src/file/unlocked_item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct UnlockedItem {
2222
created: u64,
2323
#[zeroize(skip)]
2424
modified: u64,
25+
#[serde(with = "serde_bytes")]
2526
secret: Vec<u8>,
2627
}
2728

client/src/mac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use zbus::zvariant::Type;
77
/// A message authentication code. It provides constant-time comparison when
88
/// compared against another mac or against a slice of bytes.
99
#[derive(Deserialize, Serialize, Type, Clone)]
10-
pub struct Mac(Vec<u8>);
10+
pub struct Mac(#[serde(with = "serde_bytes")] Vec<u8>);
1111

1212
impl std::fmt::Debug for Mac {
1313
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

0 commit comments

Comments
 (0)