Skip to main content

SecretKeyFile

Struct SecretKeyFile 

Source
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

Source

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.

Source

pub fn open(file: impl AsRef<Path>) -> Result<SecretKeyFile, Error>

Parse a SecretKeyFile from file (in toml format).

Source

pub fn write(&self, w: impl Write) -> Result<(), Error>

Write self serialized as toml to w.

Source

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.

Source

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.

Source

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.

Source

pub fn is_encrypted(&self) -> bool

Status of the internal state.

Source

pub fn secret_key(&self) -> Option<SecretKey>

Returns None if the secret key is encrypted.

Source

pub fn public_key(&self) -> Option<PublicKey>

Returns None if the secret key is encrypted.

Source

pub fn public_key_file(&self) -> Option<PublicKeyFile>

Returns None if the secret key is encrypted.

Trait Implementations§

Source§

impl<'de> Deserialize<'de> for SecretKeyFile

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SecretKeyFile

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,