[][src]Struct seckey::SecKey

pub struct SecKey<T: ?Sized> { /* fields omitted */ }

Secure Key

The use memsec/malloc protection secret bytes.

Note that this does not protect data outside of the secure heap.

More docs see Secure memory · libsodium.

Methods

impl<T> SecKey<T>[src]

pub fn new(t: T) -> Result<SecKey<T>, T>[src]

use seckey::{ free, SecKey };

let k = SecKey::new([1, 2, 3])
    .unwrap_or_else(|mut val| {
        // NOTE should zero it
        free(val);
        panic!()
    });
assert_eq!([1, 2, 3], *k.read());

pub unsafe fn from_ptr(t: *const T) -> Option<SecKey<T>>[src]

use seckey::SecKey;

let mut v = [1, 2, 3];
let k = unsafe { SecKey::from_ptr(&v).unwrap() };
assert_eq!([1, 2, 3], v);
assert_eq!([1, 2, 3], *k.read());

pub unsafe fn with<F>(f: F) -> Option<SecKey<T>> where
    F: FnOnce(*mut T), 
[src]

use seckey::SecKey;

let k: SecKey<u32> = unsafe { SecKey::with(|ptr| *ptr = 1).unwrap() };
assert_eq!(1, *k.read());

impl<T: Copy> SecKey<T>[src]

pub fn from_ref(t: &T) -> Option<SecKey<T>>[src]

impl<T: Default> SecKey<T>[src]

pub fn with_default<F>(f: F) -> Option<SecKey<T>> where
    F: FnOnce(&mut T), 
[src]

use seckey::SecKey;

let k: SecKey<u32> = SecKey::with_default(|ptr| *ptr += 1).unwrap();
assert_eq!(1, *k.read());

impl SecKey<[u8]>[src]

pub fn from_bytes(src: &mut [u8]) -> Option<SecKey<[u8]>>[src]

On success src is zeroed and a new protected SecKey<[u8]> is returned. On failure src remains untouched and None is returned.

use seckey::SecKey;

let mut unprotected = [1u8; 2];
let k = SecKey::from_bytes(&mut unprotected[..]).unwrap();

assert_eq!(unprotected, [0u8; 2]);
assert_eq!(*k.read(), [1u8; 2]);

impl SecKey<str>[src]

pub fn from_str(src: &mut str) -> Option<SecKey<str>>[src]

On success src is zeroed and a new protected SecKey<str> is returned. On failure src remains untouched and None is returned.

use seckey::SecKey;

let mut unprotected = "abc".to_string();
let k = SecKey::from_str(&mut unprotected).unwrap();

assert_eq!(&unprotected, "\0\0\0");
assert_eq!(&*k.read(), "abc");

impl<T: ?Sized> SecKey<T>[src]

pub fn read(&self) -> SecReadGuard<T>[src]

Borrow Read

use seckey::SecKey;

let secpass = SecKey::new([8u8; 8]).unwrap();
assert_eq!([8u8; 8], *secpass.read());

pub fn write(&mut self) -> SecWriteGuard<T>[src]

Borrow Write

let mut wpass = secpass.write();
wpass[0] = 0;
assert_eq!([0, 8, 8, 8, 8, 8, 8, 8], *wpass);

Trait Implementations

impl<T: ?Sized> Debug for SecKey<T>[src]

impl<T: ?Sized> Drop for SecKey<T>[src]

impl<T: ?Sized> Pointer for SecKey<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for SecKey<T>

impl<T> !Send for SecKey<T>

impl<T> !Sync for SecKey<T>

impl<T: ?Sized> Unpin for SecKey<T>

impl<T: ?Sized> UnwindSafe for SecKey<T> where
    T: RefUnwindSafe

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, 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.