[][src]Crate pzip

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

Key

A key of any length (longer is better) that will be derived with HKDF-SHA256.

PZip

Structure for holding information about a PZip archive, and a namespace for common operations.

PZipReader

Reader for PZip files.

PZipWriter

Writer for PZip files.

Password

A password that will be encoded as UTF-8 and derived with PBKDF2-SHA256.

RawKey

A raw key (no derivation) for encryption and decryption. Must match the expected key size of the Algorithm being used.

Enums

Algorithm

The encryption algorithms known by PZip.

Compression

The compression methods known by PZip.

Error

The multitude of ways this crate can fail.

KeyDerivation

The key derivation functions (KDFs) known by PZip.

Tag

Tagged data used for encryption, key derivation, or file metadata.

Constants

DEFAULT_BLOCK_SIZE

The default block size to use when writing PZip blocks.

DEFAULT_PBKDF2_ITERATIONS

The default number of iterations to use in PBKDF2 derivations.

Traits

PZipKey

Wraps a KeyDerivation and input key material.

Functions

derive_nonce

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

Type Definitions

PZipTags