From 9eb58647c1beff7b2995f051aa0df9c56cd5aed7 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 24 Nov 2021 13:02:22 +0100 Subject: [PATCH] pbs-datastore: use hex::serde feature Signed-off-by: Dietmar Maurer --- pbs-datastore/Cargo.toml | 2 +- pbs-datastore/src/manifest.rs | 27 +-------------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/pbs-datastore/Cargo.toml b/pbs-datastore/Cargo.toml index f4b5b2a9..3ed2ae2e 100644 --- a/pbs-datastore/Cargo.toml +++ b/pbs-datastore/Cargo.toml @@ -11,7 +11,7 @@ base64 = "0.13" crc32fast = "1" endian_trait = { version = "0.6", features = [ "arrays" ] } futures = "0.3" -hex = "0.4.3" +hex = { version = "0.4.3", features = [ "serde" ] } lazy_static = "1.4" libc = "0.2" log = "0.4" diff --git a/pbs-datastore/src/manifest.rs b/pbs-datastore/src/manifest.rs index 2aa1d489..58e8aba7 100644 --- a/pbs-datastore/src/manifest.rs +++ b/pbs-datastore/src/manifest.rs @@ -16,31 +16,6 @@ pub const MANIFEST_LOCK_NAME: &str = ".index.json.lck"; pub const CLIENT_LOG_BLOB_NAME: &str = "client.log.blob"; pub const ENCRYPTED_KEY_BLOB_NAME: &str = "rsa-encrypted.key.blob"; -mod hex_csum { - use serde::{self, Deserialize, Serializer, Deserializer}; - use hex::FromHex; - - pub fn serialize( - csum: &[u8; 32], - serializer: S, - ) -> Result - where - S: Serializer, - { - let s = hex::encode(csum); - serializer.serialize_str(&s) - } - - pub fn deserialize<'de, D>( - deserializer: D, - ) -> Result<[u8; 32], D::Error> - where - D: Deserializer<'de>, - { - let s = String::deserialize(deserializer)?; - <[u8; 32]>::from_hex(&s).map_err(serde::de::Error::custom) - } -} fn crypt_mode_none() -> CryptMode { CryptMode::None } fn empty_value() -> Value { json!({}) } @@ -52,7 +27,7 @@ pub struct FileInfo { #[serde(default="crypt_mode_none")] // to be compatible with < 0.8.0 backups pub crypt_mode: CryptMode, pub size: u64, - #[serde(with = "hex_csum")] + #[serde(with = "hex::serde")] pub csum: [u8; 32], }