Skip to content

Commit

Permalink
Implement Debug for OpeningKey and SealingKey.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Jan 24, 2019
1 parent c156075 commit abbb616
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct OpeningKey {
key: Key,
}

derive_debug_via_field!(OpeningKey, key);

impl OpeningKey {
/// Create a new opening key.
///
Expand Down Expand Up @@ -148,6 +150,8 @@ pub struct SealingKey {
key: Key,
}

derive_debug_via_field!(SealingKey, key);

impl SealingKey {
/// Constructs a new sealing key from `key_bytes`.
#[inline]
Expand Down Expand Up @@ -236,6 +240,8 @@ struct Key {
algorithm: &'static Algorithm,
}

derive_debug_via_field!(Key, algorithm);

#[allow(variant_size_differences)]
enum KeyInner {
AesGcm(aes_gcm::Key),
Expand Down
17 changes: 17 additions & 0 deletions tests/aead_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,20 @@ fn aead_chacha20_poly1305_openssh() {
},
);
}

#[test]
fn test_aead_key_debug() {
let key_bytes = [0; 32];

let key = aead::OpeningKey::new(&aead::AES_256_GCM, &key_bytes).unwrap();
assert_eq!(
"OpeningKey { key: Key { algorithm: AES_256_GCM } }",
format!("{:?}", key)
);

let key = aead::SealingKey::new(&aead::CHACHA20_POLY1305, &key_bytes).unwrap();
assert_eq!(
"SealingKey { key: Key { algorithm: CHACHA20_POLY1305 } }",
format!("{:?}", key)
);
}

0 comments on commit abbb616

Please sign in to comment.