Skip to content

Commit

Permalink
RSA: implement EncodePublicKey for VerifyingKeys (#207)
Browse files Browse the repository at this point in the history
Implement key -> der conversion for public keys.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
  • Loading branch information
lumag committed Oct 8, 2022
1 parent 2cac57a commit 9066931
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/pkcs1v15.rs
Expand Up @@ -4,7 +4,7 @@ use core::fmt::{Debug, Display, Formatter, LowerHex, UpperHex};
use core::marker::PhantomData;
use core::ops::Deref;
use digest::Digest;
use pkcs8::AssociatedOid;
use pkcs8::{AssociatedOid, Document, EncodePublicKey};
use rand_core::{CryptoRng, RngCore};
#[cfg(feature = "hazmat")]
use signature::hazmat::{PrehashSigner, PrehashVerifier};
Expand Down Expand Up @@ -574,6 +574,15 @@ where
}
}

impl<D> EncodePublicKey for VerifyingKey<D>
where
D: Digest,
{
fn to_public_key_der(&self) -> pkcs8::spki::Result<Document> {
self.inner.to_public_key_der()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
10 changes: 10 additions & 0 deletions src/pss.rs
Expand Up @@ -5,6 +5,7 @@ use core::fmt::{Debug, Display, Formatter, LowerHex, UpperHex};
use core::marker::PhantomData;
use core::ops::Deref;
use digest::{Digest, DynDigest, FixedOutputReset};
use pkcs8::{Document, EncodePublicKey};
use rand_core::{CryptoRng, RngCore};
#[cfg(feature = "hazmat")]
use signature::hazmat::{PrehashVerifier, RandomizedPrehashSigner};
Expand Down Expand Up @@ -874,6 +875,15 @@ where
}
}

impl<D> EncodePublicKey for VerifyingKey<D>
where
D: Digest,
{
fn to_public_key_der(&self) -> pkcs8::spki::Result<Document> {
self.inner.to_public_key_der()
}
}

#[cfg(test)]
mod test {
use crate::pss::{BlindedSigningKey, SigningKey, VerifyingKey};
Expand Down

0 comments on commit 9066931

Please sign in to comment.