Skip to content

Commit

Permalink
add test_signature_key_pair
Browse files Browse the repository at this point in the history
  • Loading branch information
rainliu committed Sep 4, 2023
1 parent 34e707b commit 21ce952
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rmls/src/crypto/provider/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! [RFC9420 Sec.5](https://www.rfc-editor.org/rfc/rfc9420.html#section-5) CryptoProvider trait and
//! implementations that provide the cryptographic primitives to be used in group key computations.

#[cfg(test)]
mod provider_test;

#[cfg(feature = "RingCryptoProvider")]
mod ring;
#[cfg(feature = "RingCryptoProvider")]
Expand Down
31 changes: 31 additions & 0 deletions rmls/src/crypto/provider/provider_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use super::*;

const PLAINTEXT: &[u8] = b"38a6b327573639d654b5b729336cf74d01728cf4fa9af81a0ef1814ffc1d492f";

fn test_signature_key_pair_with_crypto_provider(
crypto_provider: &impl CryptoProvider,
) -> Result<()> {
for c in 1..=7u16 {
let cipher_suite: CipherSuite = c.try_into()?;
if crypto_provider.supports(cipher_suite) {
let signature = crypto_provider.signature(cipher_suite);
let key_pair = signature.generate_key_pair()?;
let out = signature.sign(key_pair.private_key(), PLAINTEXT)?;
assert!(signature
.verify(key_pair.public_key(), PLAINTEXT, &out)
.is_ok());
}
}

Ok(())
}

#[test]
fn test_signature_key_pair() -> Result<()> {
#[cfg(feature = "RingCryptoProvider")]
test_signature_key_pair_with_crypto_provider(&RingCryptoProvider::default())?;
#[cfg(feature = "RustCryptoProvider")]
test_signature_key_pair_with_crypto_provider(&RustCryptoProvider::default())?;

Ok(())
}

0 comments on commit 21ce952

Please sign in to comment.