[][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.

Methods

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

pub fn new<S>(inner: Stack<'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()
        {
            if let VerificationResult::GoodChecksum { .. } =
                results.get(0).unwrap()
            { Ok(()) /* good */ } else { panic!() }
        } 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()
        {
            if let VerificationResult::GoodChecksum { .. } =
                results.get(0).unwrap()
            { Ok(()) /* good */ } else { panic!() }
        } else { panic!() }
    }
}

let mut verifier =
    DetachedVerifier::from_bytes(p, &o, b"Make it so, number one!",
                                 Helper(&cert), None)?;

let mut message = String::new();
verifier.read_to_string(&mut message)?;
assert_eq!(&message, "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<Stack<'a, Cookie>>[src]

Finalizes the signer, returning the writer stack.

Trait Implementations

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

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

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

fn write_vectored(&mut self, bufs: &[IoVec]) -> Result<usize, Error>[src]

🔬 This is a nightly-only experimental API. (iovec)

Like write, except that it writes from a slice of buffers. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0
[src]

Attempts to write an entire buffer into this writer. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0
[src]

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Write. Read more

Auto Trait Implementations

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

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

Blanket Implementations

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

impl<T, U> TryInto 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 for T where
    V: MultiLane<T>,