Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No paste dependency #724

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions aws-lc-fips-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ bindgen = { version = "0.69.5", optional = true }
[target.'cfg(not(all(any(target_arch = "x86_64", target_arch = "aarch64"), any(target_os = "linux", target_os = "macos"), any(target_env = "gnu", target_env = "musl", target_env = ""))))'.build-dependencies]
bindgen = { version = "0.69.5" }

[dependencies]
paste = "1.0.11"

[dev-dependencies]
# Pinned dependency to preserve MSRV: 1.60.0 <= rust-version < 1.65.0
regex = "~1.9.6"
Expand Down
55 changes: 35 additions & 20 deletions aws-lc-fips-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![cfg_attr(not(clippy), allow(unexpected_cfgs))]
#![cfg_attr(not(clippy), allow(unknown_lints))]

use paste::paste;
use std::os::raw::{c_char, c_long, c_void};

#[allow(unused_macros)]
Expand All @@ -16,28 +15,44 @@ macro_rules! use_bindings {
}

macro_rules! platform_binding {
($platform:ident) => {
paste! {
#[cfg(all($platform, not(feature = "ssl"), not(use_bindgen_generated)))]
use_bindings!([< $platform _crypto >]);

#[cfg(all($platform, feature = "ssl", not(use_bindgen_generated)))]
use_bindings!([< $platform _crypto_ssl >]);
}
($platform:ident, $platform_crypto:ident, $platform_ssl:ident) => {
#[cfg(all($platform, not(feature = "ssl"), not(use_bindgen_generated)))]
use_bindings!($platform_crypto);
#[cfg(all($platform, feature = "ssl", not(use_bindgen_generated)))]
use_bindings!($platform_ssl);
};
}

platform_binding!(x86_64_unknown_linux_gnu);

platform_binding!(aarch64_unknown_linux_gnu);

platform_binding!(x86_64_unknown_linux_musl);

platform_binding!(aarch64_unknown_linux_musl);

platform_binding!(x86_64_apple_darwin);

platform_binding!(aarch64_apple_darwin);
platform_binding!(
aarch64_apple_darwin,
aarch64_apple_darwin_crypto,
aarch64_apple_darwin_crypto_ssl
);
platform_binding!(
aarch64_unknown_linux_gnu,
aarch64_unknown_linux_gnu_crypto,
aarch64_unknown_linux_gnu_crypto_ssl
);
platform_binding!(
aarch64_unknown_linux_musl,
aarch64_unknown_linux_musl_crypto,
aarch64_unknown_linux_musl_crypto_ssl
);
platform_binding!(
x86_64_apple_darwin,
x86_64_apple_darwin_crypto,
x86_64_apple_darwin_crypto_ssl
);
platform_binding!(
x86_64_unknown_linux_gnu,
x86_64_unknown_linux_gnu_crypto,
x86_64_unknown_linux_gnu_crypto_ssl
);
platform_binding!(
x86_64_unknown_linux_musl,
x86_64_unknown_linux_musl_crypto,
x86_64_unknown_linux_musl_crypto_ssl
);

#[cfg(use_bindgen_generated)]
#[allow(
Expand Down
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
31 changes: 15 additions & 16 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,24 @@ 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,
EcPrivateKeyRfc5915Der,
EcPublicKeyUncompressedBin,
EcPublicKeyCompressedBin,
PublicKeyX509Der,
Curve25519SeedBin,
Pkcs8V1Der,
Pkcs8V2Der
(EcPrivateKeyBin, EcPrivateKeyBinType),
(EcPrivateKeyRfc5915Der, EcPrivateKeyRfc5915DerType),
(EcPublicKeyUncompressedBin, EcPublicKeyUncompressedBinType),
(EcPublicKeyCompressedBin, EcPublicKeyCompressedBinType),
(PublicKeyX509Der, PublicKeyX509DerType),
(Curve25519SeedBin, Curve25519SeedBinType),
(Pkcs8V1Der, 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
3 changes: 0 additions & 3 deletions aws-lc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,5 @@ bindgen = { version = "0.69.5", optional = true }
[target.'cfg(not(any(all(any(target_arch="x86_64",target_arch="aarch64"),any(target_os="linux",target_os="macos",target_os="windows"),any(target_env="gnu",target_env="musl",target_env="msvc",target_env="")),all(target_arch="x86",target_os="windows",target_env="msvc"),all(target_arch="x86",target_os="linux",target_env="gnu"))))'.build-dependencies]
bindgen = { version = "0.69.5" }

[dependencies]
paste = "1.0.11"

[package.metadata.aws-lc-sys]
commit-hash = "d0356099f6b668697cdb381dfb09f9a694a6c9c2"
89 changes: 70 additions & 19 deletions aws-lc-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![cfg_attr(not(clippy), allow(unexpected_cfgs))]
#![cfg_attr(not(clippy), allow(unknown_lints))]

use paste::paste;
use std::os::raw::{c_char, c_long, c_void};

#[allow(unused_macros)]
Expand All @@ -16,27 +15,79 @@ macro_rules! use_bindings {
}

macro_rules! platform_binding {
($platform:ident) => {
paste! {
#[cfg(all($platform, not(feature = "ssl"), not(use_bindgen_generated)))]
use_bindings!([< $platform _crypto >]);
}
($platform:ident, $platform_crypto:ident, $platform_ssl:ident) => {
#[cfg(all($platform, not(feature = "ssl"), not(use_bindgen_generated)))]
use_bindings!($platform_crypto);
#[cfg(all($platform, feature = "ssl", not(use_bindgen_generated)))]
use_bindings!($platform_ssl);
};
}

platform_binding!(aarch64_linux_android);
platform_binding!(aarch64_apple_darwin);
platform_binding!(aarch64_pc_windows_msvc);
platform_binding!(aarch64_unknown_linux_gnu);
platform_binding!(aarch64_unknown_linux_musl);
platform_binding!(i686_pc_windows_msvc);
platform_binding!(i686_unknown_linux_gnu);
platform_binding!(riscv64gc_unknown_linux_gnu);
platform_binding!(x86_64_apple_darwin);
platform_binding!(x86_64_pc_windows_gnu);
platform_binding!(x86_64_pc_windows_msvc);
platform_binding!(x86_64_unknown_linux_gnu);
platform_binding!(x86_64_unknown_linux_musl);
platform_binding!(
aarch64_linux_android,
aarch64_linux_android_crypto,
aarch64_linux_android_crypto_ssl
);
platform_binding!(
aarch64_apple_darwin,
aarch64_apple_darwin_crypto,
aarch64_apple_darwin_crypto_ssl
);
platform_binding!(
aarch64_pc_windows_msvc,
aarch64_pc_windows_msvc_crypto,
aarch64_pc_windows_msvc_crypto_ssl
);
platform_binding!(
aarch64_unknown_linux_gnu,
aarch64_unknown_linux_gnu_crypto,
aarch64_unknown_linux_gnu_crypto_ssl
);
platform_binding!(
aarch64_unknown_linux_musl,
aarch64_unknown_linux_musl_crypto,
aarch64_unknown_linux_musl_crypto_ssl
);
platform_binding!(
i686_pc_windows_msvc,
i686_pc_windows_msvc_crypto,
i686_pc_windows_msvc_crypto_ssl
);
platform_binding!(
i686_unknown_linux_gnu,
i686_unknown_linux_gnu_crypto,
i686_unknown_linux_gnu_crypto_ssl
);
platform_binding!(
riscv64gc_unknown_linux_gnu,
riscv64gc_unknown_linux_gnu_crypto,
riscv64gc_unknown_linux_gnu_crypto_ssl
);
platform_binding!(
x86_64_apple_darwin,
x86_64_apple_darwin_crypto,
x86_64_apple_darwin_crypto_ssl
);
platform_binding!(
x86_64_pc_windows_gnu,
x86_64_pc_windows_gnu_crypto,
x86_64_pc_windows_gnu_crypto_ssl
);
platform_binding!(
x86_64_pc_windows_msvc,
x86_64_pc_windows_msvc_crypto,
x86_64_pc_windows_msvc_crypto_ssl
);
platform_binding!(
x86_64_unknown_linux_gnu,
x86_64_unknown_linux_gnu_crypto,
x86_64_unknown_linux_gnu_crypto_ssl
);
platform_binding!(
x86_64_unknown_linux_musl,
x86_64_unknown_linux_musl_crypto,
x86_64_unknown_linux_musl_crypto_ssl
);

#[cfg(use_bindgen_generated)]
#[allow(
Expand Down
Loading