Simplify code.
This commit is contained in:
parent
01126aabdf
commit
da51f27173
1 changed files with 19 additions and 22 deletions
|
@ -98,28 +98,22 @@ impl<'a> crypto::Signer for CardSigner {
|
||||||
PublicKeyAlgorithm::RSAEncryptSign,
|
PublicKeyAlgorithm::RSAEncryptSign,
|
||||||
mpi::PublicKey::RSA { .. },
|
mpi::PublicKey::RSA { .. },
|
||||||
) => {
|
) => {
|
||||||
let sig = match hash_algo {
|
let hash = match hash_algo {
|
||||||
openpgp::types::HashAlgorithm::SHA256 => {
|
openpgp::types::HashAlgorithm::SHA256 => Hash::SHA256(
|
||||||
let hash =
|
digest
|
||||||
Hash::SHA256(digest.try_into().map_err(|_| {
|
.try_into()
|
||||||
anyhow!("invalid slice length")
|
.map_err(|_| anyhow!("invalid slice length"))?,
|
||||||
})?);
|
),
|
||||||
self.ocu.signature_for_hash(hash)?
|
openpgp::types::HashAlgorithm::SHA384 => Hash::SHA384(
|
||||||
}
|
digest
|
||||||
openpgp::types::HashAlgorithm::SHA384 => {
|
.try_into()
|
||||||
let hash =
|
.map_err(|_| anyhow!("invalid slice length"))?,
|
||||||
Hash::SHA384(digest.try_into().map_err(|_| {
|
),
|
||||||
anyhow!("invalid slice length")
|
openpgp::types::HashAlgorithm::SHA512 => Hash::SHA512(
|
||||||
})?);
|
digest
|
||||||
self.ocu.signature_for_hash(hash)?
|
.try_into()
|
||||||
}
|
.map_err(|_| anyhow!("invalid slice length"))?,
|
||||||
openpgp::types::HashAlgorithm::SHA512 => {
|
),
|
||||||
let hash =
|
|
||||||
Hash::SHA512(digest.try_into().map_err(|_| {
|
|
||||||
anyhow!("invalid slice length")
|
|
||||||
})?);
|
|
||||||
self.ocu.signature_for_hash(hash)?
|
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
"Unsupported hash algorithm for RSA {:?}",
|
"Unsupported hash algorithm for RSA {:?}",
|
||||||
|
@ -128,11 +122,14 @@ impl<'a> crypto::Signer for CardSigner {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let sig = self.ocu.signature_for_hash(hash)?;
|
||||||
|
|
||||||
let mpi = mpi::MPI::new(&sig[..]);
|
let mpi = mpi::MPI::new(&sig[..]);
|
||||||
Ok(mpi::Signature::RSA { s: mpi })
|
Ok(mpi::Signature::RSA { s: mpi })
|
||||||
}
|
}
|
||||||
(PublicKeyAlgorithm::EdDSA, mpi::PublicKey::EdDSA { .. }) => {
|
(PublicKeyAlgorithm::EdDSA, mpi::PublicKey::EdDSA { .. }) => {
|
||||||
let hash = Hash::EdDSA(digest);
|
let hash = Hash::EdDSA(digest);
|
||||||
|
|
||||||
let sig = self.ocu.signature_for_hash(hash)?;
|
let sig = self.ocu.signature_for_hash(hash)?;
|
||||||
|
|
||||||
let r = mpi::MPI::new(&sig[..32]);
|
let r = mpi::MPI::new(&sig[..32]);
|
||||||
|
|
Loading…
Reference in a new issue