pub trait ToFromBytes: AsRef<[u8]> + Debug + Sized {
    // Required method
    fn from_bytes(bytes: &[u8]) -> Result<Self, FastCryptoError>;

    // Provided method
    fn as_bytes(&self) -> &[u8]  { ... }
}
Expand description

Trait impl’d by concrete types that represent digital cryptographic material (keys).

Key types must (as mandated by the AsRef<[u8]> bound) be a thin wrapper around the “bag-of-bytes” serialized form of a key which can be directly parsed from or written to the “wire”.

The ToFromBytes trait aims to provide similar simplicity by minimizing the number of steps involved to obtain a serializable key and ideally ensuring there is one signature type for any given signature system shared by all “provider” crates.

For signature systems which require a more advanced internal representation (e.g. involving decoded scalars or decompressed elliptic curve points) it’s recommended that “provider” libraries maintain their own internal signature type and use From bounds to provide automatic conversions.

Required Methods§

fn from_bytes(bytes: &[u8]) -> Result<Self, FastCryptoError>

Parse an object from its byte representation

Provided Methods§

fn as_bytes(&self) -> &[u8]

Borrow a byte slice representing the serialized form of this object

Object Safety§

This trait is not object safe.

Implementors§

source§

impl ToFromBytes for GenericSignature

GenericSignature encodes a single signature [enum Signature] as is flag || signature || pubkey. It encodes [struct MultiSigLegacy] as the MultiSig flag (0x03) concat with the bcs serializedbytes of [struct MultiSigLegacy] i.e. flag || bcs_bytes(MultiSigLegacy). [struct Multisig] is encodede as the MultiSig flag (0x03) concat with the bcs serializedbytes of [struct Multisig] i.e. flag || bcs_bytes(Multisig).

source§

impl ToFromBytes for Signature

source§

impl ToFromBytes for MultiSig

source§

impl ToFromBytes for MultiSigLegacy

source§

impl ToFromBytes for ZkLoginAuthenticator

source§

impl ToFromBytes for AuthorityPublicKeyBytes

source§

impl ToFromBytes for Ed25519SuiSignature

source§

impl ToFromBytes for Secp256k1SuiSignature

source§

impl ToFromBytes for Secp256r1SuiSignature

§

impl ToFromBytes for BLS12381AggregateSignature

§

impl ToFromBytes for BLS12381AggregateSignature

§

impl ToFromBytes for BLS12381KeyPair

§

impl ToFromBytes for BLS12381KeyPair

§

impl ToFromBytes for BLS12381PrivateKey

§

impl ToFromBytes for BLS12381PrivateKey

§

impl ToFromBytes for BLS12381PublicKey

§

impl ToFromBytes for BLS12381PublicKey

§

impl ToFromBytes for BLS12381Signature

§

impl ToFromBytes for BLS12381Signature

§

impl ToFromBytes for Ed25519AggregateSignature

§

impl ToFromBytes for Ed25519KeyPair

The bytes form of the keypair always only contain the private key bytes

§

impl ToFromBytes for Ed25519PrivateKey

§

impl ToFromBytes for Ed25519PublicKey

§

impl ToFromBytes for Ed25519Signature

§

impl ToFromBytes for Secp256k1KeyPair

The bytes form of the keypair always only contain the private key bytes

§

impl ToFromBytes for Secp256k1PrivateKey

§

impl ToFromBytes for Secp256k1PublicKey

§

impl ToFromBytes for Secp256k1RecoverableSignature

§

impl ToFromBytes for Secp256k1Signature

§

impl ToFromBytes for Secp256r1KeyPair

The bytes form of the keypair always only contain the private key bytes

§

impl ToFromBytes for Secp256r1PrivateKey

§

impl ToFromBytes for Secp256r1PublicKey

§

impl ToFromBytes for Secp256r1RecoverableSignature

§

impl ToFromBytes for Secp256r1Signature

§

impl<N> ToFromBytes for GenericByteArray<N>
where N: ArrayLength<u8> + Debug,

§

impl<const RECOMMENDED_LENGTH: usize, const FIXED_LENGTH_ONLY: bool> ToFromBytes for PrivateSeed<RECOMMENDED_LENGTH, FIXED_LENGTH_ONLY>