Skip to main content

Key

Struct Key 

Source
pub struct Key { /* private fields */ }

Implementations§

Source§

impl Key

Source

pub fn new(public_keys: impl AsRef<PublicKeys>) -> Self

Source

pub fn new_allow_all(public_keys: impl AsRef<PublicKeys>) -> Self

Source

pub fn new_with_private_keys( private_keys: PrivateKeys, public_keys: PublicKeys, ) -> Self

Source

pub fn new_with_private_key_base(private_key_base: PrivateKeyBase) -> Self

Source

pub fn public_keys(&self) -> &PublicKeys

Source

pub fn private_keys(&self) -> Option<&PrivateKeys>

Source

pub fn has_private_keys(&self) -> bool

Source

pub fn has_encrypted_private_keys(&self) -> bool

Source

pub fn private_key_salt(&self) -> Option<&Salt>

Source

pub fn private_key_envelope( &self, password: Option<&str>, ) -> Result<Option<Envelope>>

Extract the private key data as an Envelope, optionally decrypting it.

§Returns
  • Ok(None) if no private key is present
  • Ok(Some(Envelope)) containing:
    • Decrypted PrivateKeys if unencrypted
    • Decrypted PrivateKeys if encrypted and correct password provided
    • Encrypted envelope if encrypted and no password provided
  • Err(...) if encrypted and wrong password provided
§Examples
use bc_components::PrivateKeyBase;
use bc_envelope::prelude::*;
use bc_xid::Key;

// Unencrypted key
let prvkey_base = PrivateKeyBase::new();
let key = Key::new_with_private_key_base(prvkey_base.clone());
let envelope = key.private_key_envelope(None).unwrap().unwrap();
// Returns envelope containing PrivateKeys

// Encrypted key without password
// Returns the encrypted envelope as-is

// Encrypted key with correct password
// Returns envelope containing decrypted PrivateKeys
Source

pub fn signing_public_key(&self) -> &SigningPublicKey

Source

pub fn encapsulation_public_key(&self) -> &EncapsulationPublicKey

Source

pub fn endpoints(&self) -> &HashSet<URI>

Source

pub fn endpoints_mut(&mut self) -> &mut HashSet<URI>

Source

pub fn add_endpoint(&mut self, endpoint: URI)

Source

pub fn permissions(&self) -> &Permissions

Source

pub fn permissions_mut(&mut self) -> &mut Permissions

Source

pub fn add_permission(&mut self, privilege: Privilege)

Source§

impl Key

Source

pub fn into_envelope_opt( self, private_key_options: XIDPrivateKeyOptions, ) -> Envelope

Source§

impl Key

Source

pub fn try_from_envelope( envelope: &Envelope, password: Option<&[u8]>, ) -> Result<Self>

Try to extract a Key from an envelope, optionally providing a password to decrypt an encrypted private key.

If the private key is encrypted and no password is provided, the Key will be created without the private key (it will be None).

Trait Implementations§

Source§

impl Clone for Key

Source§

fn clone(&self) -> Key

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 Key

Source§

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

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

impl EnvelopeEncodable for Key

Source§

fn into_envelope(self) -> Envelope

Converts this value into a Gordian Envelope. Read more
Source§

fn to_envelope(&self) -> Envelope
where Self: Clone,

Converts a reference to this value into a Gordian Envelope. Read more
Source§

impl HasNickname for Key

Source§

fn nickname(&self) -> &str

Source§

fn set_nickname(&mut self, nickname: impl Into<String>)

Source§

fn add_nickname(&mut self, name: &str) -> Result<()>

Source§

impl HasPermissions for Key

Source§

fn permissions(&self) -> &Permissions

Source§

fn permissions_mut(&mut self) -> &mut Permissions

Source§

fn allow(&self) -> &HashSet<Privilege>

Source§

fn deny(&self) -> &HashSet<Privilege>

Source§

fn allow_mut(&mut self) -> &mut HashSet<Privilege>

Source§

fn deny_mut(&mut self) -> &mut HashSet<Privilege>

Source§

fn add_allow(&mut self, privilege: Privilege)

Source§

fn add_deny(&mut self, privilege: Privilege)

Source§

fn remove_allow(&mut self, privilege: &Privilege)

Source§

fn remove_deny(&mut self, privilege: &Privilege)

Source§

fn clear_all_permissions(&mut self)

Source§

impl Hash for Key

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Key

Source§

fn eq(&self, other: &Key) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PublicKeysProvider for Key

Source§

fn public_keys(&self) -> PublicKeys

Returns a complete set of public keys for cryptographic operations. Read more
Source§

impl ReferenceProvider for &Key

Source§

fn reference(&self) -> Reference

Returns a cryptographic reference that uniquely identifies this object. Read more
Source§

fn ref_hex(&self) -> String

Returns the reference data as a hexadecimal string. Read more
Source§

fn ref_data_short(&self) -> [u8; 4]

Returns the first four bytes of the reference. Read more
Source§

fn ref_hex_short(&self) -> String

Returns the first four bytes of the reference as a hexadecimal string. Read more
Source§

fn ref_bytewords(&self, prefix: Option<&str>) -> String

Returns the first four bytes of the reference as upper-case ByteWords. Read more
Source§

fn ref_bytemoji(&self, prefix: Option<&str>) -> String

Returns the first four bytes of the reference as Bytemoji. Read more
Source§

impl TryFrom<&Envelope> for Key

Source§

type Error = Error

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

fn try_from(envelope: &Envelope) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Envelope> for Key

Source§

type Error = Error

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

fn try_from(envelope: Envelope) -> Result<Self>

Performs the conversion.
Source§

impl Verifier for Key

Source§

fn verify(&self, signature: &Signature, message: &dyn AsRef<[u8]>) -> bool

Verifies a signature against a message. Read more
Source§

impl Eq for Key

Source§

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V