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) -> IdentityKeywhere 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: CryptoRng + RngCore>( &self, csprng: &mut R, 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_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: CryptoRng + RngCore>( &self, csprng: &mut R, 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.

Trait Implementations§

source§

impl Clone for IdentityKey

source§

fn clone(&self) -> IdentityKey

Returns a copy 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

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

impl Default for IdentityKey

source§

fn default() -> Self

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

impl Display for IdentityKey

source§

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

Display just the Identity (never the underlying key).

source§

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

source§

fn from(value: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.