[][src]Struct xaynet::message::SumBuffer

pub struct SumBuffer<T> { /* fields omitted */ }

A wrapper around a buffer that contains a Sum message.

It provides getters and setters to access the different fields of the message safely.

Examples

Decoding a sum message

let sum_signature = vec![0x11; 64];
let ephm_pk = vec![0x22; 32];
let bytes = [sum_signature.as_slice(), ephm_pk.as_slice()].concat();
let buffer = SumBuffer::new(&bytes).unwrap();
assert_eq!(buffer.sum_signature(), sum_signature.as_slice());
assert_eq!(buffer.ephm_pk(), ephm_pk.as_slice());

Encoding a sum message

let sum_signature = vec![0x11; 64];
let ephm_pk = vec![0x22; 32];
let mut storage = vec![0xff; 96];
let mut buffer = SumBuffer::new_unchecked(&mut storage);
buffer
    .sum_signature_mut()
    .copy_from_slice(&sum_signature[..]);
buffer.ephm_pk_mut().copy_from_slice(&ephm_pk[..]);
assert_eq!(&storage[..64], sum_signature.as_slice());
assert_eq!(&storage[64..], ephm_pk.as_slice());

Implementations

impl<T: AsRef<[u8]>> SumBuffer<T>[src]

pub fn new(bytes: T) -> Result<Self, DecodeError>[src]

Performs bound checks for the various message fields on bytes and returns a new SumBuffer.

Errors

Fails if the bytes are smaller than a minimal-sized sum message buffer.

pub fn new_unchecked(bytes: T) -> Self[src]

Returns a SumBuffer without performing any bound checks.

This means accessing the various fields may panic if the data is invalid.

pub fn check_buffer_length(&self) -> Result<(), DecodeError>[src]

Performs bound checks to ensure the fields can be accessed without panicking.

impl<T: AsMut<[u8]>> SumBuffer<T>[src]

pub fn ephm_pk_mut(&mut self) -> &mut [u8][src]

Gets a mutable reference to the sum participant ephemeral public key field.

Panics

Accessing the field may panic if the buffer has not been checked before.

pub fn sum_signature_mut(&mut self) -> &mut [u8][src]

Gets a mutable reference to the sum signature field.

Panics

Accessing the field may panic if the buffer has not been checked before.

impl<'a, T: AsRef<[u8]> + ?Sized> SumBuffer<&'a T>[src]

pub fn ephm_pk(&self) -> &'a [u8][src]

Gets a reference to the sum participant ephemeral public key field.

Panics

Accessing the field may panic if the buffer has not been checked before.

pub fn sum_signature(&self) -> &'a [u8][src]

Gets a reference to the sum signature field.

Panics

Accessing the field may panic if the buffer has not been checked before.

Trait Implementations

impl<T: Clone> Clone for SumBuffer<T>[src]

impl<T: Debug> Debug for SumBuffer<T>[src]

impl<T: Eq> Eq for SumBuffer<T>[src]

impl<T: Hash> Hash for SumBuffer<T>[src]

impl<T: PartialEq> PartialEq<SumBuffer<T>> for SumBuffer<T>[src]

impl<T> StructuralEq for SumBuffer<T>[src]

impl<T> StructuralPartialEq for SumBuffer<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for SumBuffer<T> where
    T: RefUnwindSafe

impl<T> Send for SumBuffer<T> where
    T: Send

impl<T> Sync for SumBuffer<T> where
    T: Sync

impl<T> Unpin for SumBuffer<T> where
    T: Unpin

impl<T> UnwindSafe for SumBuffer<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]