Skip to content

Commit

Permalink
cleanup rsapublickey
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Dec 1, 2023
1 parent a5fc616 commit 7211bfa
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::traits::keys::{CrtValueNew, PrivateKeyPartsNew, PublicKeyPartsNew};
use crate::traits::{PaddingScheme, PublicKeyParts, SignatureScheme};

/// Represents the public part of an RSA key.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct RsaPublicKey {
/// Modulus: product of prime numbers `p` and `q`
Expand All @@ -34,16 +34,24 @@ pub struct RsaPublicKey {
/// Typically 0x10001 (65537)
e: BoxedUint,

#[cfg_attr(feature = "serde", serde(skip))]
n_params: BoxedResidueParams,
}

// TODO: derive `Hash` impl when `BoxedUint` supports it
impl Eq for RsaPublicKey {}
impl PartialEq for RsaPublicKey {
#[inline]
fn eq(&self, other: &RsaPublicKey) -> bool {
self.n == other.n && self.e == other.e
}
}

impl Hash for RsaPublicKey {
fn hash<H: Hasher>(&self, state: &mut H) {
// Domain separator for RSA private keys
state.write(b"RsaPublicKey");
Hash::hash(&self.n.as_words(), state);
Hash::hash(&self.e.as_words(), state);
Hash::hash(&self.n, state);
Hash::hash(&self.e, state);
}
}

Expand Down

0 comments on commit 7211bfa

Please sign in to comment.