pub fn import_pub(bs: &[u8]) -> Result<[u8; 32]> {
    if let [ASN1Block::Sequence(_, subject_public_key_info)] = simple_asn1::from_der(bs)
        .map_err(|u| Error::KeyImport(u.to_string()))?
        .as_slice()
    {
        if let [ASN1Block::Sequence(_, algorithm), ASN1Block::BitString(_, 256, subject_public_key)] =
            subject_public_key_info.as_slice()
        {
            if let [ASN1Block::ObjectIdentifier(_, oid)] = algorithm.as_slice() {
                if oid == oid_x25519() {
                    let mut bs = [0u8; 32];
                    bs.copy_from_slice(&subject_public_key);
                    return Ok(bs);
                }
                return Err(Error::KeyImport("unsupported public key type".to_owned()));
            }
        }
    }
    Err(Error::KeyImport(
        "invalid/ unsupported public key".to_owned(),
    ))
}
// ASN1 DER import/ export functions.
// https://tools.ietf.org/html/rfc8410
// https://tools.ietf.org/html/rfc5958
ASN1 DER import/ export functions.
ASN1 DER import / export functions .
pub fn import_pub(bs: &[u8]) -> Result<[u8; 32]> {
    if let [ASN1Block::Sequence(_, subject_public_key_info)] = simple_asn1::from_der(bs)
        .map_err(|u| Error::KeyImport(u.to_string()))?
        .as_slice()
    {
        if let [ASN1Block::Sequence(_, algorithm), ASN1Block::BitString(_, 256, subject_public_key)] =
            subject_public_key_info.as_slice()
        {
            if let [ASN1Block::ObjectIdentifier(_, oid)] = algorithm.as_slice() {
                if oid == oid_x25519() {
                    let mut bs = [0u8; 32];
                    bs.copy_from_slice(&subject_public_key);
                    return Ok(bs);
                }
                return Err(Error::KeyImport("unsupported public key type".to_owned()));
            }
        }
    }
    Err(Error::KeyImport(
        "invalid/ unsupported public key".to_owned(),
    ))
}
pub fn import_pub ( bs : & [ u8 ] ) -> Result < [ u8 ; 32 ] > { if let [ ASN1Block :: Sequence ( _ , subject_public_key_info ) ] = simple_asn1 :: from_der ( bs ) . map_err ( | u | Error :: KeyImport ( u . to_string ( ) ) ) ? . as_slice ( ) { if let [ ASN1Block :: Sequence ( _ , algorithm ) , ASN1Block :: BitString ( _ , 256 , subject_public_key ) ] = subject_public_key_info . as_slice ( ) { if let [ ASN1Block :: ObjectIdentifier ( _ , oid ) ] = algorithm . as_slice ( ) { if oid == oid_x25519 ( ) { let mut bs = [ 0u8 ; 32 ] ; bs . copy_from_slice ( & subject_public_key ) ; return Ok ( bs ) ; } return Err ( Error :: KeyImport ( " " . to_owned ( ) ) ) ; } } } Err ( Error :: KeyImport ( " " . to_owned ( ) , ) ) }
ASN1 DER import/ export functions.
ASN1 DER import / export functions .
bs
&[u8]
bs
&[u8]