[][src]Struct cryptovec::CryptoVec

pub struct CryptoVec { /* fields omitted */ }

A buffer which zeroes its memory on .clear(), .resize() and reallocations, to avoid copying secrets around.

Implementations

impl CryptoVec[src]

pub fn new() -> CryptoVec

Notable traits for CryptoVec

impl Write for CryptoVec
[src]

Creates a new CryptoVec.

pub fn new_zeroed(size: usize) -> CryptoVec

Notable traits for CryptoVec

impl Write for CryptoVec
[src]

Creates a new CryptoVec with n zeros.

pub fn with_capacity(capacity: usize) -> CryptoVec

Notable traits for CryptoVec

impl Write for CryptoVec
[src]

Creates a new CryptoVec with capacity capacity.

pub fn len(&self) -> usize[src]

Length of this CryptoVec.

assert_eq!(cryptovec::CryptoVec::new().len(), 0)

pub fn is_empty(&self) -> bool[src]

Returns true if and only if this CryptoVec is empty.

assert!(cryptovec::CryptoVec::new().is_empty())

pub fn resize(&mut self, size: usize)[src]

Resize this CryptoVec, appending zeros at the end. This may perform at most one reallocation, overwriting the previous version with zeros.

pub fn clear(&mut self)[src]

Clear this CryptoVec (retaining the memory).

let mut v = cryptovec::CryptoVec::new();
v.extend(b"blabla");
v.clear();
assert!(v.is_empty())

pub fn push(&mut self, s: u8)[src]

Append a new byte at the end of this CryptoVec.

pub fn push_u32_be(&mut self, s: u32)[src]

Append a new u32, big endian-encoded, at the end of this CryptoVec.

let mut v = cryptovec::CryptoVec::new();
let n = 43554;
v.push_u32_be(n);
assert_eq!(n, v.read_u32_be(0))

pub fn read_u32_be(&self, i: usize) -> u32[src]

Read a big endian-encoded u32 from this CryptoVec, with the first byte at position i.

let mut v = cryptovec::CryptoVec::new();
let n = 99485710;
v.push_u32_be(n);
assert_eq!(n, v.read_u32_be(0))

pub fn read<R: Read>(&mut self, n_bytes: usize, r: R) -> Result<usize, Error>[src]

Read n_bytes from r, and append them at the end of this CryptoVec. Returns the number of bytes read (and appended).

pub fn write_all_from<W: Write>(
    &self,
    offset: usize,
    w: W
) -> Result<usize, Error>
[src]

Write all this CryptoVec to the provided Write. Returns the number of bytes actually written.

let mut v = cryptovec::CryptoVec::new();
v.extend(b"blabla");
let mut s = std::io::stdout();
v.write_all_from(0, &mut s).unwrap();

pub fn resize_mut(&mut self, n: usize) -> &mut [u8][src]

Resize this CryptoVec, returning a mutable borrow to the extra bytes.

let mut v = cryptovec::CryptoVec::new();
v.resize_mut(4).clone_from_slice(b"test");

pub fn extend(&mut self, s: &[u8])[src]

Append a slice at the end of this CryptoVec.

let mut v = cryptovec::CryptoVec::new();
v.extend(b"test");

pub fn from_slice(s: &[u8]) -> CryptoVec

Notable traits for CryptoVec

impl Write for CryptoVec
[src]

Create a CryptoVec from a slice

CryptoVec::from_slice(b"test");

Trait Implementations

impl AsMut<[u8]> for CryptoVec[src]

impl AsRef<[u8]> for CryptoVec[src]

impl Clone for CryptoVec[src]

impl Debug for CryptoVec[src]

impl Default for CryptoVec[src]

impl Deref for CryptoVec[src]

type Target = [u8]

The resulting type after dereferencing.

impl DerefMut for CryptoVec[src]

impl Drop for CryptoVec[src]

impl From<String> for CryptoVec[src]

impl From<Vec<u8>> for CryptoVec[src]

impl Index<Range<usize>> for CryptoVec[src]

type Output = [u8]

The returned type after indexing.

impl Index<RangeFrom<usize>> for CryptoVec[src]

type Output = [u8]

The returned type after indexing.

impl Index<RangeFull> for CryptoVec[src]

type Output = [u8]

The returned type after indexing.

impl Index<RangeTo<usize>> for CryptoVec[src]

type Output = [u8]

The returned type after indexing.

impl Index<usize> for CryptoVec[src]

type Output = u8

The returned type after indexing.

impl IndexMut<Range<usize>> for CryptoVec[src]

impl IndexMut<RangeFrom<usize>> for CryptoVec[src]

impl IndexMut<RangeFull> for CryptoVec[src]

impl IndexMut<RangeTo<usize>> for CryptoVec[src]

impl Send for CryptoVec[src]

impl Sync for CryptoVec[src]

impl Unpin for CryptoVec[src]

impl Write for CryptoVec[src]

Auto Trait Implementations

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<T> From<T> for T[src]

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

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.