[][src]Struct simple_secrets::Packet

pub struct Packet { /* fields omitted */ }

Converts serializable data to and from websafe strings.

Methods

impl Packet
[src]

pub fn new(master: String) -> Result<Packet, SimpleSecretsError>
[src]

Construct a Packet with the given master key. Must be 64 hex characters.

Errors

Returns an error if there is a problem with the key. The error kind can be:

Examples

use simple_secrets::Packet;
// Try `head /dev/urandom | shasum -a 256` to make a decent 256-bit key
let sender = Packet::new("<64-char hex string master key (32 bytes, 256 bits)>".to_string());

pub fn pack<T: ?Sized>(&self, value: &T) -> Result<String, SimpleSecretsError> where
    T: Serialize
[src]

Turn a Rust type into an encrypted packet. This object will possibly be deserialized in a different programming environment—it should be JSON-like in structure.

Errors

Returns a SimpleSecretsError if there is a problem at any point in the process of serializing, encrypting, authenticating, and serializing the data. The various scenarios are described in the doc for that error type.

Examples

use simple_secrets::Packet;
// Try `head /dev/urandom | shasum -a 256` to make a decent 256-bit key
let sender = Packet::new("<64-char hex string master key (32 bytes, 256 bits)>".to_string());
let packet = sender.pack("this is a secret message").unwrap();
assert_eq!(packet, "Qr4m7AughkcQIRqQvlyXiB67EwHdBf5n9J\
                    D2s_Z9NpO4ksPGvLYjNbDm3HRzvFXFSpV2\
                    IqDQw_LTamndMh2c7iOQT0lSp4LstqJPAt\
                    oQklU5sb7JHYyTOuf-6W-q7W8gAnq1wCs5");

pub fn unpack<'a, T>(&self, websafe: String) -> Result<T, SimpleSecretsError> where
    T: Deserialize<'a>, 
[src]

Turn an encrypted packet into a Rust structure. This object possibly originated in a different programming environment—it should be JSON-like in structure.

Errors

Returns a SimpleSecretsError if there is a problem at any point in the process of decoding, verifying, decrypting, and deserializing the data. The various scenarios are described in the doc for that error type.

Examples

use simple_secrets::Packet;
// Try `head /dev/urandom | shasum -a 256` to make a decent 256-bit key
let sender = Packet::new("<64-char hex string master key (32 bytes, 256 bits)>".to_string());
// Read data from somewhere
let packet = "OqlG6KVMeyFYmunboS3HIXkvN_nXKTxg2y\
              NkQydZOhvJrZvmfov54hUmkkiZCnlhzyrl\
              wOJkbV7XnPPbqvdzZ6TsFOO5YdmxjxRksZ\
              meIhbhLaMiDbfsOuSY1dBn_ZgtYCw-FRIM".to_string();
let secret_message = sender.unpack(packet)?;
// equivalent of => { "msg": "this is a secret message" }

pub fn pack_raw(&self, data: &mut Vec<u8>) -> Result<String, SimpleSecretsError>
[src]

Encrypt a packet into raw bytes. This allows the caller to issue app-specific typesafe serialization calls beforehand.

pub fn unpack_raw(&self, websafe: String) -> Result<Vec<u8>, SimpleSecretsError>
[src]

Decrypt a packet into raw bytes. This allows the caller to issue app-specific typesafe deserialization calls later.

Trait Implementations

impl From<[u8; 32]> for Packet
[src]

fn from(key: [u8; 32]) -> Self
[src]

Construct a Packet with the given 256-bit master key.

impl Drop for Packet
[src]

fn drop(&mut self)
[src]

Ensure that sensitive data is removed from memory

Auto Trait Implementations

impl Send for Packet

impl Sync for Packet

Blanket Implementations

impl<T> From for T
[src]

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

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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