Skip to content

Commit

Permalink
Remove unnecessary from FixedLength
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jun 14, 2023
1 parent 2aa6844 commit 7438df0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
6 changes: 2 additions & 4 deletions aws-lc-rs/src/aead/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ impl Nonce {
/// `error::Unspecified` when byte slice length is not `NONCE_LEN`
#[inline]
pub fn try_assume_unique_for_key(value: &[u8]) -> Result<Self, error::Unspecified> {
Ok(Self(FixedLength::<NONCE_LEN>::try_assume_unique_for_key(
value,
)?))
Ok(Self(FixedLength::<NONCE_LEN>::try_from(value)?))
}

/// Constructs a `Nonce` with the given value, assuming that the value is
/// unique for the lifetime of the key it is being used with.
#[inline]
#[must_use]
pub fn assume_unique_for_key(value: [u8; NONCE_LEN]) -> Self {
Self(FixedLength::<NONCE_LEN>::assume_unique_for_key(value))
Self(FixedLength::<NONCE_LEN>::from(value))
}
}

Expand Down
25 changes: 3 additions & 22 deletions aws-lc-rs/src/iv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,14 @@
//! Initialization Vector (IV) cryptographic primitives
use crate::error::Unspecified;
use crate::{error, rand};
use crate::rand;
use zeroize::Zeroize;

/// An initialization vector that must be unique for the lifetime of the associated key
/// it is used with.
pub struct FixedLength<const L: usize>([u8; L]);

impl<const L: usize> FixedLength<L> {
/// Constructs a [`FixedLength`] with the given value, assuming that the value is
/// unique for the lifetime of the key it is being used with.
///
/// Fails if `value` isn't `L` bytes long.
/// # Errors
/// `error::Unspecified` when byte slice length is not `L`
#[inline]
pub fn try_assume_unique_for_key(value: &[u8]) -> Result<Self, error::Unspecified> {
let value: &[u8; L] = value.try_into()?;
Ok(Self::assume_unique_for_key(*value))
}

/// Constructs a [`FixedLength`] with the given value, assuming that the value is
/// unique for the lifetime of the key it is being used with.
#[inline]
#[must_use]
pub fn assume_unique_for_key(value: [u8; L]) -> Self {
Self(value)
}

/// Returns the size of the iv in bytes.
#[allow(clippy::must_use_candidate)]
pub fn size(&self) -> usize {
Expand Down Expand Up @@ -85,7 +65,8 @@ impl<const L: usize> TryFrom<&[u8]> for FixedLength<L> {
type Error = Unspecified;

fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
FixedLength::<L>::try_assume_unique_for_key(value)
let value: &[u8; L] = value.try_into()?;
Ok(Self::from(*value))
}
}

Expand Down

0 comments on commit 7438df0

Please sign in to comment.