3 unstable releases

0.2.1 Apr 15, 2022
0.2.0 Jul 2, 2020
0.1.0 Jun 17, 2020

#2459 in Cryptography

MIT license

36KB
738 lines

pz

PZip Docs

Implementation of the PZip format in Rust.


lib.rs:

Implementation of the PZip format in Rust.

Streaming example:

use std::io;
use pzip::{PZip, Password, Algorithm, Compression, Error, PZipKey};

fn main() -> Result<(), Error> {
    let plaintext = b"hello world";
    let mut ciphertext = Vec::<u8>::new();
    let mut check = Vec::<u8>::new();
    let key = Password("pzip");
    PZip::encrypt_to(
        &mut io::Cursor::new(plaintext),
        &mut ciphertext,
        Algorithm::AesGcm256,
        &key,
        Compression::None,
    )?;
    PZip::decrypt_to(
        &mut io::Cursor::new(ciphertext),
        &mut check,
        key.material()
    )?;
    assert_eq!(check, plaintext);
    Ok(())
}

One-shot example:

use pzip::{PZip, Password, Algorithm, Compression, Error, PZipKey};

fn main() -> Result<(), Error> {
    let key = Password("secret");
    let plaintext = b"hello world";
    let ciphertext = PZip::encrypt(
        plaintext,
        Algorithm::AesGcm256,
        &key,
        Compression::None
    )?;
    let check = PZip::decrypt(&ciphertext, key.material())?;
    assert_eq!(check, plaintext);
    Ok(())
}

Dependencies

~7–14MB
~261K SLoC