Struct IdentityKey

Source
pub struct IdentityKey { /* private fields */ }
Expand description

Identity Key that allows signing hashes as a given Identity.

This acts as a wrapper for a specific cryptographic private key, and it is only be used for a specific corresponding signature algorithm. The underlying private key may be located in a hardware module or some other private keystore; in this case, it may be impossible to export the key.

§Example


// Make a new temporary key
let key = IdentityKey::new();

// Sign some data with it
let hash = Hash::new(b"I am data, about to be signed");
let signature = key.sign(&hash);

Implementations§

Source§

impl IdentityKey

Source

pub fn from_interface(interface: Arc<dyn SignInterface>) -> IdentityKey

Create a new IdentityKey, given a wrapped object that can implement a SignInterface.

Source

pub fn new() -> IdentityKey

Generate a temporary IdentityKey that exists in program memory.

Source

pub fn with_rng<R>(csprng: &mut R) -> IdentityKey
where R: CryptoRng + RngCore,

Generate a temporary IdentityKey that exists in program memory, using the provided cryptographic RNG.

Source

pub fn with_rng_and_version<R>( csprng: &mut R, version: u8, ) -> Result<IdentityKey, CryptoError>
where R: CryptoRng + RngCore,

Generate a temporary IdentityKey that exists in program memory. Uses the specified version instead of the default, and fails if the version is unsupported.

Source

pub fn version(&self) -> u8

Get the signature algorithm version used by this key.

Source

pub fn id(&self) -> &Identity

Get the associated Identity for this key.

Source

pub fn sign(&self, hash: &Hash) -> Signature

Sign a hash. Signing should be fast and always succeed.

Source

pub fn max_signature_size(&self) -> usize

The maximum expected size of a signature from this key

Source

pub fn export_for_lock(&self, lock: &LockId) -> Option<IdentityLockbox>

Pack this key into a Lockbox, meant for the recipient specified by lock. Returns None if this key cannot be exported.

Source

pub fn export_for_lock_with_rng<R>( &self, csprng: &mut R, lock: &LockId, ) -> Option<IdentityLockbox>
where R: CryptoRng + RngCore,

Pack this key into a Lockbox, meant for the recipient specified by lock. Returns None if this key cannot be exported.

Source

pub fn export_for_stream(&self, stream: &StreamKey) -> Option<IdentityLockbox>

Pack this key into a Lockbox, meant for the recipient specified by stream. Returns None if this key cannot be exported.

Source

pub fn export_for_stream_with_rng<R>( &self, csprng: &mut R, stream: &StreamKey, ) -> Option<IdentityLockbox>
where R: CryptoRng + RngCore,

Pack this key into a Lockbox, meant for the recipient specified by stream. Returns None if this key cannot be exported.

Trait Implementations§

Source§

impl Clone for IdentityKey

Source§

fn clone(&self) -> IdentityKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IdentityKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for IdentityKey

Source§

fn default() -> IdentityKey

Returns the “default value” for a type. Read more
Source§

impl Display for IdentityKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Display just the Identity (never the underlying key).

Source§

impl<T> From<T> for IdentityKey
where T: SignInterface + 'static,

Source§

fn from(value: T) -> IdentityKey

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.