Skip to content

Commit

Permalink
added serde support for pkcs1v15 structs
Browse files Browse the repository at this point in the history
  • Loading branch information
LWEdslev committed Mar 18, 2024
1 parent d011ca5 commit bf61816
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/pkcs1v15/decrypting_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::{
traits::{Decryptor, EncryptingKeypair, RandomizedDecryptor},
Result, RsaPrivateKey,
};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use alloc::vec::Vec;
use rand_core::CryptoRngCore;
use zeroize::ZeroizeOnDrop;
Expand All @@ -12,6 +14,7 @@ use zeroize::ZeroizeOnDrop;
///
/// [RFC8017 § 7.2]: https://datatracker.ietf.org/doc/html/rfc8017#section-7.2
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DecryptingKey {
inner: RsaPrivateKey,
}
Expand Down
3 changes: 3 additions & 0 deletions src/pkcs1v15/encrypting_key.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use super::encrypt;
use crate::{traits::RandomizedEncryptor, Result, RsaPublicKey};
use alloc::vec::Vec;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use rand_core::CryptoRngCore;

/// Encryption key for PKCS#1 v1.5 encryption as described in [RFC8017 § 7.2].
///
/// [RFC8017 § 7.2]: https://datatracker.ietf.org/doc/html/rfc8017#section-7.2
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct EncryptingKey {
pub(super) inner: RsaPublicKey,
}
Expand Down
3 changes: 3 additions & 0 deletions src/pkcs1v15/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use crate::algorithms::pad::uint_to_be_pad;
use ::signature::SignatureEncoding;
use alloc::{boxed::Box, string::ToString};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use core::fmt::{Debug, Display, Formatter, LowerHex, UpperHex};
use num_bigint::BigUint;
use spki::{
Expand All @@ -14,6 +16,7 @@ use spki::{
///
/// [RFC8017 § 8.2]: https://datatracker.ietf.org/doc/html/rfc8017#section-8.2
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Signature {
pub(super) inner: BigUint,
pub(super) len: usize,
Expand Down
3 changes: 3 additions & 0 deletions src/pkcs1v15/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::{dummy_rng::DummyRng, Result, RsaPrivateKey};
use alloc::vec::Vec;
use core::marker::PhantomData;
use digest::Digest;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use pkcs8::{
spki::{
der::AnyRef, AlgorithmIdentifierRef, AssociatedAlgorithmIdentifier,
Expand All @@ -20,6 +22,7 @@ use zeroize::ZeroizeOnDrop;
///
/// [RFC8017 § 8.2]: https://datatracker.ietf.org/doc/html/rfc8017#section-8.2
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SigningKey<D>
where
D: Digest,
Expand Down
3 changes: 3 additions & 0 deletions src/pkcs1v15/verifying_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::RsaPublicKey;
use alloc::vec::Vec;
use core::marker::PhantomData;
use digest::Digest;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use pkcs8::{
spki::{
der::AnyRef, AlgorithmIdentifierRef, AssociatedAlgorithmIdentifier,
Expand All @@ -16,6 +18,7 @@ use signature::{hazmat::PrehashVerifier, DigestVerifier, Verifier};
///
/// [RFC8017 § 8.2]: https://datatracker.ietf.org/doc/html/rfc8017#section-8.2
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct VerifyingKey<D>
where
D: Digest,
Expand Down

0 comments on commit bf61816

Please sign in to comment.