pub trait SOP<'s>: Sized {
type Keys: Load<'s, Self> + Save + SopRef<'s, Self>;
type Certs: Load<'s, Self> + Save + SopRef<'s, Self>;
type Sigs: Load<'s, Self> + Save + SopRef<'s, Self>;
Show 15 methods
// Required methods
fn version(&'s self) -> Result<Box<dyn Version<'_> + 's>>;
fn generate_key(
&'s self
) -> Result<Box<dyn GenerateKey<'_, Self, Self::Keys> + 's>>;
fn change_key_password(
&'s self
) -> Result<Box<dyn ChangeKeyPassword<'_, Self, Self::Keys> + 's>>;
fn revoke_key(
&'s self
) -> Result<Box<dyn RevokeKey<'_, Self, Self::Certs, Self::Keys> + 's>>;
fn extract_cert(
&'s self
) -> Result<Box<dyn ExtractCert<'_, Self, Self::Certs, Self::Keys> + 's>>;
fn sign(
&'s self
) -> Result<Box<dyn Sign<'_, Self, Self::Keys, Self::Sigs> + 's>>;
fn verify(
&'s self
) -> Result<Box<dyn Verify<'_, Self, Self::Certs, Self::Sigs> + 's>>;
fn encrypt(
&'s self
) -> Result<Box<dyn Encrypt<'_, Self, Self::Certs, Self::Keys> + 's>>;
fn decrypt(
&'s self
) -> Result<Box<dyn Decrypt<'_, Self, Self::Certs, Self::Keys> + 's>>;
fn armor(&'s self) -> Result<Box<dyn Armor<'_> + 's>>;
fn dearmor(&'s self) -> Result<Box<dyn Dearmor<'_> + 's>>;
fn inline_detach(
&'s self
) -> Result<Box<dyn InlineDetach<'_, Self::Sigs> + 's>>;
fn inline_verify(
&'s self
) -> Result<Box<dyn InlineVerify<'_, Self, Self::Certs> + 's>>;
fn inline_sign(
&'s self
) -> Result<Box<dyn InlineSign<'_, Self, Self::Keys> + 's>>;
// Provided method
fn spec_version(&'s self) -> &'static str { ... }
}
Expand description
Main entry point to the Stateless OpenPGP Interface.
Required Associated Types§
Required Methods§
sourcefn version(&'s self) -> Result<Box<dyn Version<'_> + 's>>
fn version(&'s self) -> Result<Box<dyn Version<'_> + 's>>
Gets version information.
Examples
// Prints the name of the SOP implementation.
println!("{}", sop.version()?.frontend()?);
// Prints the name of the underlying OpenPGP implementation.
println!("{}", sop.version()?.backend()?);
// Prints extended version information.
println!("{}", sop.version()?.extended()?);
sourcefn generate_key(
&'s self
) -> Result<Box<dyn GenerateKey<'_, Self, Self::Keys> + 's>>
fn generate_key( &'s self ) -> Result<Box<dyn GenerateKey<'_, Self, Self::Keys> + 's>>
Generates a Secret Key.
Customize the operation using the builder GenerateKey
.
Examples
let alice_sec = sop.generate_key()?
.userid("Alice Lovelace <alice@openpgp.example>")
.generate()?;
sourcefn change_key_password(
&'s self
) -> Result<Box<dyn ChangeKeyPassword<'_, Self, Self::Keys> + 's>>
fn change_key_password( &'s self ) -> Result<Box<dyn ChangeKeyPassword<'_, Self, Self::Keys> + 's>>
Updates a key’s password.
Customize the operation using the builder ChangeKeyPassword
.
Examples
let alice_secret =
Keys::from_reader(sop, &mut File::open("alice.secret")?)?;
let alice_updated_secret = sop.change_key_password()?
.old_key_password(Password::new_unchecked(b"hunter2".to_vec()))?
.new_key_password(Password::new(b"jaeger2".to_vec())?)?
.keys(&alice_secret)?;
sourcefn revoke_key(
&'s self
) -> Result<Box<dyn RevokeKey<'_, Self, Self::Certs, Self::Keys> + 's>>
fn revoke_key( &'s self ) -> Result<Box<dyn RevokeKey<'_, Self, Self::Certs, Self::Keys> + 's>>
Creates a Revocation Certificate.
Customize the operation using the builder RevokeKey
.
Examples
let alice_secret =
Keys::from_reader(sop, &mut File::open("alice.secret")?)?;
let alice_revoked = sop.revoke_key()?
.with_key_password(Password::new_unchecked(b"hunter2".to_vec()))?
.keys(&alice_secret)?;
sourcefn extract_cert(
&'s self
) -> Result<Box<dyn ExtractCert<'_, Self, Self::Certs, Self::Keys> + 's>>
fn extract_cert( &'s self ) -> Result<Box<dyn ExtractCert<'_, Self, Self::Certs, Self::Keys> + 's>>
Extracts a Certificate from a Secret Key.
Customize the operation using the builder ExtractCert
.
Examples
let alice_secret =
Keys::from_reader(sop, &mut File::open("alice.secret")?)?;
let alice_public = sop.extract_cert()?
.keys(&alice_secret)?;
sourcefn verify(
&'s self
) -> Result<Box<dyn Verify<'_, Self, Self::Certs, Self::Sigs> + 's>>
fn verify( &'s self ) -> Result<Box<dyn Verify<'_, Self, Self::Certs, Self::Sigs> + 's>>
Verifies Detached Signatures.
Customize the operation using the builder Verify
.
Examples
let alice_public =
Certs::from_reader(sop, &mut File::open("alice.public")?)?;
let sig =
Sigs::from_reader(sop, &mut File::open("data.asc")?)?;
let verifications = sop.verify()?
.certs(&alice_public)?
.signatures(&sig)?
.data(&mut Cursor::new(&b"Hello World :)"))?;
let valid_signatures = ! verifications.is_empty();
sourcefn encrypt(
&'s self
) -> Result<Box<dyn Encrypt<'_, Self, Self::Certs, Self::Keys> + 's>>
fn encrypt( &'s self ) -> Result<Box<dyn Encrypt<'_, Self, Self::Certs, Self::Keys> + 's>>
Encrypts a Message.
Customize the operation using the builder Encrypt
.
Examples
Encrypts a message for Bob, and signs it using Alice’s key.
let alice_secret =
Keys::from_reader(sop, &mut File::open("alice.secret")?)?;
let bob_public =
Certs::from_reader(sop, &mut File::open("bob.public")?)?;
let (_session_key, ciphertext) = sop.encrypt()?
.sign_with_keys(&alice_secret)?
.with_certs(&bob_public)?
.plaintext(&mut Cursor::new(&b"Hello World :)"))?
.to_vec()?;
sourcefn decrypt(
&'s self
) -> Result<Box<dyn Decrypt<'_, Self, Self::Certs, Self::Keys> + 's>>
fn decrypt( &'s self ) -> Result<Box<dyn Decrypt<'_, Self, Self::Certs, Self::Keys> + 's>>
Decrypts a Message.
Customize the operation using the builder Decrypt
.
Examples
Decrypts a message encrypted for Bob, and verifies Alice’s signature on it.
let alice_public =
Certs::from_reader(sop, &mut File::open("alice.public")?)?;
let bob_secret =
Keys::from_reader(sop, &mut File::open("bob.secret")?)?;
let ((_session_key, verifications), plaintext) = sop.decrypt()?
.verify_with_certs(&alice_public)?
.with_keys(&bob_secret)?
.ciphertext(&mut File::open("ciphertext.pgp")?)?
.to_vec()?;
let valid_signatures = ! verifications.is_empty();
sourcefn armor(&'s self) -> Result<Box<dyn Armor<'_> + 's>>
fn armor(&'s self) -> Result<Box<dyn Armor<'_> + 's>>
Converts binary OpenPGP data to ASCII.
By default, SOP operations emit ASCII-Armored data. But, occasionally it can be useful to explicitly armor data.
Customize the operation using the builder Armor
.
Examples
let (_, alice_secret_asc) = sop.armor()?
.data(&mut File::open("alice.secret.bin")?)?
.to_vec()?;
assert!(alice_secret_asc.starts_with(b"-----BEGIN PGP PRIVATE KEY BLOCK-----"));
sourcefn dearmor(&'s self) -> Result<Box<dyn Dearmor<'_> + 's>>
fn dearmor(&'s self) -> Result<Box<dyn Dearmor<'_> + 's>>
Converts ASCII OpenPGP data to binary.
By default, SOP operations emit ASCII-Armored data, but this behavior can be changed at export time. Nevertheless, occasionally it can be useful to explicitly dearmor data.
Customize the operation using the builder Dearmor
.
Examples
let (_, alice_secret_bin) = sop.dearmor()?
.data(&mut File::open("alice.secret.asc")?)?
.to_vec()?;
assert!(! alice_secret_bin.starts_with(b"-----BEGIN PGP PRIVATE KEY BLOCK-----"));
sourcefn inline_detach(&'s self) -> Result<Box<dyn InlineDetach<'_, Self::Sigs> + 's>>
fn inline_detach(&'s self) -> Result<Box<dyn InlineDetach<'_, Self::Sigs> + 's>>
Splits Signatures from an Inline-Signed Message.
Note: The signatures are not verified, this merely transforms
an inline-signed message into a detached signature, which in
turn can be verified using SOP::verify
.
Customize the operation using the builder InlineDetach
.
Examples
let (signatures, data) = sop.inline_detach()?
.message(&mut File::open("inline-signed.pgp")?)?
.to_vec()?;
sourcefn inline_verify(
&'s self
) -> Result<Box<dyn InlineVerify<'_, Self, Self::Certs> + 's>>
fn inline_verify( &'s self ) -> Result<Box<dyn InlineVerify<'_, Self, Self::Certs> + 's>>
Verifies an Inline-Signed Message.
Customize the operation using the builder InlineVerify
.
Examples
let alice_public =
Certs::from_reader(sop, &mut File::open("alice.public")?)?;
let (verifications, data) = sop.inline_verify()?
.certs(&alice_public)?
.message(&mut File::open("inline-signed.pgp")?)?
.to_vec()?;
let valid_signatures = ! verifications.is_empty();
sourcefn inline_sign(
&'s self
) -> Result<Box<dyn InlineSign<'_, Self, Self::Keys> + 's>>
fn inline_sign( &'s self ) -> Result<Box<dyn InlineSign<'_, Self, Self::Keys> + 's>>
Creates an Inline-Signed Message.
Customize the operation using the builder InlineSign
.
Examples
let alice_secret =
Keys::from_reader(sop, &mut File::open("alice.secret")?)?;
let (inline_signed_asc) = sop.inline_sign()?
.keys(&alice_secret)?
.data(&mut Cursor::new(&b"Hello World :)"))?
.to_vec()?;
Provided Methods§
sourcefn spec_version(&'s self) -> &'static str
fn spec_version(&'s self) -> &'static str
Gets SOP version information.
The default implementation returns the version of the spec that this framework supports. This should be fine for most implementations. However, implementations may chose to override this function to return a more nuanced response.