ECKeyBase

Trait ECKeyBase 

Source
pub trait ECKeyBase:
    Display
    + Debug
    + Clone
    + PartialEq
    + Eq
    + Hash {
    const KEY_SIZE: usize;

    // Required methods
    fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Self>
       where Self: Sized;
    fn data(&self) -> &[u8] ;

    // Provided methods
    fn hex(&self) -> String { ... }
    fn from_hex(hex: impl AsRef<str>) -> Result<Self> { ... }
}
Expand description

A base trait for all elliptic curve keys.

This trait defines common functionality for all elliptic curve keys, including both private and public keys. It provides methods for key construction from binary data and hexadecimal strings, as well as conversion to hexadecimal format.

All EC key types have a fixed size depending on their specific type:

  • EC private keys: 32 bytes
  • EC compressed public keys: 33 bytes
  • EC uncompressed public keys: 65 bytes
  • Schnorr public keys: 32 bytes

Required Associated Constants§

Source

const KEY_SIZE: usize

The size of the key in bytes.

Required Methods§

Source

fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Self>
where Self: Sized,

Creates a key from a reference to binary data.

Returns an error if the data is not valid for this key type.

Source

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

Returns the key’s binary data.

Provided Methods§

Source

fn hex(&self) -> String

Returns the key as a hexadecimal string.

Source

fn from_hex(hex: impl AsRef<str>) -> Result<Self>

Creates a key from a hexadecimal string.

Returns an error if the string is not valid hexadecimal or if the resulting data is not valid for this key type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl ECKeyBase for ECPrivateKey

Implements the ECKeyBase trait methods.

Source§

const KEY_SIZE: usize = 32usize

Source§

impl ECKeyBase for ECPublicKey

Implements the ECKeyBase trait methods for ECPublicKey.

Source§

const KEY_SIZE: usize = 33usize

Source§

impl ECKeyBase for ECUncompressedPublicKey

Implements the ECKeyBase trait methods for ECUncompressedPublicKey.

Source§

const KEY_SIZE: usize = 65usize

Source§

impl ECKeyBase for SchnorrPublicKey

Implements the ECKeyBase trait methods for SchnorrPublicKey.

Source§

const KEY_SIZE: usize = 32usize