Sha256: e1280064ed4ea04fa648d5024be2f11fee8f4592b1989c8d6e6c60c3bdd51f69

Contents?: true

Size: 916 Bytes

Versions: 4

Compression:

Stored size: 916 Bytes

Contents

extern crate libpasta;
extern crate ring;

use libpasta::key;
use ring::digest;

#[derive(Debug)]
struct StaticSource(&'static [u8; 16]);
static STATIC_SOURCE: StaticSource = StaticSource(b"ThisIsAStaticKey");

impl key::Store for StaticSource {
    /// Insert a new key into the `Store`.
    fn insert(&self, _key: &[u8]) -> String {
        "StaticKey".to_string()
    }

    /// Get a key from the `Store`.
    fn get_key(&self, _id: &str) -> Option<Vec<u8>> {
        Some(self.0.to_vec())
    }
}

fn main() {
    let mut config = libpasta::Config::default();
    config.set_key_source(&STATIC_SOURCE);

    // Construct an HMAC instance and use this as the outer configuration
    let keyed_function = libpasta::primitives::Hmac::with_key_id(&digest::SHA256, "StaticKey");
    config.set_keyed_hash(keyed_function);

    let hash = config.hash_password("hunter2");
    println!("Computed hash: {:?}", hash);
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
libpasta-0.1.0.pre.rc0-x86_64-linux ext/pasta-bindings/libpasta/examples/alternate_key_source.rs
libpasta-0.0.6-x86_64-linux ext/pasta-bindings/libpasta/examples/alternate_key_source.rs
libpasta-0.0.5 ext/pasta-bindings/libpasta/examples/alternate_key_source.rs
libpasta-0.0.5-x86_64-linux ext/pasta-bindings/libpasta/examples/alternate_key_source.rs