Skip to content

Commit

Permalink
add feature flags to prevent needless warnings when nts-pool is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Nov 30, 2023
1 parent 3029a0d commit 356f8cc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ntp-proto/src/packet/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ impl AesSivCmac256 {
AesSivCmac256 { key }
}

#[cfg(feature = "nts-pool")]
pub fn key_size() -> usize {
// prefer trust in compiler optimisation over trust in mental arithmetic
Self::new(Default::default()).key.len()
}

#[cfg(feature = "nts-pool")]
pub fn from_key_bytes(key_bytes: &[u8]) -> Result<Self, KeyError> {
(key_bytes.len() == Self::key_size())
.then(|| Self::new(*aead::Key::<Aes128Siv>::from_slice(key_bytes)))
Expand Down Expand Up @@ -233,11 +235,13 @@ impl AesSivCmac512 {
AesSivCmac512 { key }
}

#[cfg(feature = "nts-pool")]
pub fn key_size() -> usize {
// prefer trust in compiler optimisation over trust in mental arithmetic
Self::new(Default::default()).key.len()
}

#[cfg(feature = "nts-pool")]
pub fn from_key_bytes(key_bytes: &[u8]) -> Result<Self, KeyError> {
(key_bytes.len() == Self::key_size())
.then(|| Self::new(*aead::Key::<Aes256Siv>::from_slice(key_bytes)))
Expand Down Expand Up @@ -461,6 +465,7 @@ mod tests {
assert_eq!(result, (0..16).collect::<Vec<u8>>());
}

#[cfg(feature = "nts-pool")]
#[test]
fn key_functions_correctness() {
use aead::KeySizeUser;
Expand Down

0 comments on commit 356f8cc

Please sign in to comment.