Sha256: 1d768a4f2be48bd30a08743366d6fcc1ccedeca135e2f93d4d0496b881c17eda

Contents?: true

Size: 881 Bytes

Versions: 4

Compression:

Stored size: 881 Bytes

Contents

extern crate libpasta;
extern crate ring;

use ring::digest;

#[test]
fn test_hmac() {
    // Use scrypt as the default inner hash
    let hash_primitive = libpasta::primitives::Scrypt::default();
    let mut config = libpasta::Config::with_primitive(hash_primitive);

    // Some proper way of getting a key
    let key = b"yellow submarine";
    let key_id = config.add_key(key);
    // Construct an HMAC instance and use this as the outer configuration
    let keyed_function = libpasta::primitives::Hmac::with_key_id(&digest::SHA256, &key_id);
    config.set_keyed_hash(keyed_function);

    let hash = config.hash_password("hunter2");
    println!("Computed hash: {:?}", hash);
    // Outputs:
    // Computed hash: "$!$hmac$key_id=LNMhDy...,h=SHA256$$scrypt$ln=14,r=8,p=1$ZJ5EY...$grlNA...."

    assert!(hash.starts_with("$!$hmac"));
    assert!(hash.contains("scrypt"));
}

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/tests/test_hmac.rs
libpasta-0.0.6-x86_64-linux ext/pasta-bindings/libpasta/tests/test_hmac.rs
libpasta-0.0.5 ext/pasta-bindings/libpasta/tests/test_hmac.rs
libpasta-0.0.5-x86_64-linux ext/pasta-bindings/libpasta/tests/test_hmac.rs