MCPcopy Create free account
hub / github.com/Keats/jsonwebtoken / extract_first_bitstring

Function extract_first_bitstring

src/pem/decoder.rs:188–207  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

186// Though PKCS#11 keys shouldn't have anything else.
187// It will get confusing with certificates.
188fn 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

Callers 3

as_ec_public_keyMethod · 0.85
as_ed_public_keyMethod · 0.85
as_rsa_keyMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected