[][src]Trait tari_utilities::byte_array::ByteArray

pub trait ByteArray {
    fn from_bytes(bytes: &[u8]) -> Result<Self, ByteArrayError>
    where
        Self: Sized
;
fn as_bytes(&self) -> &[u8]; fn to_hex(&self) -> String { ... }
fn from_hex(hex: &str) -> Result<Self, ByteArrayError>
    where
        Self: Sized
, { ... }
fn to_vec(&self) -> Vec<u8> { ... }
fn from_vec(v: &Vec<u8>) -> Result<Self, ByteArrayError>
    where
        Self: Sized
, { ... } }

Many of the types in this crate are just large numbers (256 bit usually). This trait provides the common functionality for types like secret keys, signatures, commitments etc. to be converted to and from byte arrays and hexadecimal formats.

Required methods

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

Try and convert the given byte array to the implemented type. Any failures (incorrect array length, implementation-specific checks, etc) return a ByteArrayError.

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

Return the type as a byte array

Loading content...

Provided methods

fn to_hex(&self) -> String

Return the hexadecimal string representation of the type

fn from_hex(hex: &str) -> Result<Self, ByteArrayError> where
    Self: Sized

Try and convert the given hexadecimal string to the type. Any failures (incorrect string length, non hex characters, etc) return a KeyError with an explanatory note.

fn to_vec(&self) -> Vec<u8>

Return the type as a byte vector

fn from_vec(v: &Vec<u8>) -> Result<Self, ByteArrayError> where
    Self: Sized

Try and convert the given byte vector to the implemented type. Any failures (incorrect string length etc) return a KeyError with an explanatory note.

Loading content...

Implementations on Foreign Types

impl ByteArray for Vec<u8>[src]

fn from_hex(hex: &str) -> Result<Self, ByteArrayError> where
    Self: Sized
[src]

Try and convert the given hexadecimal string to the type. Any failures (incorrect string length, non hex characters, etc) return a KeyError with an explanatory note.

impl ByteArray for [u8; 32][src]

fn to_hex(&self) -> String[src]

fn from_hex(hex: &str) -> Result<Self, ByteArrayError> where
    Self: Sized
[src]

fn to_vec(&self) -> Vec<u8>[src]

fn from_vec(v: &Vec<u8>) -> Result<Self, ByteArrayError> where
    Self: Sized
[src]

Loading content...

Implementors

Loading content...