Struct gpgme::context::Context
[−]
[src]
#[must_use]pub struct Context(_);
A context for cryptographic operations
Methods
impl Context
[src]
unsafe fn from_raw(raw: gpgme_ctx_t) -> Self
fn as_raw(&self) -> gpgme_ctx_t
fn into_raw(self) -> gpgme_ctx_t
fn from_protocol(proto: Protocol) -> Result<Self>
fn protocol(&self) -> Protocol
fn armor(&self) -> bool
fn set_armor(&mut self, enabled: bool)
fn text_mode(&self) -> bool
fn set_text_mode(&mut self, enabled: bool)
fn offline(&self) -> bool
fn set_offline(&mut self, enabled: bool)
fn get_flag<S>(&self, name: S) -> Result<&str, Option<Utf8Error>> where S: IntoNativeString
fn get_flag_raw<S>(&self, name: S) -> Option<&CStr> where S: IntoNativeString
fn set_flag<S1, S2>(&mut self, name: S1, value: S2) -> Result<()> where S1: IntoNativeString, S2: IntoNativeString
fn engine_info(&self) -> EngineInfo
fn set_engine_path<S>(&mut self, path: S) -> Result<()> where S: IntoNativeString
fn set_engine_home_dir<S>(&mut self, home_dir: S) -> Result<()> where S: IntoNativeString
fn set_engine_info<S1, S2>(&mut self,
path: Option<S1>,
home_dir: Option<S2>)
-> Result<()> where S1: IntoNativeString, S2: IntoNativeString
path: Option<S1>,
home_dir: Option<S2>)
-> Result<()> where S1: IntoNativeString, S2: IntoNativeString
fn pinentry_mode(self) -> PinentryMode
fn set_pinentry_mode(&mut self, mode: PinentryMode) -> Result<()>
fn with_passphrase_provider<P, F, R>(&mut self, provider: P, f: F) -> R where P: PassphraseProvider, 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, 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 });
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 find_trust_items<S: IntoNativeString>(&mut self,
pattern: S,
max_level: i32)
-> Result<TrustItems>
pattern: S,
max_level: i32)
-> Result<TrustItems>
fn key_list_mode(&self) -> KeyListMode
fn add_key_list_mode(&mut self, mask: KeyListMode) -> Result<()>
fn set_key_list_mode(&mut self, mode: KeyListMode) -> Result<()>
fn keys(&mut self) -> Result<Keys>
fn secret_keys(&mut self) -> Result<Keys>
fn get_key(&mut self, key: &Key) -> Result<Key>
fn get_secret_key(&mut self, key: &Key) -> Result<Key>
fn find_key<S: IntoNativeString>(&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: IntoNativeString>(&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: IntoNativeString
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: IntoNativeString
Returns an iterator for a list of all secret keys matching one or more of the specified patterns.
fn generate_key<S>(&mut self,
params: S,
public: Option<&mut Data>,
secret: Option<&mut Data>)
-> Result<KeyGenerationResult> where S: IntoNativeString
params: S,
public: Option<&mut Data>,
secret: Option<&mut Data>)
-> Result<KeyGenerationResult> where S: IntoNativeString
fn create_key<S1, S2>(&mut self,
userid: S1,
algo: S2,
expires: Option<SystemTime>,
flags: CreateKeyFlags)
-> Result<KeyGenerationResult> where S1: IntoNativeString, S2: IntoNativeString
userid: S1,
algo: S2,
expires: Option<SystemTime>,
flags: CreateKeyFlags)
-> Result<KeyGenerationResult> where S1: IntoNativeString, S2: IntoNativeString
fn create_subkey<S>(&mut self,
key: &Key,
algo: S,
expires: Option<SystemTime>,
flags: CreateKeyFlags)
-> Result<KeyGenerationResult> where S: IntoNativeString
key: &Key,
algo: S,
expires: Option<SystemTime>,
flags: CreateKeyFlags)
-> Result<KeyGenerationResult> where S: IntoNativeString
fn add_uid<S>(&mut self, key: &Key, userid: S) -> Result<()> where S: IntoNativeString
fn revoke_uid<S>(&mut self, key: &Key, userid: S) -> Result<()> where S: IntoNativeString
fn sign_key<I>(&mut self,
key: &Key,
userids: I,
expires: Option<SystemTime>)
-> Result<()> where I: IntoIterator, I::Item: AsRef<[u8]>
key: &Key,
userids: I,
expires: Option<SystemTime>)
-> Result<()> where I: IntoIterator, I::Item: AsRef<[u8]>
fn sign_key_with_flags<I>(&mut self,
key: &Key,
userids: I,
expires: Option<SystemTime>,
flags: KeySigningFlags)
-> Result<()> where I: IntoIterator, I::Item: AsRef<[u8]>
key: &Key,
userids: I,
expires: Option<SystemTime>,
flags: KeySigningFlags)
-> Result<()> where I: IntoIterator, I::Item: AsRef<[u8]>
fn change_key_tofu_policy(&mut self,
key: &Key,
policy: TofuPolicy)
-> Result<()>
key: &Key,
policy: TofuPolicy)
-> Result<()>
fn change_key_passphrase(&mut self, key: &Key) -> Result<()>
fn edit_key<E: EditInteractor>(&mut self,
key: &Key,
interactor: E,
data: &mut Data)
-> Result<()>
key: &Key,
interactor: E,
data: &mut Data)
-> Result<()>
fn edit_card_key<E: EditInteractor>(&mut self,
key: &Key,
interactor: E,
data: &mut Data)
-> Result<()>
key: &Key,
interactor: E,
data: &mut Data)
-> Result<()>
fn edit_key_with<E: Editor>(&mut self,
key: &Key,
editor: E,
data: &mut Data)
-> Result<()>
key: &Key,
editor: E,
data: &mut Data)
-> Result<()>
fn edit_card_key_with<E: Editor>(&mut self,
key: &Key,
editor: E,
data: &mut Data)
-> Result<()>
key: &Key,
editor: E,
data: &mut Data)
-> Result<()>
fn interact<I: Interactor>(&mut self,
key: &Key,
interactor: I,
data: &mut Data)
-> Result<()>
key: &Key,
interactor: I,
data: &mut Data)
-> Result<()>
fn interact_with_card<I: Interactor>(&mut self,
key: &Key,
interactor: I,
data: &mut Data)
-> Result<()>
key: &Key,
interactor: I,
data: &mut Data)
-> Result<()>
fn delete_key(&mut self, key: &Key) -> Result<()>
fn delete_secret_key(&mut self, key: &Key) -> Result<()>
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<()>
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: IntoNativeString
patterns: I,
mode: ExportMode,
data: Option<&mut Data>)
-> Result<()> where I: IntoIterator, I::Item: IntoNativeString
fn export_keys<'k, I>(&mut self,
keys: I,
mode: ExportMode,
data: Option<&mut Data>)
-> Result<()> where I: IntoIterator<Item=&'k Key>
keys: I,
mode: ExportMode,
data: Option<&mut Data>)
-> Result<()> where I: IntoIterator<Item=&'k Key>
fn clear_sender(&mut self) -> Result<()>
fn set_sender<S: IntoNativeString>(&mut self, sender: S) -> Result<()>
fn sender(&self) -> Result<&str, Option<Utf8Error>>
fn sender_raw(&self) -> Option<&CStr>
fn clear_signers(&mut self)
fn add_signer(&mut self, key: &Key) -> Result<()>
fn signers(&self) -> Signers
fn clear_signature_notations(&mut self)
fn add_signature_notation<S1, S2>(&mut self,
name: S1,
value: S2,
flags: SignatureNotationFlags)
-> Result<()> where S1: IntoNativeString, S2: IntoNativeString
name: S1,
value: S2,
flags: SignatureNotationFlags)
-> Result<()> where S1: IntoNativeString, S2: IntoNativeString
fn add_signature_policy_url<S>(&mut self, url: S, critical: bool) -> Result<()> where S: IntoNativeString
fn signature_policy_url(&self) -> Result<&str, Option<Utf8Error>>
fn signature_policy_url_raw(&self) -> Option<&CStr>
fn signature_notations(&self) -> SignatureNotations
fn sign(&mut self,
mode: SignMode,
plain: &mut Data,
signature: &mut Data)
-> Result<SigningResult>
mode: SignMode,
plain: &mut Data,
signature: &mut Data)
-> Result<SigningResult>
fn sign_clear(&mut self,
plain: &mut Data,
signed: &mut Data)
-> Result<SigningResult>
plain: &mut Data,
signed: &mut Data)
-> Result<SigningResult>
fn sign_detached(&mut self,
plain: &mut Data,
signature: &mut Data)
-> Result<SigningResult>
plain: &mut Data,
signature: &mut Data)
-> Result<SigningResult>
fn sign_normal(&mut self,
plain: &mut Data,
signed: &mut Data)
-> Result<SigningResult>
plain: &mut Data,
signed: &mut Data)
-> Result<SigningResult>
fn verify(&mut self,
signature: &mut Data,
signed: Option<&mut Data>,
plain: Option<&mut Data>)
-> Result<VerificationResult>
signature: &mut Data,
signed: Option<&mut Data>,
plain: Option<&mut Data>)
-> Result<VerificationResult>
fn verify_detached(&mut self,
signature: &mut Data,
signed: &mut Data)
-> Result<VerificationResult>
signature: &mut Data,
signed: &mut Data)
-> Result<VerificationResult>
fn verify_opaque(&mut self,
signature: &mut Data,
plain: &mut Data)
-> Result<VerificationResult>
signature: &mut Data,
plain: &mut Data)
-> Result<VerificationResult>
fn encrypt<'k, I>(&mut self,
recp: I,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<EncryptionResult> where I: IntoIterator<Item=&'k Key>
recp: I,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<EncryptionResult> where I: IntoIterator<Item=&'k Key>
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 pattern").unwrap(); let (mut plaintext, mut ciphertext) = (Data::new().unwrap(), Data::new().unwrap()); ctx.encrypt(Some(&key), &mut plaintext, &mut ciphertext).unwrap();
fn encrypt_with_flags<'k, I>(&mut self,
recp: I,
flags: EncryptFlags,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<EncryptionResult> where I: IntoIterator<Item=&'k Key>
recp: I,
flags: EncryptFlags,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<EncryptionResult> where I: IntoIterator<Item=&'k Key>
fn encrypt_symmetric(&mut self,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<()>
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<()>
fn encrypt_symmetric_with_flags(&mut self,
flags: EncryptFlags,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<()>
flags: EncryptFlags,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<()>
fn sign_and_encrypt<'k, I>(&mut self,
recp: I,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<(EncryptionResult, SigningResult)> where I: IntoIterator<Item=&'k Key>
recp: I,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<(EncryptionResult, SigningResult)> where I: IntoIterator<Item=&'k Key>
Encrypts and signs 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 pattern").unwrap(); let (mut plaintext, mut ciphertext) = (Data::new().unwrap(), Data::new().unwrap()); ctx.sign_and_encrypt(Some(&key), &mut plaintext, &mut ciphertext).unwrap();
fn sign_and_encrypt_with_flags<'k, I>(&mut self,
recp: I,
flags: EncryptFlags,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<(EncryptionResult, SigningResult)> where I: IntoIterator<Item=&'k Key>
recp: I,
flags: EncryptFlags,
plaintext: &mut Data,
ciphertext: &mut Data)
-> Result<(EncryptionResult, SigningResult)> where I: IntoIterator<Item=&'k Key>
fn decrypt(&mut self,
ciphertext: &mut Data,
plaintext: &mut Data)
-> Result<DecryptionResult>
ciphertext: &mut Data,
plaintext: &mut Data)
-> Result<DecryptionResult>
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 = Data::new().unwrap(); ctx.decrypt(&mut cipher, &mut plain).unwrap();
fn decrypt_and_verify(&mut self,
ciphertext: &mut Data,
plaintext: &mut Data)
-> Result<(DecryptionResult, VerificationResult)>
ciphertext: &mut Data,
plaintext: &mut Data)
-> Result<(DecryptionResult, VerificationResult)>
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 = Data::new().unwrap(); ctx.decrypt_and_verify(&mut cipher, &mut plain).unwrap();