mirror of
https://github.com/NLnetLabs/krill.git
synced 2026-09-30 05:14:52 +02:00
Implement review feedback.
This commit is contained in:
committed by
Tim Bruijnzeels
parent
b8d5b13a92
commit
c60ef30c74
@@ -1,5 +1,5 @@
|
||||
//! Defines helper methods for Serializing and Deserializing external types.
|
||||
use std::str::FromStr;
|
||||
use std::{str::FromStr, sync::atomic::{AtomicU64, Ordering}};
|
||||
|
||||
use bytes::Bytes;
|
||||
use log::LevelFilter;
|
||||
@@ -162,3 +162,22 @@ where
|
||||
let string = String::deserialize(d)?;
|
||||
Facility::from_str(&string).map_err(|_| de::Error::custom(format!("Unsupported syslog_facility: \"{}\"", string)))
|
||||
}
|
||||
|
||||
//------------- AtomicU64 -----------------------------------------------------
|
||||
// Implemented automatically by Serde derive but only for x86_64 architectures,
|
||||
// for other architectures (such as armv7 for the Raspberry Pi 4b) it has to be
|
||||
// implemented manually.
|
||||
|
||||
pub fn de_atomicu64<'de, D>(d: D) -> Result<AtomicU64, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Ok(AtomicU64::new(u64::deserialize(d)?))
|
||||
}
|
||||
|
||||
pub fn ser_atomicu64<S>(v: &AtomicU64, s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
s.serialize_u64(v.load(Ordering::SeqCst))
|
||||
}
|
||||
@@ -27,6 +27,7 @@ use std::{
|
||||
use crate::commons::{
|
||||
error::{Error, KrillIoError},
|
||||
KrillResult,
|
||||
util::ext_serde,
|
||||
};
|
||||
|
||||
const CHACHA20_KEY_BIT_LEN: usize = 256;
|
||||
@@ -41,6 +42,11 @@ const UNUSED_AAD: [u8; 0] = [0; 0];
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct NonceState {
|
||||
sender_unique: [u8; 4], // 32 bits
|
||||
|
||||
#[serde(
|
||||
deserialize_with = "ext_serde::de_atomicu64",
|
||||
serialize_with = "ext_serde::ser_atomicu64"
|
||||
)]
|
||||
counter: AtomicU64, // + 64 bits = 96 bits = CHACHA20_NONCE_BIT_LEN
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user