diff --git a/aws-lc-rs/src/cbb.rs b/aws-lc-rs/src/cbb.rs index c48a71b45d6..bb4853ade7b 100644 --- a/aws-lc-rs/src/cbb.rs +++ b/aws-lc-rs/src/cbb.rs @@ -72,3 +72,41 @@ impl Drop for LcCBB<'_> { } } } + +#[cfg(test)] +mod tests { + use super::LcCBB; + use aws_lc::CBB_add_asn1_bool; + + #[test] + fn dynamic_buffer() { + let mut cbb = LcCBB::new(4); + assert_eq!(1, unsafe { CBB_add_asn1_bool(cbb.as_mut_ptr(), 1) }); + let buffer = cbb.into_buffer::<'_, ()>().expect("be copied to buffer"); + assert_eq!(buffer.as_ref(), &[1, 1, 255]); + } + + #[test] + fn dynamic_buffer_grows() { + let mut cbb = LcCBB::new(1); + assert_eq!(1, unsafe { CBB_add_asn1_bool(cbb.as_mut_ptr(), 1) }); + let buffer = cbb.into_buffer::<'_, ()>().expect("be copied to buffer"); + assert_eq!(buffer.as_ref(), &[1, 1, 255]); + } + + #[test] + fn fixed_buffer() { + let mut buffer = [0u8; 4]; + let mut cbb = LcCBB::new_fixed(&mut buffer); + assert_eq!(1, unsafe { CBB_add_asn1_bool(cbb.as_mut_ptr(), 1) }); + let out_len = cbb.finish().expect("cbb finishable"); + assert_eq!(&buffer[..out_len], &[1, 1, 255]); + } + + #[test] + fn fixed_buffer_no_growth() { + let mut buffer = [0u8; 1]; + let mut cbb = LcCBB::new_fixed(&mut buffer); + assert_ne!(1, unsafe { CBB_add_asn1_bool(cbb.as_mut_ptr(), 1) }); + } +} diff --git a/aws-lc-rs/src/rsa/key.rs b/aws-lc-rs/src/rsa/key.rs index a60b8258df1..662e7bc59c5 100644 --- a/aws-lc-rs/src/rsa/key.rs +++ b/aws-lc-rs/src/rsa/key.rs @@ -22,7 +22,7 @@ use aws_lc::{ EVP_DigestSignInit, EVP_PKEY_assign_RSA, EVP_PKEY_new, RSA_generate_key_ex, RSA_generate_key_fips, RSA_get0_e, RSA_get0_n, RSA_get0_p, RSA_get0_q, RSA_new, RSA_parse_private_key, RSA_parse_public_key, RSA_public_key_to_bytes, RSA_set0_key, RSA_size, - BIGNUM, EVP_PKEY, EVP_PKEY_CTX, RSA, RSA_F4, + BIGNUM, EVP_PKEY, EVP_PKEY_CTX, RSA, }; use mirai_annotations::verify_unreachable; @@ -620,6 +620,14 @@ mod tests { use super::{KeyPair, KeySize, PublicKeyComponents}; use crate::encoding::AsDer; + #[test] + fn keysize_len() { + assert_eq!(KeySize::Rsa2048.len(), 256); + assert_eq!(KeySize::Rsa3072.len(), 384); + assert_eq!(KeySize::Rsa4096.len(), 512); + assert_eq!(KeySize::Rsa8192.len(), 1024); + } + macro_rules! generate_encode_decode { ($name:ident, $size:expr) => { #[test]