Skip to content

Commit

Permalink
added serde tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LWEdslev committed Mar 22, 2024
1 parent a7dc12a commit 80b8eff
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/oaep/decrypting_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ where

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use sha2::Sha256;

Expand All @@ -116,8 +115,9 @@ mod tests {

let ser_decrypting_key =
serde_json::to_string(&decrypting_key).expect("unable to serialize decrypting key");
let deser_decrypting_key = serde_json::from_str::<DecryptingKey<Sha256>>(&ser_decrypting_key)
.expect("unable to serialize decrypting key");
let deser_decrypting_key =
serde_json::from_str::<DecryptingKey<Sha256>>(&ser_decrypting_key)
.expect("unable to serialize decrypting key");

assert_eq!(decrypting_key.label, deser_decrypting_key.label);
assert_eq!(decrypting_key.inner, deser_decrypting_key.inner);
Expand Down
3 changes: 1 addition & 2 deletions src/oaep/encrypting_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ where

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use sha2::Sha256;

Expand Down
12 changes: 6 additions & 6 deletions src/pkcs1v15/decrypting_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use crate::{
traits::{Decryptor, EncryptingKeypair, RandomizedDecryptor},
Result, RsaPrivateKey,
};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use alloc::vec::Vec;
use rand_core::CryptoRngCore;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use zeroize::ZeroizeOnDrop;

/// Decryption key for PKCS#1 v1.5 decryption as described in [RFC8017 § 7.2].
Expand Down Expand Up @@ -55,16 +55,16 @@ impl ZeroizeOnDrop for DecryptingKey {}

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use serde_test::{assert_tokens, Configure, Token};

let mut rng = ChaCha8Rng::from_seed([42; 32]);
let decrypting_key = DecryptingKey::new(RsaPrivateKey::new(&mut rng, 64).expect("failed to generate key"));
let decrypting_key =
DecryptingKey::new(RsaPrivateKey::new(&mut rng, 64).expect("failed to generate key"));

let tokens = [
Token::Struct { name: "DecryptingKey", len: 1 },
Expand All @@ -74,4 +74,4 @@ mod tests {
];
assert_tokens(&decrypting_key.clone().readable(), &tokens);
}
}
}
3 changes: 1 addition & 2 deletions src/pkcs1v15/encrypting_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ impl RandomizedEncryptor for EncryptingKey {

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use serde_test::{assert_tokens, Configure, Token};

Expand Down
3 changes: 1 addition & 2 deletions src/pkcs1v15/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ impl<'de> Deserialize<'de> for Signature {

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use serde_test::{assert_tokens, Configure, Token};
let signature = Signature {
inner: BigUint::new(Vec::from([42])),
Expand Down
3 changes: 1 addition & 2 deletions src/pkcs1v15/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,10 @@ where

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use sha2::Sha256;

Expand Down
3 changes: 1 addition & 2 deletions src/pkcs1v15/verifying_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,10 @@ where

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use sha2::Sha256;

Expand Down
3 changes: 1 addition & 2 deletions src/pss/blinded_signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,10 @@ where

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use sha2::Sha256;

Expand Down
3 changes: 1 addition & 2 deletions src/pss/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ impl<'de> Deserialize<'de> for Signature {

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use serde_test::{assert_tokens, Configure, Token};
let signature = Signature {
inner: BigUint::new(Vec::from([42])),
Expand Down
3 changes: 1 addition & 2 deletions src/pss/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,10 @@ where

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use sha2::Sha256;

Expand Down
3 changes: 1 addition & 2 deletions src/pss/verifying_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,10 @@ where

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use sha2::Sha256;

Expand Down

0 comments on commit 80b8eff

Please sign in to comment.