webauthn-rs-proto

Patched webauthn-rs-proto (https://crates.io/crates/webauthn-rs-proto) that adds support for Ed25519.
git clone https://git.philomathiclife.com/repos/webauthn-rs-proto
Log | Files | Refs | README | LICENSE

cose.rs (3498B)


      1 //! Types related to CBOR Object Signing and Encryption (COSE)
      2 
      3 use serde::{Deserialize, Serialize};
      4 
      5 /// A COSE signature algorithm, indicating the type of key and hash type
      6 /// that should be used. You shouldn't need to alter or use this value.
      7 #[allow(non_camel_case_types)]
      8 #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
      9 #[repr(i32)]
     10 pub enum COSEAlgorithm {
     11     #[serde(alias = "Ed25519")]
     12     /// Identifies this key as EdDSA (likely curve Ed25519).
     13     EdDSA = -8,
     14     /// Identifies this key as ECDSA (recommended SECP256R1) with SHA256 hashing
     15     #[serde(alias = "ECDSA_SHA256")]
     16     ES256 = -7, // recommends curve SECP256R1
     17     /// Identifies this key as ECDSA (recommended SECP384R1) with SHA384 hashing
     18     #[serde(alias = "ECDSA_SHA384")]
     19     ES384 = -35, // recommends curve SECP384R1
     20     /// Identifies this key as ECDSA (recommended SECP521R1) with SHA512 hashing
     21     #[serde(alias = "ECDSA_SHA512")]
     22     ES512 = -36, // recommends curve SECP521R1
     23     /// Identifies this key as RS256 aka RSASSA-PKCS1-v1_5 w/ SHA-256
     24     RS256 = -257,
     25     /// Identifies this key as RS384 aka RSASSA-PKCS1-v1_5 w/ SHA-384
     26     RS384 = -258,
     27     /// Identifies this key as RS512 aka RSASSA-PKCS1-v1_5 w/ SHA-512
     28     RS512 = -259,
     29     /// Identifies this key as PS256 aka RSASSA-PSS w/ SHA-256
     30     PS256 = -37,
     31     /// Identifies this key as PS384 aka RSASSA-PSS w/ SHA-384
     32     PS384 = -38,
     33     /// Identifies this key as PS512 aka RSASSA-PSS w/ SHA-512
     34     PS512 = -39,
     35     /// Identifies this as an INSECURE RS1 aka RSASSA-PKCS1-v1_5 using SHA-1. This is not
     36     /// used by validators, but can exist in some windows hello tpm's
     37     INSECURE_RS1 = -65535,
     38     /// Identifies this key as the protocol used for [PIN/UV Auth Protocol One](https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#pinProto1)
     39     ///
     40     /// This reports as algorithm `-25`, but it is a lie. Don't include this in any algorithm lists.
     41     PinUvProtocol,
     42 }
     43 
     44 impl COSEAlgorithm {
     45     /// Return the set of secure recommended COSEAlgorithm's
     46     pub fn secure_algs() -> Vec<Self> {
     47         vec![
     48             COSEAlgorithm::EdDSA,
     49             COSEAlgorithm::ES256,
     50             COSEAlgorithm::RS256,
     51         ]
     52     }
     53 
     54     /// Return the set of all possible algorithms that may exist as a COSEAlgorithm
     55     pub fn all_possible_algs() -> Vec<Self> {
     56         vec![
     57             COSEAlgorithm::EdDSA,
     58             COSEAlgorithm::ES256,
     59             COSEAlgorithm::ES384,
     60             COSEAlgorithm::ES512,
     61             COSEAlgorithm::RS256,
     62             COSEAlgorithm::RS384,
     63             COSEAlgorithm::RS512,
     64             COSEAlgorithm::PS256,
     65             COSEAlgorithm::PS384,
     66             COSEAlgorithm::PS512,
     67             COSEAlgorithm::INSECURE_RS1,
     68         ]
     69     }
     70 }
     71 
     72 impl TryFrom<i128> for COSEAlgorithm {
     73     type Error = ();
     74 
     75     fn try_from(i: i128) -> Result<Self, Self::Error> {
     76         match i {
     77             -8 => Ok(COSEAlgorithm::EdDSA),
     78             -7 => Ok(COSEAlgorithm::ES256),
     79             -35 => Ok(COSEAlgorithm::ES384),
     80             -36 => Ok(COSEAlgorithm::ES512),
     81             -257 => Ok(COSEAlgorithm::RS256),
     82             -258 => Ok(COSEAlgorithm::RS384),
     83             -259 => Ok(COSEAlgorithm::RS512),
     84             -37 => Ok(COSEAlgorithm::PS256),
     85             -38 => Ok(COSEAlgorithm::PS384),
     86             -39 => Ok(COSEAlgorithm::PS512),
     87             -65535 => Ok(COSEAlgorithm::INSECURE_RS1),
     88             _ => Err(()),
     89         }
     90     }
     91 }