|  | 
| 1 | 1 | // Copyright 2024 Contributors to the Parsec project. | 
| 2 | 2 | // SPDX-License-Identifier: Apache-2.0 | 
| 3 | 3 | 
 | 
| 4 |  | -use crate::{structures::EccSignature, Error, Result, WrapperErrorKind}; | 
|  | 4 | +use crate::{ | 
|  | 5 | +    structures::{EccSignature, Signature}, | 
|  | 6 | +    Error, Result, WrapperErrorKind, | 
|  | 7 | +}; | 
| 5 | 8 | 
 | 
| 6 | 9 | use std::convert::TryFrom; | 
| 7 | 10 | 
 | 
|  | 
| 38 | 41 |     } | 
| 39 | 42 | } | 
| 40 | 43 | 
 | 
| 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