/// Construct a `PublicKey` from a slice of bytes.
/// Bytes are expected to be either a raw key or encoded in ASN.1.
Construct a `PublicKey` from a slice of bytes.
Bytes are expected to be either a raw key or encoded in ASN.1.
Construct a ` PublicKey ` from a slice of bytes . Bytes are expected to be either a raw key or encoded in ASN . 1 .
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, HederaError> {
        let bytes = bytes.as_ref();
        if bytes.len() == ed25519_dalek::PUBLIC_KEY_LENGTH {
            // If the buffer is exactly the length of a public key; assume that this is
            // a raw key and return it directly
            return Ok(PublicKey(ed25519_dalek::PublicKey::from_bytes(bytes)?));
        }
        let info: SubjectPublicKeyInfo = der_decode(&bytes)?;
        if info.algorithm.algorithm != *OID_ED25519 {
            return Err(HederaError::UnknownPublicKeyAlgorithm);
        }
        if info.subject_public_key.len() != ed25519_dalek::PUBLIC_KEY_LENGTH {
            return Err(HederaError::InvalidPublicKeyLength);
        }
        Ok(PublicKey(ed25519_dalek::PublicKey::from_bytes(
            &info.subject_public_key,
        )?))
    }
pub fn from_bytes ( bytes : impl AsRef < [ u8 ] > ) -> Result < Self , HederaError > { let bytes = bytes . as_ref ( ) ; if bytes . len ( ) == ed25519_dalek :: PUBLIC_KEY_LENGTH { // If the buffer is exactly the length of a public key; assume that this is // a raw key and return it directly return Ok ( PublicKey ( ed25519_dalek :: PublicKey :: from_bytes ( bytes ) ? ) ) ; } let info : SubjectPublicKeyInfo = der_decode ( & bytes ) ? ; if info . algorithm . algorithm != * OID_ED25519 { return Err ( HederaError :: UnknownPublicKeyAlgorithm ) ; } if info . subject_public_key . len ( ) != ed25519_dalek :: PUBLIC_KEY_LENGTH { return Err ( HederaError :: InvalidPublicKeyLength ) ; } Ok ( PublicKey ( ed25519_dalek :: PublicKey :: from_bytes ( & info . subject_public_key , ) ? ) ) }
Construct a `PublicKey` from a slice of bytes.
Construct a ` PublicKey ` from a slice of bytes .
bytes
impl AsRef<[u8]>