Skip to content

Commit bbcb4cc

Browse files
committed
Convert signature to rsa signatures
Signed-off-by: Arthur Gautier <[email protected]>
1 parent ac7f227 commit bbcb4cc

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

tss-esapi/src/abstraction/signatures.rs

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Copyright 2024 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::{structures::EccSignature, Error, Result, WrapperErrorKind};
4+
use crate::{
5+
structures::{EccSignature, Signature},
6+
Error, Result, WrapperErrorKind,
7+
};
58

69
use std::convert::TryFrom;
710

@@ -38,5 +41,32 @@ where
3841
}
3942
}
4043

41-
// TODO(baloo): impl TryFrom<RsaSignature> for rsa::pkcs1v15::Signature
42-
// TODO(baloo): impl TryFrom<RsaSignature> for rsa::pss::Signature
44+
// Note: this does not implement `TryFrom<RsaSignature>` because `RsaSignature` does not carry the
45+
// information whether the signatures was generated using PKCS#1v1.5 or PSS.
46+
impl TryFrom<Signature> for rsa::pkcs1v15::Signature {
47+
type Error = Error;
48+
49+
fn try_from(signature: Signature) -> Result<Self> {
50+
let Signature::RsaSsa(signature) = signature else {
51+
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
52+
};
53+
54+
Self::try_from(signature.signature().as_bytes())
55+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))
56+
}
57+
}
58+
59+
// Note: this does not implement `TryFrom<RsaSignature>` because `RsaSignature` does not carry the
60+
// information whether the signatures was generated using PKCS#1v1.5 or PSS.
61+
impl TryFrom<Signature> for rsa::pss::Signature {
62+
type Error = Error;
63+
64+
fn try_from(signature: Signature) -> Result<Self> {
65+
let Signature::RsaPss(signature) = signature else {
66+
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
67+
};
68+
69+
Self::try_from(signature.signature().as_bytes())
70+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))
71+
}
72+
}

0 commit comments

Comments
 (0)