This really just finds and returns the first bitstring or octet string Which is the x coordinate for EC public keys And the DER contents of an RSA key Though PKCS#11 keys shouldn't have anything else. It will get confusing with certificates.
(asn1: &[simple_asn1::ASN1Block])
| 186 | // Though PKCS#11 keys shouldn't have anything else. |
| 187 | // It will get confusing with certificates. |
| 188 | fn extract_first_bitstring(asn1: &[simple_asn1::ASN1Block]) -> Result<&[u8]> { |
| 189 | for asn1_entry in asn1 { |
| 190 | match asn1_entry { |
| 191 | simple_asn1::ASN1Block::Sequence(_, entries) => { |
| 192 | if let Ok(result) = extract_first_bitstring(entries) { |
| 193 | return Ok(result); |
| 194 | } |
| 195 | } |
| 196 | simple_asn1::ASN1Block::BitString(_, _, value) => { |
| 197 | return Ok(value.as_ref()); |
| 198 | } |
| 199 | simple_asn1::ASN1Block::OctetString(_, value) => { |
| 200 | return Ok(value.as_ref()); |
| 201 | } |
| 202 | _ => (), |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | Err(ErrorKind::InvalidEcdsaKey.into()) |
| 207 | } |
| 208 | |
| 209 | /// Find whether this is EC, RSA, or Ed |
| 210 | /// Note: Ed448 keys are not supported |
no outgoing calls
no test coverage detected