clippy + fmt
This commit is contained in:
parent
382e4478cf
commit
a6ea8c2c1a
|
@ -10,7 +10,7 @@ use crate::keys::Key;
|
||||||
fn sign_hmac(alg: hmac::Algorithm, key: Key, signing_input: &str) -> Result<String> {
|
fn sign_hmac(alg: hmac::Algorithm, key: Key, signing_input: &str) -> Result<String> {
|
||||||
let signing_key = match key {
|
let signing_key = match key {
|
||||||
Key::Hmac(bytes) => hmac::Key::new(alg, bytes),
|
Key::Hmac(bytes) => hmac::Key::new(alg, bytes),
|
||||||
_ => return Err(ErrorKind::InvalidKeyFormat)?,
|
_ => return Err(ErrorKind::InvalidKeyFormat.into()),
|
||||||
};
|
};
|
||||||
let digest = hmac::sign(&signing_key, signing_input.as_bytes());
|
let digest = hmac::sign(&signing_key, signing_input.as_bytes());
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ fn sign_rsa(
|
||||||
signature::RsaKeyPair::from_pkcs8(bytes).map_err(|_| ErrorKind::InvalidRsaKey)?
|
signature::RsaKeyPair::from_pkcs8(bytes).map_err(|_| ErrorKind::InvalidRsaKey)?
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(ErrorKind::InvalidKeyFormat)?;
|
return Err(ErrorKind::InvalidKeyFormat.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ fn verify_ring_es(
|
||||||
let bytes = match key {
|
let bytes = match key {
|
||||||
Key::Pkcs8(bytes) => bytes,
|
Key::Pkcs8(bytes) => bytes,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(ErrorKind::InvalidKeyFormat)?;
|
return Err(ErrorKind::InvalidKeyFormat.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
verify_ring(alg, signature, signing_input, bytes)
|
verify_ring(alg, signature, signing_input, bytes)
|
||||||
|
@ -135,7 +135,7 @@ fn verify_ring_rsa(
|
||||||
|
|
||||||
Ok(res.is_ok())
|
Ok(res.is_ok())
|
||||||
}
|
}
|
||||||
_ => Err(ErrorKind::InvalidKeyFormat)?,
|
_ => Err(ErrorKind::InvalidKeyFormat.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl PemEncodedKey {
|
||||||
let pem_contents = content.contents;
|
let pem_contents = content.contents;
|
||||||
let asn1_content = match simple_asn1::from_der(pem_contents.as_slice()) {
|
let asn1_content = match simple_asn1::from_der(pem_contents.as_slice()) {
|
||||||
Ok(asn1) => asn1,
|
Ok(asn1) => asn1,
|
||||||
Err(_) => return Err(ErrorKind::InvalidKeyFormat)?,
|
Err(_) => return Err(ErrorKind::InvalidKeyFormat.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
match content.tag.as_ref() {
|
match content.tag.as_ref() {
|
||||||
|
@ -106,14 +106,14 @@ impl PemEncodedKey {
|
||||||
standard: Standard::Pkcs8,
|
standard: Standard::Pkcs8,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
None => return Err(ErrorKind::InvalidKeyFormat)?,
|
None => Err(ErrorKind::InvalidKeyFormat.into()),
|
||||||
},
|
},
|
||||||
|
|
||||||
// Unknown/unsupported type
|
// Unknown/unsupported type
|
||||||
_ => return Err(ErrorKind::InvalidKeyFormat)?,
|
_ => Err(ErrorKind::InvalidKeyFormat.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => return Err(ErrorKind::InvalidKeyFormat)?,
|
Err(_) => Err(ErrorKind::InvalidKeyFormat.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ impl PemEncodedKey {
|
||||||
// And the DER contents of an RSA key
|
// And the DER contents of an RSA key
|
||||||
// Though PKCS#11 keys shouldn't have anything else.
|
// Though PKCS#11 keys shouldn't have anything else.
|
||||||
// It will get confusing with certificates.
|
// It will get confusing with certificates.
|
||||||
fn extract_first_bitstring(asn1: &Vec<simple_asn1::ASN1Block>) -> Result<&[u8]> {
|
fn extract_first_bitstring(asn1: &[simple_asn1::ASN1Block]) -> Result<&[u8]> {
|
||||||
for asn1_entry in asn1.iter() {
|
for asn1_entry in asn1.iter() {
|
||||||
match asn1_entry {
|
match asn1_entry {
|
||||||
simple_asn1::ASN1Block::Sequence(_, entries) => {
|
simple_asn1::ASN1Block::Sequence(_, entries) => {
|
||||||
|
@ -156,15 +156,16 @@ fn extract_first_bitstring(asn1: &Vec<simple_asn1::ASN1Block>) -> Result<&[u8]>
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ErrorKind::InvalidEcdsaKey)?
|
|
||||||
|
Err(ErrorKind::InvalidEcdsaKey.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find whether this is EC or RSA
|
/// Find whether this is EC or RSA
|
||||||
fn classify_pem(asn1: &Vec<simple_asn1::ASN1Block>) -> Option<Classification> {
|
fn classify_pem(asn1: &[simple_asn1::ASN1Block]) -> Option<Classification> {
|
||||||
// These should be constant but the macro requires
|
// These should be constant but the macro requires
|
||||||
// #![feature(const_vec_new)]
|
// #![feature(const_vec_new)]
|
||||||
let ec_public_key_oid = simple_asn1::oid!(1, 2, 840, 10045, 2, 1);
|
let ec_public_key_oid = simple_asn1::oid!(1, 2, 840, 10_045, 2, 1);
|
||||||
let rsa_public_key_oid = simple_asn1::oid!(1, 2, 840, 113549, 1, 1, 1);
|
let rsa_public_key_oid = simple_asn1::oid!(1, 2, 840, 113_549, 1, 1, 1);
|
||||||
|
|
||||||
for asn1_entry in asn1.iter() {
|
for asn1_entry in asn1.iter() {
|
||||||
match asn1_entry {
|
match asn1_entry {
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub fn encode_rsa_public_pkcs1_pem(modulus: &[u8], exponent: &[u8]) -> Result<St
|
||||||
pub fn encode_rsa_public_pkcs1_der(modulus: &[u8], exponent: &[u8]) -> Result<Vec<u8>> {
|
pub fn encode_rsa_public_pkcs1_der(modulus: &[u8], exponent: &[u8]) -> Result<Vec<u8>> {
|
||||||
match simple_asn1::to_der(&encode_rsa_public_pksc1_asn1(modulus, exponent)) {
|
match simple_asn1::to_der(&encode_rsa_public_pksc1_asn1(modulus, exponent)) {
|
||||||
Ok(bytes) => Ok(bytes),
|
Ok(bytes) => Ok(bytes),
|
||||||
Err(_) => return Err(ErrorKind::InvalidRsaKey)?,
|
Err(_) => Err(ErrorKind::InvalidRsaKey.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ pub fn encode_rsa_public_pkcs8_pem(modulus: &[u8], exponent: &[u8]) -> Result<St
|
||||||
pub fn encode_rsa_public_pkcs8_der(modulus: &[u8], exponent: &[u8]) -> Result<Vec<u8>> {
|
pub fn encode_rsa_public_pkcs8_der(modulus: &[u8], exponent: &[u8]) -> Result<Vec<u8>> {
|
||||||
match simple_asn1::to_der(&encode_rsa_public_pksc8_asn1(modulus, exponent)?) {
|
match simple_asn1::to_der(&encode_rsa_public_pksc8_asn1(modulus, exponent)?) {
|
||||||
Ok(bytes) => Ok(bytes),
|
Ok(bytes) => Ok(bytes),
|
||||||
Err(_) => return Err(ErrorKind::InvalidRsaKey)?,
|
Err(_) => Err(ErrorKind::InvalidRsaKey.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ pub fn encode_ec_public_pem(x: &[u8]) -> Result<String> {
|
||||||
pub fn encode_ec_public_der(x: &[u8]) -> Result<Vec<u8>> {
|
pub fn encode_ec_public_der(x: &[u8]) -> Result<Vec<u8>> {
|
||||||
match simple_asn1::to_der(&encode_ec_public_asn1(x)) {
|
match simple_asn1::to_der(&encode_ec_public_asn1(x)) {
|
||||||
Ok(bytes) => Ok(bytes),
|
Ok(bytes) => Ok(bytes),
|
||||||
Err(_) => return Err(ErrorKind::InvalidEcdsaKey)?,
|
Err(_) => Err(ErrorKind::InvalidEcdsaKey.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_rsa_public_pksc8_asn1(modulus: &[u8], exponent: &[u8]) -> Result<ASN1Block> {
|
fn encode_rsa_public_pksc8_asn1(modulus: &[u8], exponent: &[u8]) -> Result<ASN1Block> {
|
||||||
let pksc1 = match simple_asn1::to_der(&encode_rsa_public_pksc1_asn1(modulus, exponent)) {
|
let pksc1 = match simple_asn1::to_der(&encode_rsa_public_pksc1_asn1(modulus, exponent)) {
|
||||||
Ok(bytes) => bytes,
|
Ok(bytes) => bytes,
|
||||||
Err(_) => return Err(ErrorKind::InvalidRsaKey)?,
|
Err(_) => return Err(ErrorKind::InvalidRsaKey.into()),
|
||||||
};
|
};
|
||||||
Ok(ASN1Block::Sequence(
|
Ok(ASN1Block::Sequence(
|
||||||
0,
|
0,
|
||||||
|
@ -57,7 +57,7 @@ fn encode_rsa_public_pksc8_asn1(modulus: &[u8], exponent: &[u8]) -> Result<ASN1B
|
||||||
0,
|
0,
|
||||||
vec![
|
vec![
|
||||||
// rsaEncryption (PKCS #1)
|
// rsaEncryption (PKCS #1)
|
||||||
ASN1Block::ObjectIdentifier(0, simple_asn1::oid!(1, 2, 840, 113549, 1, 1, 1)),
|
ASN1Block::ObjectIdentifier(0, simple_asn1::oid!(1, 2, 840, 113_549, 1, 1, 1)),
|
||||||
ASN1Block::Null(0),
|
ASN1Block::Null(0),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue