Skip to content

Commit

Permalink
Make paste a dev-dependency only
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Mar 10, 2025
1 parent da8ded2 commit 8d18746
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion aws-lc-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ untrusted = { version = "0.7.1", optional = true }
aws-lc-sys = { version = "0.27.0", path = "../aws-lc-sys", optional = true }
aws-lc-fips-sys = { version = "0.13.1", path = "../aws-lc-fips-sys", optional = true }
zeroize = "1.7"
paste = "1.0.11"

[dev-dependencies]
paste = "1.0.11"
lazy_static = "1.4.0"
clap = { version = "4.1.8", features = ["derive"] }
hex = "0.4.3"
Expand Down
25 changes: 10 additions & 15 deletions aws-lc-rs/src/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ use aead_ctx::AeadCtx;
use core::fmt::Debug;
use core::ops::RangeFrom;
use core::stringify;
use paste::paste;

mod aead_ctx;
mod aes_gcm;
Expand Down Expand Up @@ -529,43 +528,39 @@ impl<N: NonceSequence> SealingKey<N> {
}

macro_rules! nonce_seq_key_op_mut {
($name:ident) => {
paste! {
($name:ident, $name_prep_nonce:ident) => {
/// A key operation with a precomputed nonce from a key's associated `NonceSequence`.
pub struct [<$name PreparedNonce>]<'a, N: NonceSequence> {
pub struct $name_prep_nonce<'a, N: NonceSequence> {
key: &'a mut $name<N>,
nonce: Nonce,
}

impl<'a, N: NonceSequence> [<$name PreparedNonce>]<'a, N> {
impl<'a, N: NonceSequence> $name_prep_nonce<'a, N> {
fn new(key: &'a mut $name<N>) -> Result<Self, Unspecified> {
let nonce = key.nonce_sequence.advance()?;
Ok(Self {
key,
nonce,
})
Ok(Self { key, nonce })
}
}

impl<N: NonceSequence> [<$name PreparedNonce>]<'_, N> {
impl<N: NonceSequence> $name_prep_nonce<'_, N> {
/// Returns the prepared Nonce that is used for key methods invoked on [Self].
#[must_use]
pub fn nonce(&self) -> &Nonce {
&self.nonce
}
}

impl<N: NonceSequence> Debug for [<$name PreparedNonce>]<'_, N> {
impl<N: NonceSequence> Debug for $name_prep_nonce<'_, N> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
f.debug_struct(stringify!([<$name PreparedNonce>])).finish_non_exhaustive()
f.debug_struct(stringify!($name_prep_nonce))
.finish_non_exhaustive()
}
}
}
};
}

nonce_seq_key_op_mut!(OpeningKey);
nonce_seq_key_op_mut!(SealingKey);
nonce_seq_key_op_mut!(OpeningKey, OpeningKeyPreparedNonce);
nonce_seq_key_op_mut!(SealingKey, SealingKeyPreparedNonce);

impl<N: NonceSequence> OpeningKeyPreparedNonce<'_, N> {
/// Authenticates and decrypts (“opens”) data in place.
Expand Down
25 changes: 16 additions & 9 deletions aws-lc-rs/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
//! Serialization formats
use crate::buffer::Buffer;
use paste::paste;

macro_rules! generated_encodings {
($($name:ident),*) => { paste! {
($($name:ident, $name_type:ident),*) => {
use core::fmt::{Debug, Error, Formatter};
use core::ops::Deref;
mod buffer_type {
$(
pub struct [<$name Type>] {
pub struct $name_type {
_priv: (),
}
)*
}
$(
/// Serialized bytes
pub struct $name<'a>(Buffer<'a, buffer_type::[<$name Type>]>);
pub struct $name<'a>(Buffer<'a, buffer_type::$name_type>);

impl<'a> Deref for $name<'a> {
type Target = Buffer<'a, buffer_type::[<$name Type>]>;
type Target = Buffer<'a, buffer_type::$name_type>;

fn deref(&self) -> &Self::Target {
&self.0
Expand All @@ -46,24 +45,32 @@ macro_rules! generated_encodings {
}
}

impl<'a> From<Buffer<'a, buffer_type::[<$name Type>]>> for $name<'a> {
fn from(value: Buffer<'a, buffer_type::[<$name Type>]>) -> Self {
impl<'a> From<Buffer<'a, buffer_type::$name_type>> for $name<'a> {
fn from(value: Buffer<'a, buffer_type::$name_type>) -> Self {
Self(value)
}
}
)*
}}
}
}
pub(crate) use generated_encodings;
generated_encodings!(
EcPrivateKeyBin,
EcPrivateKeyBinType,
EcPrivateKeyRfc5915Der,
EcPrivateKeyRfc5915DerType,
EcPublicKeyUncompressedBin,
EcPublicKeyUncompressedBinType,
EcPublicKeyCompressedBin,
EcPublicKeyCompressedBinType,
PublicKeyX509Der,
PublicKeyX509DerType,
Curve25519SeedBin,
Curve25519SeedBinType,
Pkcs8V1Der,
Pkcs8V2Der
Pkcs8V1DerType,
Pkcs8V2Der,
Pkcs8V2DerType
);

/// Trait for types that can be serialized into a DER format.
Expand Down
4 changes: 1 addition & 3 deletions aws-lc-rs/src/kem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@ where
}
}

use paste::paste;

generated_encodings!(EncapsulationKeyBytes);
generated_encodings!(EncapsulationKeyBytes, EncapsulationKeyBytesType);

/// A serializable encapsulation key usable with KEM algorithms. Constructed
/// from either a `DecapsulationKey` or raw bytes.
Expand Down

0 comments on commit 8d18746

Please sign in to comment.