Crate pzip

Source
Expand description

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(())
}

Structs§

  • A key of any length (longer is better) that will be derived with HKDF-SHA256.
  • Structure for holding information about a PZip archive, and a namespace for common operations.
  • Reader for PZip files.
  • Writer for PZip files.
  • A password that will be encoded as UTF-8 and derived with PBKDF2-SHA256.
  • A raw key (no derivation) for encryption and decryption. Must match the expected key size of the Algorithm being used.

Enums§

  • The encryption algorithms known by PZip.
  • The compression methods known by PZip.
  • The multitude of ways this crate can fail.
  • The key derivation functions (KDFs) known by PZip.
  • Tagged data used for encryption, key derivation, or file metadata.

Constants§

Traits§

Functions§

  • Given a “base” nonce and a counter, returns a Nonce suitable for encrypting/decrypting one block.

Type Aliases§