Skip to content

Commit

Permalink
Provide identity_key_x509_as_der
Browse files Browse the repository at this point in the history
Signed-off-by: David Mulder <[email protected]>
  • Loading branch information
dmulder committed Oct 27, 2023
1 parent 397c2ef commit f6b3dbd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub enum HsmError {
IdentityKeyInvalidForSigning,
IdentityKeySignature,
IdentityKeyX509ToPem,
IdentityKeyX509ToDer,
IdentityKeyX509Missing,
RsaGenerate,
RsaPrivateToDer,
Expand Down Expand Up @@ -214,4 +215,5 @@ trait HsmIdentity: Hsm {
) -> Result<Self::LoadableIdentityKey, HsmError>;

fn identity_key_x509_as_pem(&mut self, key: &Self::IdentityKey) -> Result<Vec<u8>, HsmError>;
fn identity_key_x509_as_der(&mut self, key: &Self::IdentityKey) -> Result<Vec<u8>, HsmError>;
}
17 changes: 17 additions & 0 deletions src/soft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,23 @@ impl HsmIdentity for SoftHsm {
}
}

fn identity_key_x509_as_der(&mut self, key: &Self::IdentityKey) -> Result<Vec<u8>, HsmError> {
match key {
SoftIdentityKey::Ecdsa256 {
pkey: _,
x509: Some(x509),
}
| SoftIdentityKey::Rsa2048 {
pkey: _,
x509: Some(x509),
} => x509.to_der().map_err(|ossl_err| {
error!(?ossl_err);
HsmError::IdentityKeyX509ToDer
}),
_ => Err(HsmError::IdentityKeyX509Missing),
}
}

fn identity_key_sign(
&mut self,
key: &Self::IdentityKey,
Expand Down

0 comments on commit f6b3dbd

Please sign in to comment.