RustCrypto / RSA

RSA implementation in pure Rust
Apache License 2.0
536 stars 146 forks source link

Support `From<_> for &RsaPublicKey` and `From<_> for &RsaPrivateKey` for relevant types #426

Closed LWEdslev closed 5 months ago

LWEdslev commented 5 months ago

For example if I have a pss::VerifyingKey and a function fn foo(key: &RsaPublicKey) I currenctly have to do this:

let key: VerifyingKey<Sha256> = ....;
foo(&key.clone().into()); // if we don't clone here it is moved

whereas a pretty simple implementation could make it

let key: VerifyingKey<Sha256> = ....;
foo((&key).into());

the implementation could be something like:

impl<'a, D> From<&'a VerifyingKey<D>> for &'a RsaPublicKey
where
    D: Digest,
{
    fn from(key: &'a VerifyingKey<D>) -> Self {
        &key.inner
    }
}
tarcieri commented 5 months ago

Use AsRef