Skip to content

Commit

Permalink
feat: add support for EncodePrivateKey (#208)
Browse files Browse the repository at this point in the history
Implement encoding Signing keys to PKCS#8 DER format.

Signed-off-by: Dmitry Baryshkov <[email protected]>
  • Loading branch information
lumag authored Oct 8, 2022
1 parent 8a1026b commit ece83cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/pkcs1v15.rs
Original file line number Diff line number Diff line change
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, Document, EncodePublicKey};
use pkcs8::{AssociatedOid, Document, EncodePrivateKey, EncodePublicKey, SecretDocument};
use rand_core::{CryptoRng, RngCore};
#[cfg(feature = "hazmat")]
use signature::hazmat::{PrehashSigner, PrehashVerifier};
Expand Down Expand Up @@ -376,6 +376,15 @@ where
}
}

impl<D> EncodePrivateKey for SigningKey<D>
where
D: Digest,
{
fn to_pkcs8_der(&self) -> pkcs8::Result<SecretDocument> {
self.inner.to_pkcs8_der()
}
}

impl<D> Signer<Signature> for SigningKey<D>
where
D: Digest,
Expand Down
20 changes: 19 additions & 1 deletion src/pss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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 pkcs8::{Document, EncodePrivateKey, EncodePublicKey, SecretDocument};
use rand_core::{CryptoRng, RngCore};
#[cfg(feature = "hazmat")]
use signature::hazmat::{PrehashVerifier, RandomizedPrehashSigner};
Expand Down Expand Up @@ -574,6 +574,15 @@ where
}
}

impl<D> EncodePrivateKey for SigningKey<D>
where
D: Digest,
{
fn to_pkcs8_der(&self) -> pkcs8::Result<SecretDocument> {
self.inner.to_pkcs8_der()
}
}

impl<D> RandomizedSigner<Signature> for SigningKey<D>
where
D: Digest + FixedOutputReset,
Expand Down Expand Up @@ -688,6 +697,15 @@ where
}
}

impl<D> EncodePrivateKey for BlindedSigningKey<D>
where
D: Digest,
{
fn to_pkcs8_der(&self) -> pkcs8::Result<SecretDocument> {
self.inner.to_pkcs8_der()
}
}

impl<D> RandomizedSigner<Signature> for BlindedSigningKey<D>
where
D: Digest + FixedOutputReset,
Expand Down

0 comments on commit ece83cb

Please sign in to comment.