pub struct Key {
pub fingerprint: String,
pub name: String,
pub mail: String,
pub password: Option<String>,
}
Expand description
A struct representing a public key.
Fields§
§fingerprint: String
The fingerprint of the key.
name: String
The name associated with the key.
mail: String
The email address associated with the key.
password: Option<String>
The password the key is protected with
Implementations§
Source§impl Key
impl Key
Sourcepub fn new(
name: &str,
mail: &str,
password: Option<&str>,
gpg: &GnuPG,
) -> Result<Self, GPGError>
pub fn new( name: &str, mail: &str, password: Option<&str>, gpg: &GnuPG, ) -> Result<Self, GPGError>
Creates a new GPG key with the given name and email address.
§Parameters
name
: the name of the keymail
: the email address associated with the keypassword
: an optional password to use for the keygpg
: a reference toGnuPG
struct
§Returns
If the key is successfully created, returns an instance of Key
wrapped in an Ok
variant.
If the key creation fails, returns an instance of GPGError
wrapped in an Err
variant.
Sourcepub fn get_by_name(name: &str, gpg: &GnuPG) -> Option<Self>
pub fn get_by_name(name: &str, gpg: &GnuPG) -> Option<Self>
Sourcepub fn get_by_mail(mail: &str, gpg: &GnuPG) -> Option<Self>
pub fn get_by_mail(mail: &str, gpg: &GnuPG) -> Option<Self>
Sourcepub fn get_by_fingerprint(fingerprint: &str, gpg: &GnuPG) -> Option<Self>
pub fn get_by_fingerprint(fingerprint: &str, gpg: &GnuPG) -> Option<Self>
Sourcepub fn unlock(&self, pw: &str) -> Self
pub fn unlock(&self, pw: &str) -> Self
Adds information to unlock a GPG key with the given password.
§Parameters
pw
: the password to use to unlock the key
§Returns
Returns a new Key
object, with the password set to the given value.
§Example
use gnupg::*;
let gnupg = GnuPG::new().unwrap();
let encrypted = "-----BEGIN PGP MESSAGE-----
...
-----END PGP MESSAGE-----";
let key = Key::get_by_name("Arisu", &gnupg).unwrap();
let plain = gnupg.decrypt(&key.unlock("pass"), encrypted);
println!("Plain Text: {:?}", plain);
Trait Implementations§
impl Eq for Key
impl StructuralPartialEq for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more