Skip to content

Commit

Permalink
Address test case feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail committed Jan 24, 2024
1 parent 74a6486 commit 21bf008
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
38 changes: 38 additions & 0 deletions aws-lc-rs/src/cbb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) });
}
}
10 changes: 9 additions & 1 deletion aws-lc-rs/src/rsa/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 21bf008

Please sign in to comment.