Crate hapi_iron_oxide

Crate hapi_iron_oxide 

Source
Expand description

§hapi-iron-oxide

This module is made to be compatible with brc-dd/iron-webcrypto, which is the crate that backs vvo/iron-session. This allows APIs made in Rust be able to talk to Next.js.

§Installation

cargo add hapi-iron-oxide

§Usage

use hapi_iron_oxide::{seal, unseal};

let password = "passwordpasswordpasswordpasswordpasswordpasswordpasswordpassword";
let data = "Hello World Please";

let sealed = seal::<32, 32, _>(data.to_string(), password, Default::default()).unwrap();
let unsealed = unseal(sealed, password.clone(), Default::default());

assert_eq!(unsealed.unwrap(), data.to_string());

The options struct can be customized like This

use hapi_iron_oxide::*;
use hapi_iron_oxide::options::EncryptionOptions;
use hapi_iron_oxide::algorithm::Algorithm;

let password = "passwordpasswordpasswordpasswordpasswordpasswordpasswordpassword";
let data = "Hello World Please";

let options = SealOptionsBuilder::new().ttl(1000).finish();

assert_eq!(
    options,
    SealOptions {
        encryption: EncryptionOptions {
            algorithm: Algorithm::Aes256Cbc,
            iterations: 1,
            minimum_password_length: 32,
        },
        integrity: EncryptionOptions {
            algorithm: Algorithm::Sha256,
            iterations: 1,
            minimum_password_length: 32,
        },
        ttl: 1000,
        timestamp_skew: 60,
        local_offset: 0,
    }
);

let sealed = seal::<32, 32, _>(data.to_string(), password, options).unwrap();
assert!(!sealed.is_empty());

§Thank you

Thank you to

Re-exports§

pub use options::SealOptions;
pub use options::SealOptionsBuilder;

Modules§

algorithm
base64_engine
constants
encryption
errors
hmac_sign
key
options
password

Functions§

seal
Creates sealed string from given options.
unseal
Unseal the sealed string back into the original string.