pub struct SecretKeyFile { /* private fields */ }Expand description
Standard pkgar private key format definition. Use serde.
Internally, this struct stores the encrypted state of the private key as an enum.
Manipulate the state using the encrypt(), decrypt() and is_encrypted().
Implementations§
Source§impl SecretKeyFile
impl SecretKeyFile
Sourcepub fn new() -> (PublicKeyFile, SecretKeyFile)
pub fn new() -> (PublicKeyFile, SecretKeyFile)
Generate a keypair with all the nessesary info to save both keys. You
must call save() on each object to persist them to disk.
Sourcepub fn open(file: impl AsRef<Path>) -> Result<SecretKeyFile, Error>
pub fn open(file: impl AsRef<Path>) -> Result<SecretKeyFile, Error>
Parse a SecretKeyFile from file (in toml format).
Sourcepub fn save(&self, file: impl AsRef<Path>) -> Result<(), Error>
pub fn save(&self, file: impl AsRef<Path>) -> Result<(), Error>
Shortcut to write the secret key to file.
Make sure to call encrypt() in order to encrypt
the private key, otherwise it will be stored as plain text.
Sourcepub fn encrypt(&mut self, passwd: Passwd) -> Result<(), Error>
pub fn encrypt(&mut self, passwd: Passwd) -> Result<(), Error>
Ensure that the internal state of this struct is encrypted. Note that if passwd is empty, this function is a no-op.
Sourcepub fn decrypt(&mut self, passwd: Passwd) -> Result<(), Error>
pub fn decrypt(&mut self, passwd: Passwd) -> Result<(), Error>
Ensure that the internal state of this struct is decrypted. If the internal state is already decrypted, this function is a no-op.
Sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
Status of the internal state.
Sourcepub fn secret_key(&self) -> Option<SecretKey>
pub fn secret_key(&self) -> Option<SecretKey>
Returns None if the secret key is encrypted.
Sourcepub fn public_key(&self) -> Option<PublicKey>
pub fn public_key(&self) -> Option<PublicKey>
Returns None if the secret key is encrypted.
Sourcepub fn public_key_file(&self) -> Option<PublicKeyFile>
pub fn public_key_file(&self) -> Option<PublicKeyFile>
Returns None if the secret key is encrypted.