Module pgp::packet[][src]

Expand description

Packet module

Handles everything in relationship to packets.

Key generation is handled seperately as well as signing and verifying with external hashing applied.

use pgp::crypto::{self, sym::SymmetricKeyAlgorithm, hash::HashAlgorithm, public_key::PublicKeyAlgorithm};
use pgp::types::{self, PublicKeyTrait, SecretKeyTrait, CompressionAlgorithm};
use smallvec::*;
use pgp::types::KeyTrait;
use pgp::packet::{SignatureConfigBuilder, Signature};

let signing_key = signed_secret_key;
let verification_key = public_key;


let passwd_fn = || String::new();

let now = chrono::Utc::now();

let mut sig_cfg_bldr = SignatureConfigBuilder::default();
let sig_cfg = sig_cfg_bldr
     .version(packet::SignatureVersion::V4)
     .typ(packet::SignatureType::Binary)
     .pub_alg(PublicKeyAlgorithm::RSA)
     .hash_alg(HashAlgorithm::SHA2_256)
     .issuer(Some(signing_key.key_id()))
     .created(Some(now))
     .unhashed_subpackets(vec![]) // must be initialized
     .hashed_subpackets(vec![
          packet::Subpacket::SignatureCreationTime(now),
          packet::Subpacket::Issuer(signing_key.key_id()),
     ]) // must be initialized
     .build()
     .unwrap();

let signature_packet = sig_cfg
     .sign(&signing_key, passwd_fn, DATA)
     .expect("Should sign");

let mut signature_bytes = Vec::with_capacity(1024);
    let mut buff = std::io::Cursor::new(&mut signature_bytes);
    packet::write_packet(&mut buff, &signature_packet).expect("Write must succeed");

signature_packet
     .verify(&verification_key, DATA)
     .expect("Failed to validate signature");

Modules

Structs

Literal Data Packet https://tools.ietf.org/html/rfc4880.html#section-5.9

Marker Packet https://tools.ietf.org/html/rfc4880.html#section-5.8

Modification Detection Code Packet https://tools.ietf.org/html/rfc4880.html#section-5.14

One-Pass Signature Packet https://tools.ietf.org/html/rfc4880.html#section-5.4

Public Key Encrypted Session Key Packet https://tools.ietf.org/html/rfc4880.html#section-5.1

Signature Packet https://tools.ietf.org/html/rfc4880.html#section-5.2

Builder for SignatureConfig.

Symmetrically Encrypted Data Packet https://tools.ietf.org/html/rfc4880.html#section-5.7

Symmetrically Encrypted Integrity Protected Data Packet https://tools.ietf.org/html/rfc4880.html#section-5.12

Symmetric-Key Encrypted Session Key Packet https://tools.ietf.org/html/rfc4880.html#section-5.3

Trust Packet https://tools.ietf.org/html/rfc4880.html#section-5.10 Trust packets SHOULD NOT be emitted to output streams that are transferred to other users, and they SHOULD be ignored on any input other than local keyring files.

User ID Packet https://tools.ietf.org/html/rfc4880.html#section-5.11

Enums

Codes for revocation reasons

Available signature subpacket types

User Attribute Packet https://tools.ietf.org/html/rfc4880.html#section-5.12

Traits

Functions