From a94718c14d4db0f1432d7d44072c7cf6bc7ab815 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sun, 16 Aug 2026 21:53:43 +0200 Subject: [PATCH] Port to zgvariant --- Cargo.lock | 32 +++++++++++++++++++++++++-- Cargo.toml | 7 +++--- client/Cargo.toml | 1 + client/src/file/api/encrypted_item.rs | 2 +- client/src/file/api/mod.rs | 8 +++---- client/src/file/error.rs | 6 ++--- client/src/file/unlocked_item.rs | 8 +++---- client/src/mac.rs | 2 +- 8 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9ca26de7..c53be2c79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1158,6 +1158,7 @@ dependencies = [ "zbus", "zbus_macros", "zeroize", + "zgvariant", "zvariant", ] @@ -2370,6 +2371,33 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "zgvariant" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60f1fd025a5215c4071378b7660d019b5588210c8645fb01f99fe30ecb382923" +dependencies = [ + "endi", + "serde", + "serde_bytes", + "winnow", + "zcheapstr", + "zgvariant_derive", + "zvariant_utils", +] + +[[package]] +name = "zgvariant_derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e85114cc9a835a222b21d5be18e488d7eb3c41a66c9be4ec9b9b58b94b9e5b8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", + "zvariant_utils", +] + [[package]] name = "zmij" version = "1.0.23" @@ -2407,9 +2435,9 @@ dependencies = [ [[package]] name = "zvariant_utils" -version = "4.0.0" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "629d80ece222cad20fe0e8741be493c4ab166acf3b85341bdc2cdbcfd8f3c2d6" +checksum = "6b84ebb462416c27cdb97f2e7f5f0ccc844da1fe2ecc7121e1b690b41318bf42" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index ff1682bd9..6bdd6c1c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,8 @@ tempfile = "3.26" tokio = { version = "1.52", default-features = false } tracing = "0.1" tracing-subscriber = "0.3" -zbus = { version = "5.14.0", default-features = false } -zbus_macros = { version = "5.11", features = ["gvariant"] } +zbus = { version = "5.19", default-features = false } +zgvariant = { version = "1.0", features = ["serde_bytes"] } +zbus_macros = { version = "5.19", features = ["gvariant"] } zeroize = { version = "1", features = ["zeroize_derive"] } -zvariant = { version = "5.8", default-features = false, features = ["gvariant", "serde_bytes"] } +zvariant = { version = "5.14", default-features = false, features = ["gvariant", "serde_bytes"] } diff --git a/client/Cargo.toml b/client/Cargo.toml index 52bb9e011..357b10bac 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -41,6 +41,7 @@ tokio = { workspace = true, features = [ "io-util", ], optional = true, default-features = false } tracing = { workspace = true, optional = true } +zgvariant.workspace = true zbus.workspace = true zbus_macros.workspace = true zvariant.workspace = true diff --git a/client/src/file/api/encrypted_item.rs b/client/src/file/api/encrypted_item.rs index c46128cbf..da9302c7b 100644 --- a/client/src/file/api/encrypted_item.rs +++ b/client/src/file/api/encrypted_item.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; -use zbus::zvariant::Type; use zeroize::{Zeroize, ZeroizeOnDrop}; +use zgvariant::Type; use super::{Error, UnlockedItem}; use crate::{AsAttributes, Key, Mac, crypto}; diff --git a/client/src/file/api/mod.rs b/client/src/file/api/mod.rs index cd73465a8..aedace5a5 100644 --- a/client/src/file/api/mod.rs +++ b/client/src/file/api/mod.rs @@ -21,7 +21,7 @@ use futures_lite::AsyncWriteExt; use serde::{Deserialize, Serialize}; #[cfg(feature = "tokio")] use tokio::{fs, io, io::AsyncWriteExt}; -use zbus::zvariant::{Endian, Type, serialized::Context}; +use zgvariant::{Type, serialized::Context}; /// Used for newly created [`Keyring`]s const DEFAULT_ITERATION_COUNT: u32 = 100000; @@ -65,7 +65,7 @@ pub(crate) fn data_dir() -> Option { } pub(crate) static GVARIANT_ENCODING: LazyLock = - LazyLock::new(|| Context::new_gvariant(Endian::Little, 0)); + LazyLock::new(|| Context::new(zgvariant::LE, 0)); /// Logical contents of a keyring file #[derive(Deserialize, Serialize, Type, Debug, Zeroize, ZeroizeOnDrop)] @@ -257,7 +257,7 @@ impl Keyring { blob.push(MAJOR_VERSION); blob.push(MINOR_VERSION); - blob.append(&mut zvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec()); + blob.append(&mut zgvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec()); Ok(blob) } @@ -373,7 +373,7 @@ impl TryFrom<&[u8]> for Keyring { } if let Some(data) = value.get((FILE_HEADER_LEN + 2)..) { - let keyring: Self = zvariant::serialized::Data::new(data, *GVARIANT_ENCODING) + let keyring: Self = zgvariant::serialized::Data::new(data, *GVARIANT_ENCODING) .deserialize()? .0; diff --git a/client/src/file/error.rs b/client/src/file/error.rs index b3eb01ac0..1adeff4d5 100644 --- a/client/src/file/error.rs +++ b/client/src/file/error.rs @@ -10,7 +10,7 @@ pub enum Error { /// No Parent directory. NoParentDir(String), /// Bytes don't have the expected GVariant format. - GVariantDeserialization(zvariant::Error), + GVariantDeserialization(zgvariant::Error), /// Mismatch between array length and length explicitly stored in keyring SaltSizeMismatch(usize, u32), /// Key for some reason too weak to trust it for writing @@ -51,8 +51,8 @@ pub enum Error { Schema(crate::SchemaError), } -impl From for Error { - fn from(value: zvariant::Error) -> Self { +impl From for Error { + fn from(value: zgvariant::Error) -> Self { Self::GVariantDeserialization(value) } } diff --git a/client/src/file/unlocked_item.rs b/client/src/file/unlocked_item.rs index 52e8f5b55..3f552cef2 100644 --- a/client/src/file/unlocked_item.rs +++ b/client/src/file/unlocked_item.rs @@ -11,7 +11,7 @@ use crate::{AsAttributes, CONTENT_TYPE_ATTRIBUTE, Key, Mac, Secret, crypto, secr /// An item stored in the file backend. #[derive( - Deserialize, Serialize, zvariant::Type, Clone, Debug, Zeroize, ZeroizeOnDrop, PartialEq, + Deserialize, Serialize, zgvariant::Type, Clone, Debug, Zeroize, ZeroizeOnDrop, PartialEq, )] pub struct UnlockedItem { #[zeroize(skip)] @@ -182,7 +182,7 @@ impl UnlockedItem { } fn encrypt_plaintext(&self) -> Result { - let blob = zvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec(); + let blob = zgvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec(); Ok(EncryptedItem { hashed_attributes: self .attributes @@ -194,7 +194,7 @@ impl UnlockedItem { } fn encrypt_encrypted(&self, key: &Key, iv: &[u8]) -> Result { - let decrypted = Zeroizing::new(zvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec()); + let decrypted = Zeroizing::new(zgvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec()); let mut blob = crypto::encrypt(&*decrypted, key, iv)?; @@ -219,7 +219,7 @@ impl TryFrom<&[u8]> for UnlockedItem { type Error = Error; fn try_from(value: &[u8]) -> Result { - let mut item: UnlockedItem = zvariant::serialized::Data::new(value, *GVARIANT_ENCODING) + let mut item: UnlockedItem = zgvariant::serialized::Data::new(value, *GVARIANT_ENCODING) .deserialize()? .0; diff --git a/client/src/mac.rs b/client/src/mac.rs index 76f15784f..bce009167 100644 --- a/client/src/mac.rs +++ b/client/src/mac.rs @@ -1,8 +1,8 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "native_crypto")] use subtle::ConstantTimeEq; -use zbus::zvariant::Type; use zeroize::{Zeroize, ZeroizeOnDrop}; +use zgvariant::Type; // There is no constructor to avoid performing sanity checks, e.g. length. /// A message authentication code. It provides constant-time comparison when