[][src]Struct sequoia_openpgp::serialize::stream::Signer

pub struct Signer<'a> { /* fields omitted */ }

Signs a packet stream.

For every signing key, a signer writes a one-pass-signature packet, then hashes and emits the data stream, then for every key writes a signature packet.

Implementations

impl<'a> Signer<'a>[src]

pub fn new<S>(inner: Message<'a, Cookie>, signer: S) -> Self where
    S: Signer + 'a, 
[src]

Creates a signer.

Example

extern crate sequoia_openpgp as openpgp;
use std::io::{Read, Write};
use openpgp::serialize::stream::{Message, Signer, LiteralWriter};
use openpgp::policy::StandardPolicy;

let p = &StandardPolicy::new();

let p = &StandardPolicy::new();

let mut o = vec![];
{
    let message = Message::new(&mut o);
    let signer = Signer::new(message, signing_keypair).build()?;
    let mut ls = LiteralWriter::new(signer).build()?;
    ls.write_all(b"Make it so, number one!")?;
    ls.finalize()?;
}

// Now check the signature.
struct Helper<'a>(&'a openpgp::Cert);
impl<'a> VerificationHelper for Helper<'a> {
    fn get_public_keys(&mut self, _: &[openpgp::KeyHandle])
                       -> openpgp::Result<Vec<openpgp::Cert>> {
        Ok(vec![self.0.clone()])
    }

    fn check(&mut self, structure: MessageStructure)
             -> openpgp::Result<()> {
        if let MessageLayer::SignatureGroup { ref results } =
            structure.iter().nth(0).unwrap()
        {
            results.get(0).unwrap().as_ref().unwrap();
            Ok(())
        } else { panic!() }
    }
}

let mut verifier = Verifier::from_bytes(p, &o, Helper(&cert), None)?;

let mut message = String::new();
verifier.read_to_string(&mut message)?;
assert_eq!(&message, "Make it so, number one!");

pub fn hash_algo(self, algo: HashAlgorithm) -> Result<Self>[src]

Sets the hash algorithm to use for the signatures.

pub fn add_signer<S>(self, signer: S) -> Self where
    S: Signer + 'a, 
[src]

Adds an additional signer.

pub fn add_intended_recipient(self, recipient: &Cert) -> Self[src]

Adds an intended recipient.

This signer emits signatures indicating the intended recipients of the encryption container containing the signature. This prevents forwarding a signed message using a different encryption context.

pub fn detached(self) -> Self[src]

Creates a signer for a detached signature.

Example

extern crate sequoia_openpgp as openpgp;
use std::io::{Read, Write};
use openpgp::serialize::stream::{Message, Signer, LiteralWriter};
use sequoia_openpgp::policy::StandardPolicy;

let p = &StandardPolicy::new();

let mut o = vec![];
{
    let message = Message::new(&mut o);
    let mut signer =
        Signer::new(message, signing_keypair).detached().build()?;
    signer.write_all(b"Make it so, number one!")?;
    // In reality, just io::copy() the file to be signed.
    signer.finalize()?;
}

// Now check the signature.
struct Helper<'a>(&'a openpgp::Cert);
impl<'a> VerificationHelper for Helper<'a> {
    fn get_public_keys(&mut self, _: &[openpgp::KeyHandle])
                       -> openpgp::Result<Vec<openpgp::Cert>> {
        Ok(vec![self.0.clone()])
    }

    fn check(&mut self, structure: MessageStructure)
             -> openpgp::Result<()> {
        if let MessageLayer::SignatureGroup { ref results } =
            structure.iter().nth(0).unwrap()
        {
            results.get(0).unwrap().as_ref().unwrap();
            Ok(())
        } else { panic!() }
    }
}

let mut verifier =
    DetachedVerifier::from_bytes(p, &o, Helper(&cert), None)?;

verifier.verify_bytes(b"Make it so, number one!")?;

pub fn creation_time(self, creation_time: SystemTime) -> Self[src]

Sets the signature's creation time to time.

Note: it is up to the caller to make sure the signing keys are actually valid as of time.

pub fn build(self) -> Result<Message<'a, Cookie>>[src]

Finalizes the signer, returning the writer stack.

Trait Implementations

impl<'a> Debug for Signer<'a>[src]

impl<'a> Drop for Signer<'a>[src]

impl<'a> Write for Signer<'a>[src]

Auto Trait Implementations

impl<'a> !RefUnwindSafe for Signer<'a>

impl<'a> !Send for Signer<'a>

impl<'a> !Sync for Signer<'a>

impl<'a> Unpin for Signer<'a>

impl<'a> !UnwindSafe for Signer<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,