fix formatting

This commit is contained in:
Egor Duda
2022-05-17 23:03:22 +03:00
parent 42bfd7860d
commit 25d538cde6
3 changed files with 24 additions and 15 deletions

View File

@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#[cfg(feature = "ed25519")]
use crate::ctap::data_formats::EDDSA_ALGORITHM;
use crate::ctap::data_formats::{
extract_array, extract_byte_string, CoseKey, PublicKeyCredentialSource,
PublicKeyCredentialType, SignatureAlgorithm, ES256_ALGORITHM,
};
#[cfg(feature="ed25519")]
use crate::ctap::data_formats::EDDSA_ALGORITHM;
use crate::ctap::status_code::Ctap2StatusCode;
use crate::ctap::storage;
use crate::env::Env;
@@ -97,7 +97,7 @@ pub fn aes256_cbc_decrypt(
}
/// An asymmetric private key that can sign messages.
#[derive(Clone,Debug,PartialEq,Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum PrivateKey {
Ecdsa(ecdsa::SecKey),
#[cfg(feature = "ed25519")]
@@ -117,7 +117,7 @@ impl PrivateKey {
SignatureAlgorithm::EDDSA => {
let bytes = rng.gen_uniform_u8x32();
Self::new_ed25519_from_bytes(&bytes).unwrap()
},
}
SignatureAlgorithm::Unknown => unreachable!(),
}
}
@@ -155,7 +155,7 @@ impl PrivateKey {
match self {
PrivateKey::Ecdsa(ecdsa_key) => ecdsa_key.sign_rfc6979::<Sha256>(message).to_asn1_der(),
#[cfg(feature = "ed25519")]
PrivateKey::Ed25519(ed25519_key) => ed25519_key.sign(message,None).to_vec(),
PrivateKey::Ed25519(ed25519_key) => ed25519_key.sign(message, None).to_vec(),
}
}

View File

@@ -896,7 +896,10 @@ impl TryFrom<CoseKey> for ecdsa::PubKey {
curve,
} = cose_key;
if algorithm != ES256_ALGORITHM || key_type != CoseKey::EC2_KEY_TYPE || curve != CoseKey::P_256_CURVE {
if algorithm != ES256_ALGORITHM
|| key_type != CoseKey::EC2_KEY_TYPE
|| curve != CoseKey::P_256_CURVE
{
return Err(Ctap2StatusCode::CTAP2_ERR_UNSUPPORTED_ALGORITHM);
}
ecdsa::PubKey::from_coordinates(&x_bytes, &y_bytes)
@@ -945,10 +948,8 @@ impl TryFrom<CoseSignature> for ecdsa::Signature {
SignatureAlgorithm::ES256 => ecdsa::Signature::from_bytes(&cose_signature.bytes)
.ok_or(Ctap2StatusCode::CTAP1_ERR_INVALID_PARAMETER),
#[cfg(feature = "ed25519")]
SignatureAlgorithm::EDDSA =>
Err(Ctap2StatusCode::CTAP2_ERR_UNSUPPORTED_ALGORITHM),
SignatureAlgorithm::Unknown =>
Err(Ctap2StatusCode::CTAP2_ERR_UNSUPPORTED_ALGORITHM),
SignatureAlgorithm::EDDSA => Err(Ctap2StatusCode::CTAP2_ERR_UNSUPPORTED_ALGORITHM),
SignatureAlgorithm::Unknown => Err(Ctap2StatusCode::CTAP2_ERR_UNSUPPORTED_ALGORITHM),
}
}
}
@@ -1632,7 +1633,8 @@ mod test {
#[cfg(feature = "ed25519")]
{
let cbor_signature_algorithm: cbor::Value = cbor_int!(EDDSA_ALGORITHM);
let signature_algorithm = SignatureAlgorithm::try_from(cbor_signature_algorithm.clone());
let signature_algorithm =
SignatureAlgorithm::try_from(cbor_signature_algorithm.clone());
let expected_signature_algorithm = SignatureAlgorithm::EDDSA;
assert_eq!(signature_algorithm, Ok(expected_signature_algorithm));
let created_cbor: cbor::Value = signature_algorithm.unwrap().into();
@@ -1702,7 +1704,10 @@ mod test {
}
}
fn test_from_into_public_key_credential_parameter(alg_int: i64, signature_algorithm: SignatureAlgorithm) {
fn test_from_into_public_key_credential_parameter(
alg_int: i64,
signature_algorithm: SignatureAlgorithm,
) {
let cbor_credential_parameter = cbor_map! {
"alg" => alg_int,
"type" => "public-key",

View File

@@ -125,12 +125,16 @@ pub const EDDSA_CRED_PARAM: PublicKeyCredentialParameter = PublicKeyCredentialPa
const SUPPORTED_CRED_PARAMS: &[PublicKeyCredentialParameter] = &[
ES256_CRED_PARAM,
#[cfg(feature = "ed25519")]
#[cfg(feature = "ed25519")]
EDDSA_CRED_PARAM,
];
fn get_preferred_cred_param (params: &[PublicKeyCredentialParameter]) -> Option<&PublicKeyCredentialParameter> {
params.iter().find(|&param| SUPPORTED_CRED_PARAMS.contains(param))
fn get_preferred_cred_param(
params: &[PublicKeyCredentialParameter],
) -> Option<&PublicKeyCredentialParameter> {
params
.iter()
.find(|&param| SUPPORTED_CRED_PARAMS.contains(param))
}
/// Transports supported by OpenSK.