Skip to content

Commit efaddec

Browse files
Port to zgvariant (#552)
* Port to zgvariant * Complete the zgvariant port The initial port left the client's D-Bus types still naming a bare `zvariant`, which no longer resolves now that the crate pulls `zgvariant` for the keyring file format and reaches D-Bus zvariant through `zbus`. Import the `zvariant` module from `zbus` so those references keep resolving. The pam module <-> daemon socket protocol is an internal wire format, not real D-Bus, so it now uses the GVariant encoding via `zgvariant` on both ends. This drops zvariant from the pam module entirely (it depends only on `zgvariant`) and keeps oo7 on a single serialization stack. Assisted-by: Claude Opus 4.8 (claude-opus-4-8) --------- Co-authored-by: Bilal Elmoussaoui <belmouss@redhat.com>
1 parent c2aa231 commit efaddec

19 files changed

Lines changed: 88 additions & 60 deletions

File tree

‎Cargo.lock‎

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

‎Cargo.toml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ tempfile = "3.26"
5353
tokio = { version = "1.52", default-features = false }
5454
tracing = "0.1"
5555
tracing-subscriber = "0.3"
56-
zbus = { version = "5.14.0", default-features = false }
57-
zbus_macros = { version = "5.11", features = ["gvariant"] }
56+
zbus = { version = "5.19", default-features = false }
57+
zgvariant = { version = "1.0", features = ["serde_bytes"] }
5858
zeroize = { version = "1", features = ["zeroize_derive"] }
59-
zvariant = { version = "5.8", default-features = false, features = ["gvariant", "serde_bytes"] }

‎client/Cargo.toml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ tokio = { workspace = true, features = [
4141
"io-util",
4242
], optional = true, default-features = false }
4343
tracing = { workspace = true, optional = true }
44+
zgvariant.workspace = true
4445
zbus.workspace = true
45-
zbus_macros.workspace = true
46-
zvariant.workspace = true
4746
zeroize.workspace = true
4847

4948
[dev-dependencies]

‎client/src/dbus/algorithm.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use serde::{Deserialize, Serialize};
2+
use zbus::zvariant;
23

34
#[derive(Debug, zvariant::Type, PartialEq, Eq, Copy, Clone)]
45
#[zvariant(signature = "s")]
@@ -43,7 +44,7 @@ impl<'de> Deserialize<'de> for Algorithm {
4344

4445
#[cfg(test)]
4546
mod tests {
46-
use zvariant::{Endian, serialized::Context, to_bytes};
47+
use zbus::zvariant::{Endian, serialized::Context, to_bytes};
4748

4849
use super::*;
4950

‎client/src/dbus/api/properties.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::{
44
Deserialize,
55
ser::{Serialize, SerializeMap},
66
};
7-
use zbus::zvariant::{Type, Value};
7+
use zbus::zvariant::{self, Type, Value};
88

99
use crate::AsAttributes;
1010

@@ -164,7 +164,7 @@ mod tests {
164164

165165
#[test]
166166
fn deserialize_item_properties() {
167-
use zvariant::Dict;
167+
use zbus::zvariant::Dict;
168168

169169
// Create serialized data that represents item properties
170170
let mut attrs_dict = Dict::new(String::SIGNATURE, String::SIGNATURE);

‎client/src/dbus/api/service.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{collections::HashMap, fmt};
22

33
use ashpd::WindowIdentifier;
44
use futures_util::{Stream, StreamExt};
5-
use zbus::zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Type, Value};
5+
use zbus::zvariant::{self, ObjectPath, OwnedObjectPath, OwnedValue, Type, Value};
66

77
use super::{
88
Collection, DBusSecret, DESTINATION, Item, PATH, Prompt, Properties, Session, Unlockable,

‎client/src/file/api/encrypted_item.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::collections::HashMap;
22

33
use serde::{Deserialize, Serialize};
4-
use zbus::zvariant::Type;
54
use zeroize::{Zeroize, ZeroizeOnDrop};
5+
use zgvariant::Type;
66

77
use super::{Error, UnlockedItem};
88
use crate::{AsAttributes, Key, Mac, crypto};

‎client/src/file/api/mod.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use futures_lite::AsyncWriteExt;
2121
use serde::{Deserialize, Serialize};
2222
#[cfg(feature = "tokio")]
2323
use tokio::{fs, io, io::AsyncWriteExt};
24-
use zbus::zvariant::{Endian, Type, serialized::Context};
24+
use zgvariant::{Type, serialized::Context};
2525

2626
/// Used for newly created [`Keyring`]s
2727
const DEFAULT_ITERATION_COUNT: u32 = 100000;
@@ -65,7 +65,7 @@ pub(crate) fn data_dir() -> Option<PathBuf> {
6565
}
6666

6767
pub(crate) static GVARIANT_ENCODING: LazyLock<Context> =
68-
LazyLock::new(|| Context::new_gvariant(Endian::Little, 0));
68+
LazyLock::new(|| Context::new(zgvariant::LE, 0));
6969

7070
/// Logical contents of a keyring file
7171
#[derive(Deserialize, Serialize, Type, Debug, Zeroize, ZeroizeOnDrop)]
@@ -257,7 +257,7 @@ impl Keyring {
257257

258258
blob.push(MAJOR_VERSION);
259259
blob.push(MINOR_VERSION);
260-
blob.append(&mut zvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec());
260+
blob.append(&mut zgvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec());
261261

262262
Ok(blob)
263263
}
@@ -373,7 +373,7 @@ impl TryFrom<&[u8]> for Keyring {
373373
}
374374

375375
if let Some(data) = value.get((FILE_HEADER_LEN + 2)..) {
376-
let keyring: Self = zvariant::serialized::Data::new(data, *GVARIANT_ENCODING)
376+
let keyring: Self = zgvariant::serialized::Data::new(data, *GVARIANT_ENCODING)
377377
.deserialize()?
378378
.0;
379379

‎client/src/file/error.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub enum Error {
1010
/// No Parent directory.
1111
NoParentDir(String),
1212
/// Bytes don't have the expected GVariant format.
13-
GVariantDeserialization(zvariant::Error),
13+
GVariantDeserialization(zgvariant::Error),
1414
/// Mismatch between array length and length explicitly stored in keyring
1515
SaltSizeMismatch(usize, u32),
1616
/// Key for some reason too weak to trust it for writing
@@ -51,8 +51,8 @@ pub enum Error {
5151
Schema(crate::SchemaError),
5252
}
5353

54-
impl From<zvariant::Error> for Error {
55-
fn from(value: zvariant::Error) -> Self {
54+
impl From<zgvariant::Error> for Error {
55+
fn from(value: zgvariant::Error) -> Self {
5656
Self::GVariantDeserialization(value)
5757
}
5858
}

‎client/src/file/unlocked_item.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{AsAttributes, CONTENT_TYPE_ATTRIBUTE, Key, Mac, Secret, crypto, secr
1111

1212
/// An item stored in the file backend.
1313
#[derive(
14-
Deserialize, Serialize, zvariant::Type, Clone, Debug, Zeroize, ZeroizeOnDrop, PartialEq,
14+
Deserialize, Serialize, zgvariant::Type, Clone, Debug, Zeroize, ZeroizeOnDrop, PartialEq,
1515
)]
1616
pub struct UnlockedItem {
1717
#[zeroize(skip)]
@@ -182,7 +182,7 @@ impl UnlockedItem {
182182
}
183183

184184
fn encrypt_plaintext(&self) -> Result<EncryptedItem, Error> {
185-
let blob = zvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec();
185+
let blob = zgvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec();
186186
Ok(EncryptedItem {
187187
hashed_attributes: self
188188
.attributes
@@ -194,7 +194,7 @@ impl UnlockedItem {
194194
}
195195

196196
fn encrypt_encrypted(&self, key: &Key, iv: &[u8]) -> Result<EncryptedItem, Error> {
197-
let decrypted = Zeroizing::new(zvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec());
197+
let decrypted = Zeroizing::new(zgvariant::to_bytes(*GVARIANT_ENCODING, &self)?.to_vec());
198198

199199
let mut blob = crypto::encrypt(&*decrypted, key, iv)?;
200200

@@ -219,7 +219,7 @@ impl TryFrom<&[u8]> for UnlockedItem {
219219
type Error = Error;
220220

221221
fn try_from(value: &[u8]) -> Result<Self, Error> {
222-
let mut item: UnlockedItem = zvariant::serialized::Data::new(value, *GVARIANT_ENCODING)
222+
let mut item: UnlockedItem = zgvariant::serialized::Data::new(value, *GVARIANT_ENCODING)
223223
.deserialize()?
224224
.0;
225225

0 commit comments

Comments
 (0)