Struct gpgme::context::Context[][src]

#[must_use]
pub struct Context(_);

A context for cryptographic operations

Methods

impl Context
[src]

Uses the specified provider to handle passphrase requests for the duration of the closure.

Examples

use std::io::prelude::*;

use gpgme::{Context, PassphraseRequest, Protocol};

let mut ctx = Context::from_protocol(Protocol::OpenPgp).unwrap();
ctx.with_passphrase_provider(|_: PassphraseRequest, out: &mut Write| {
    try!(out.write_all(b"some passphrase"));
    Ok(())
}, |mut ctx| {
    // Do something with ctx requiring a passphrase, for example decryption
});

Returns the public key with the specified fingerprint, if such a key can be found. Otherwise, an error is returned.

Returns the secret key with the specified fingerprint, if such a key can be found. Otherwise, an error is returned.

Deprecated since 0.8.0

: use get_key instead

Deprecated since 0.8.0

: use get_secret_key instead

Returns an iterator for a list of all public keys matching one or more of the specified patterns.

Returns an iterator for a list of all secret keys matching one or more of the specified patterns.

Returns an iterator over the keys encoded in the specified source.

Examples

use gpgme::{Context, Data, Protocol};

let mut ctx = Context::from_protocol(Protocol::OpenPgp).unwrap();
let mut keyring = Data::load("somefile").unwrap();
for key in ctx.read_keys(&mut keyring).unwrap() {
    println!("{:?}", key);
}

Creates a new OpenPGP key.

Examples

use gpgme::{Context, Data, Protocol};

let mut ctx = Context::from_protocol(Protocol::OpenPgp).unwrap();
let result = ctx.create_key("Example User <example@example.com>", "default", None).unwrap();
println!("Key Fingerprint: {}", result.fingerprint().unwrap());

Signs the given key with the default signing key, or the keys specified via add_signer.

Important traits for Signers<'ctx>

Important traits for SignatureNotations<'a>

Encrypts a message for the specified recipients.

Examples

use gpgme::{Context, Data, Protocol};

let mut ctx = Context::from_protocol(Protocol::OpenPgp).unwrap();
let key = ctx.find_key("[some key fingerprint]").unwrap();
let (plaintext, mut ciphertext) = ("Hello, World!", Vec::new());
ctx.encrypt(Some(&key), plaintext, &mut ciphertext).unwrap();

Encrypts and signs a message for the specified recipients.

Examples

use gpgme::{Context, Protocol};

let mut ctx = Context::from_protocol(Protocol::OpenPgp).unwrap();
let key = ctx.find_key("[some key fingerprint]").unwrap();
let (plaintext, mut ciphertext) = ("Hello, World!", Vec::new());
ctx.sign_and_encrypt(Some(&key), plaintext, &mut ciphertext).unwrap();

Decrypts a message.

Examples

use gpgme::{Context, Data, Protocol};

let mut ctx = Context::from_protocol(Protocol::OpenPgp).unwrap();
let mut cipher = Data::load("some file").unwrap();
let mut plain = Vec::new();
ctx.decrypt(&mut cipher, &mut plain).unwrap();

Decrypts and verifies a message.

Examples

use gpgme::{Context, Data, Protocol};

let mut ctx = Context::from_protocol(Protocol::OpenPgp).unwrap();
let mut cipher = Data::load("some file").unwrap();
let mut plain = Vec::new();
ctx.decrypt_and_verify(&mut cipher, &mut plain).unwrap();

Trait Implementations

impl Drop for Context
[src]

Executes the destructor for this type. Read more

impl Debug for Context
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl !Send for Context

impl !Sync for Context