[−][src]Struct xaynet::message::SumBuffer
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]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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,
T: RefUnwindSafe,
impl<T> Send for SumBuffer<T> where
T: Send,
T: Send,
impl<T> Sync for SumBuffer<T> where
T: Sync,
T: Sync,
impl<T> Unpin for SumBuffer<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for SumBuffer<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> WithSubscriber for T
[src]
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,