From 417ac636dbd77499e525517bc07f11595f9a9e08 Mon Sep 17 00:00:00 2001 From: Hugo Hakim Damer Date: Tue, 27 Aug 2024 23:39:23 +0200 Subject: [PATCH] fix: solve various import issues, ensure CI also tests rustcrypto with no_std --- .github/workflows/check.yml | 2 +- build.rs | 4 +++- src/token/cose/crypto_impl/rustcrypto/encrypt/aes_ccm.rs | 1 + src/token/cose/crypto_impl/rustcrypto/encrypt/aes_gcm.rs | 1 + .../crypto_impl/rustcrypto/key_distribution/aes_key_wrap.rs | 1 + .../cose/crypto_impl/rustcrypto/key_distribution/mod.rs | 1 + src/token/cose/crypto_impl/rustcrypto/mod.rs | 6 +++++- src/token/cose/crypto_impl/rustcrypto/sign/ecdsa.rs | 1 + src/token/cose/crypto_impl/rustcrypto/sign/mod.rs | 1 + 9 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ce83a2b..28e54bc 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -59,7 +59,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: components: rustc, cargo - - run: cargo test --no-default-features --features openssl + - run: cargo test --no-default-features --features openssl,rustcrypto fmt: name: Rustfmt diff --git a/build.rs b/build.rs index c2cc891..2d4788e 100644 --- a/build.rs +++ b/build.rs @@ -15,7 +15,9 @@ fn main() { cfg_aliases! { rustcrypto_encrypt_base: { any( - feature = "rustcrypto-aes-gcm" + feature = "rustcrypto-aes-gcm", + feature = "rustcrypto-aes-ccm", + feature = "rustcrypto-chacha20-poly1305" ) }, rustcrypto_sign_base: { diff --git a/src/token/cose/crypto_impl/rustcrypto/encrypt/aes_ccm.rs b/src/token/cose/crypto_impl/rustcrypto/encrypt/aes_ccm.rs index d91088a..c65467f 100644 --- a/src/token/cose/crypto_impl/rustcrypto/encrypt/aes_ccm.rs +++ b/src/token/cose/crypto_impl/rustcrypto/encrypt/aes_ccm.rs @@ -19,6 +19,7 @@ use crate::error::CoseCipherError; use crate::token::cose::{CoseSymmetricKey, CryptoBackend}; use super::RustCryptoContext; +use alloc::vec::Vec; impl RustCryptoContext { /// Perform an AES-CCM encryption operation on `plaintext` and the additional authenticated diff --git a/src/token/cose/crypto_impl/rustcrypto/encrypt/aes_gcm.rs b/src/token/cose/crypto_impl/rustcrypto/encrypt/aes_gcm.rs index c18d8f2..4513a70 100644 --- a/src/token/cose/crypto_impl/rustcrypto/encrypt/aes_gcm.rs +++ b/src/token/cose/crypto_impl/rustcrypto/encrypt/aes_gcm.rs @@ -19,6 +19,7 @@ use crate::error::CoseCipherError; use crate::token::cose::{CoseSymmetricKey, CryptoBackend}; use super::RustCryptoContext; +use alloc::vec::Vec; impl RustCryptoContext { /// Perform an AES-GCM encryption operation on `plaintext` and the additional authenticated diff --git a/src/token/cose/crypto_impl/rustcrypto/key_distribution/aes_key_wrap.rs b/src/token/cose/crypto_impl/rustcrypto/key_distribution/aes_key_wrap.rs index c76866b..a8ebb79 100644 --- a/src/token/cose/crypto_impl/rustcrypto/key_distribution/aes_key_wrap.rs +++ b/src/token/cose/crypto_impl/rustcrypto/key_distribution/aes_key_wrap.rs @@ -20,6 +20,7 @@ use crate::error::CoseCipherError; use crate::token::cose::{CoseSymmetricKey, CryptoBackend}; use super::RustCryptoContext; +use alloc::vec::Vec; impl RustCryptoContext { /// Perform an AES key wrap operation on the key contained in `plaintext` which is wrapped diff --git a/src/token/cose/crypto_impl/rustcrypto/key_distribution/mod.rs b/src/token/cose/crypto_impl/rustcrypto/key_distribution/mod.rs index 589f8b3..78b298f 100644 --- a/src/token/cose/crypto_impl/rustcrypto/key_distribution/mod.rs +++ b/src/token/cose/crypto_impl/rustcrypto/key_distribution/mod.rs @@ -14,6 +14,7 @@ use rand::{CryptoRng, RngCore}; use crate::error::CoseCipherError; use crate::token::cose::crypto_impl::rustcrypto::RustCryptoContext; use crate::token::cose::{CoseSymmetricKey, KeyDistributionCryptoBackend}; +use alloc::vec::Vec; #[cfg(feature = "rustcrypto-aes-kw")] mod aes_key_wrap; diff --git a/src/token/cose/crypto_impl/rustcrypto/mod.rs b/src/token/cose/crypto_impl/rustcrypto/mod.rs index 089f2d9..06a148c 100644 --- a/src/token/cose/crypto_impl/rustcrypto/mod.rs +++ b/src/token/cose/crypto_impl/rustcrypto/mod.rs @@ -92,7 +92,11 @@ impl From for CoseCipherError { } } -#[cfg(feature = "rustcrypto-aes-gcm")] +#[cfg(any( + feature = "rustcrypto-aes-gcm", + feature = "rustcrypto-aes-ccm", + feature = "rustcrypto-chacha20-poly1305" +))] impl From for CoseCipherError { fn from(_value: aead::Error) -> Self { CoseCipherError::VerificationFailure diff --git a/src/token/cose/crypto_impl/rustcrypto/sign/ecdsa.rs b/src/token/cose/crypto_impl/rustcrypto/sign/ecdsa.rs index 03a7218..929e391 100644 --- a/src/token/cose/crypto_impl/rustcrypto/sign/ecdsa.rs +++ b/src/token/cose/crypto_impl/rustcrypto/sign/ecdsa.rs @@ -33,6 +33,7 @@ use crate::error::CoseCipherError; use crate::token::cose::crypto_impl::rustcrypto::CoseRustCryptoCipherError; use crate::token::cose::crypto_impl::rustcrypto::RustCryptoContext; use crate::token::cose::{CoseEc2Key, CryptoBackend, EllipticCurve}; +use alloc::vec::Vec; impl RustCryptoContext { /// Perform an ECDSA signature operation with the ECDSA variant given in `algorithm` for the diff --git a/src/token/cose/crypto_impl/rustcrypto/sign/mod.rs b/src/token/cose/crypto_impl/rustcrypto/sign/mod.rs index 311a9c3..db5cac1 100644 --- a/src/token/cose/crypto_impl/rustcrypto/sign/mod.rs +++ b/src/token/cose/crypto_impl/rustcrypto/sign/mod.rs @@ -15,6 +15,7 @@ use rand::{CryptoRng, RngCore}; use crate::token::cose::crypto_impl::rustcrypto::RustCryptoContext; use crate::token::SignCryptoBackend; +use alloc::vec::Vec; #[cfg(feature = "rustcrypto-ecdsa")] mod ecdsa;