Struct gpgme::context::Context
[−]
[src]
pub struct Context { // some fields omitted }
A context for cryptographic operations
Methods
impl Context
fn new(_: Token) -> Result<Self>
fn has_armor(&self) -> bool
fn set_armor(&mut self, enabled: bool)
fn text_mode(&self) -> bool
fn set_text_mode(&mut self, enabled: bool)
fn protocol(&self) -> Protocol
fn set_protocol(&mut self, proto: Protocol) -> Result<()>
fn with_passphrase_handler<H, F, R>(&mut self, handler: H, f: F) -> R where H: PassphraseHandler, F: FnOnce(&mut Context) -> R
Uses the specified provider to handle passphrase requests for the duration of the closure.
Examples
use std::io::prelude::*; use gpgme::context::PassphraseRequest; let mut ctx = gpgme::create_context().unwrap(); ctx.with_passphrase_handler(|_: PassphraseRequest, out: &mut Write| { try!(out.write_all(b"some passphrase")); Ok(()) }, |mut ctx| { // Do something with ctx requiring a passphrase, for example decryption });
fn with_progress_handler<H, F, R>(&mut self, handler: H, f: F) -> R where H: ProgressHandler, F: FnOnce(&mut Context) -> R
fn with_status_handler<H, F, R>(&mut self, handler: H, f: F) -> R where H: StatusHandler, F: FnOnce(&mut Context) -> R
fn engine_info(&self) -> EngineInfoIter<Context>
fn get_engine_info(&self, proto: Protocol) -> Option<EngineInfo<Context>>
fn set_engine_filename<S>(&self, proto: Protocol, filename: S) -> Result<()> where S: Into<Vec<u8>>
fn set_engine_home_dir<S>(&self, proto: Protocol, home_dir: S) -> Result<()> where S: Into<Vec<u8>>
fn set_engine_info<S1, S2>(&mut self, proto: Protocol, filename: S1, home_dir: S2) -> Result<()> where S1: Into<Vec<u8>>, S2: Into<Vec<u8>>
fn find_trust_items<S: Into<Vec<u8>>>(&mut self, pattern: S, max_level: i32) -> Result<TrustItems>
fn offline(&self) -> bool
fn set_offline(&mut self, enabled: bool)
fn key_list_mode(&self) -> KeyListMode
fn set_key_list_mode(&mut self, mask: KeyListMode) -> Result<()>
fn keys(&mut self) -> Result<Keys>
fn secret_keys(&mut self) -> Result<Keys>
fn find_key<S: Into<Vec<u8>>>(&self, fingerprint: S) -> Result<Key>
Returns the public key with the specified fingerprint, if such a key can be found. Otherwise, an error is returned.
fn find_secret_key<S: Into<Vec<u8>>>(&self, fingerprint: S) -> Result<Key>
Returns the secret key with the specified fingerprint, if such a key can be found. Otherwise, an error is returned.
fn find_keys<I>(&mut self, patterns: I) -> Result<Keys> where I: IntoIterator, I::Item: Into<Vec<u8>>
Returns an iterator for a list of all public keys matching one or more of the specified patterns.
fn find_secret_keys<I>(&mut self, patterns: I) -> Result<Keys> where I: IntoIterator, I::Item: Into<Vec<u8>>
Returns an iterator for a list of all secret keys matching one or more of the specified patterns.
fn generate_key<S: Into<String>>(&mut self, params: S, public: Option<&mut Data>, secret: Option<&mut Data>) -> Result<KeyGenerateResult>
fn import(&mut self, key_data: &mut Data) -> Result<ImportResult>
fn import_keys<'k, I>(&mut self, keys: I) -> Result<ImportResult> where I: IntoIterator<Item=&'k Key>
fn export_all(&mut self, mode: ExportMode, data: Option<&mut Data>) -> Result<()>
fn export<I>(&mut self, patterns: I, mode: ExportMode, data: Option<&mut Data>) -> Result<()> where I: IntoIterator, I::Item: Into<Vec<u8>>
fn export_keys<'k, I>(&mut self, keys: I, mode: ExportMode, data: Option<&mut Data>) -> Result<()> where I: IntoIterator<Item=&'k Key>
fn change_key_passphrase(&mut self, key: &Key) -> Result<()>
fn edit_key<E: EditHandler>(&mut self, key: &Key, handler: E, data: &mut Data) -> Result<()>
fn edit_key_with<E: Editor>(&mut self, key: &Key, editor: E, data: &mut Data) -> Result<()>
fn delete_key(&mut self, key: &Key) -> Result<()>
fn delete_secret_key(&mut self, key: &Key) -> Result<()>
fn clear_signers(&mut self)
fn add_signer(&mut self, key: &Key) -> Result<()>
fn signers_count(&self) -> u32
fn signers(&self) -> SignersIter
fn clear_notations(&mut self)
fn add_notation<S1, S2>(&mut self, name: S1, value: S2, flags: Flags) -> Result<()> where S1: Into<String>, S2: Into<String>
fn add_policy_url<S: Into<String>>(&mut self, url: S, critical: bool) -> Result<()>
fn notations(&self) -> SignatureNotationIter<Context>
fn sign(&mut self, mode: SignMode, plain: &mut Data, signature: &mut Data) -> Result<SignResult>
fn sign_clear(&mut self, plain: &mut Data, signed: &mut Data) -> Result<SignResult>
fn sign_detached(&mut self, plain: &mut Data, signature: &mut Data) -> Result<SignResult>
fn sign_normal(&mut self, plain: &mut Data, signed: &mut Data) -> Result<SignResult>
fn verify(&mut self, signature: &mut Data, signed: Option<&mut Data>, plain: Option<&mut Data>) -> Result<VerifyResult>
fn verify_detached(&mut self, signature: &mut Data, signed: &mut Data) -> Result<VerifyResult>
fn verify_opaque(&mut self, signature: &mut Data, plain: &mut Data) -> Result<VerifyResult>
fn encrypt<'k, I>(&mut self, recp: I, flags: EncryptFlags, plain: &mut Data, cipher: &mut Data) -> Result<EncryptResult> where I: IntoIterator<Item=&'k Key>
Encrypts a message for the specified recipients.
Examples
use gpgme::{self, Data, ops}; let mut ctx = gpgme::create_context().unwrap(); let key = ctx.find_key("some pattern").unwrap(); let (mut plain, mut cipher) = (Data::new().unwrap(), Data::new().unwrap()); ctx.encrypt(Some(&key), ops::EncryptFlags::empty(), &mut plain, &mut cipher).unwrap();
fn encrypt_symmetric(&mut self, flags: EncryptFlags, plain: &mut Data, cipher: &mut Data) -> Result<()>
fn encrypt_and_sign<'k, I>(&mut self, recp: I, flags: EncryptFlags, plain: &mut Data, cipher: &mut Data) -> Result<(EncryptResult, SignResult)> where I: IntoIterator<Item=&'k Key>
Encrypts and signs a message for the specified recipients.
Examples
use gpgme::{self, Data, ops}; let mut ctx = gpgme::create_context().unwrap(); let key = ctx.find_key("some pattern").unwrap(); let (mut plain, mut cipher) = (Data::new().unwrap(), Data::new().unwrap()); ctx.encrypt_and_sign(Some(&key), ops::EncryptFlags::empty(), &mut plain, &mut cipher).unwrap();
fn decrypt(&mut self, cipher: &mut Data, plain: &mut Data) -> Result<DecryptResult>
Decrypts a message.
Examples
use std::fs::File; use gpgme::{self, Data, ops}; let mut ctx = gpgme::create_context().unwrap(); let mut cipher = Data::load("some file").unwrap(); let mut plain = Data::new().unwrap(); ctx.decrypt(&mut cipher, &mut plain).unwrap();
fn decrypt_and_verify(&mut self, cipher: &mut Data, plain: &mut Data) -> Result<(DecryptResult, VerifyResult)>
Decrypts and verifies a message.
Examples
use std::fs::File; use gpgme::{self, Data, ops}; let mut ctx = gpgme::create_context().unwrap(); let mut cipher = Data::load("some file").unwrap(); let mut plain = Data::new().unwrap(); ctx.decrypt_and_verify(&mut cipher, &mut plain).unwrap();