Skip to content

Commit bcfcba0

Browse files
committed
Use PublicKeyData as super trait for SigningKey
1 parent d01e231 commit bcfcba0

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

rcgen/src/crl.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ use crate::{
2525
/// struct MyKeyPair { public_key: Vec<u8> }
2626
/// #[cfg(not(feature = "crypto"))]
2727
/// impl SigningKey for MyKeyPair {
28-
/// fn public_key(&self) -> &[u8] { &self.public_key }
2928
/// fn sign(&self, _: &[u8]) -> Result<Vec<u8>, rcgen::Error> { Ok(vec![]) }
29+
/// }
30+
/// #[cfg(not(feature = "crypto"))]
31+
/// impl PublicKeyData for MyKeyPair {
32+
/// fn der_bytes(&self) -> &[u8] { &self.public_key }
3033
/// fn algorithm(&self) -> &'static SignatureAlgorithm { &PKCS_ED25519 }
3134
/// }
3235
/// # fn main () {

rcgen/src/key_pair.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl PublicKeyData for KeyPair {
523523
KeyPairKind::Ed(kp) => kp.public_key().as_ref(),
524524
#[cfg(feature = "crypto")]
525525
KeyPairKind::Rsa(kp, _) => kp.public_key().as_ref(),
526-
KeyPairKind::Remote(kp) => kp.public_key(),
526+
KeyPairKind::Remote(kp) => kp.der_bytes(),
527527
}
528528
}
529529

@@ -658,15 +658,9 @@ pub enum RsaKeySize {
658658
///
659659
/// Trait objects based on this trait can be passed to the [`KeyPair::from_remote`] function for generating certificates
660660
/// from a remote and raw private key, for example an HSM.
661-
pub trait SigningKey {
662-
/// Returns the public key of this key pair in the binary format as in [`KeyPair::public_key_raw`]
663-
fn public_key(&self) -> &[u8];
664-
661+
pub trait SigningKey: PublicKeyData {
665662
/// Signs `msg` using the selected algorithm
666663
fn sign(&self, msg: &[u8]) -> Result<Vec<u8>, Error>;
667-
668-
/// Reveals the algorithm to be used when calling `sign()`
669-
fn algorithm(&self) -> &'static SignatureAlgorithm;
670664
}
671665

672666
#[cfg(feature = "crypto")]

rcgen/tests/webpki.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use webpki::{
1414
};
1515

1616
use rcgen::{
17-
BasicConstraints, Certificate, CertificateParams, DnType, Error, IsCa, KeyPair, SigningKey,
17+
BasicConstraints, Certificate, CertificateParams, DnType, Error, IsCa, KeyPair, PublicKeyData,
18+
SigningKey,
1819
};
1920
use rcgen::{CertificateRevocationListParams, RevocationReason, RevokedCertParams};
2021
#[cfg(feature = "x509-parser")]
@@ -318,17 +319,19 @@ fn from_remote() {
318319
struct Remote(EcdsaKeyPair);
319320

320321
impl SigningKey for Remote {
321-
fn public_key(&self) -> &[u8] {
322-
self.0.public_key().as_ref()
323-
}
324-
325322
fn sign(&self, msg: &[u8]) -> Result<Vec<u8>, rcgen::Error> {
326323
let system_random = SystemRandom::new();
327324
self.0
328325
.sign(&system_random, msg)
329326
.map(|s| s.as_ref().to_owned())
330327
.map_err(|_| Error::RingUnspecified)
331328
}
329+
}
330+
331+
impl PublicKeyData for Remote {
332+
fn der_bytes(&self) -> &[u8] {
333+
self.0.public_key().as_ref()
334+
}
332335

333336
fn algorithm(&self) -> &'static rcgen::SignatureAlgorithm {
334337
&rcgen::PKCS_ECDSA_P256_SHA256

0 commit comments

Comments
 (0)