pbs-datastore: use hex::serde feature

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dietmar Maurer 2021-11-24 13:02:22 +01:00
parent 0ff214bedd
commit 9eb58647c1
2 changed files with 2 additions and 27 deletions

View File

@ -11,7 +11,7 @@ base64 = "0.13"
crc32fast = "1" crc32fast = "1"
endian_trait = { version = "0.6", features = [ "arrays" ] } endian_trait = { version = "0.6", features = [ "arrays" ] }
futures = "0.3" futures = "0.3"
hex = "0.4.3" hex = { version = "0.4.3", features = [ "serde" ] }
lazy_static = "1.4" lazy_static = "1.4"
libc = "0.2" libc = "0.2"
log = "0.4" log = "0.4"

View File

@ -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 CLIENT_LOG_BLOB_NAME: &str = "client.log.blob";
pub const ENCRYPTED_KEY_BLOB_NAME: &str = "rsa-encrypted.key.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<S>(
csum: &[u8; 32],
serializer: S,
) -> Result<S::Ok, S::Error>
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 crypt_mode_none() -> CryptMode { CryptMode::None }
fn empty_value() -> Value { json!({}) } 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 #[serde(default="crypt_mode_none")] // to be compatible with < 0.8.0 backups
pub crypt_mode: CryptMode, pub crypt_mode: CryptMode,
pub size: u64, pub size: u64,
#[serde(with = "hex_csum")] #[serde(with = "hex::serde")]
pub csum: [u8; 32], pub csum: [u8; 32],
} }