pub struct Key { /* private fields */ }Implementations§
Source§impl Key
impl Key
pub fn new(public_keys: impl AsRef<PublicKeys>) -> Self
pub fn new_allow_all(public_keys: impl AsRef<PublicKeys>) -> Self
pub fn new_with_private_keys( private_keys: PrivateKeys, public_keys: PublicKeys, ) -> Self
pub fn new_with_private_key_base(private_key_base: PrivateKeyBase) -> Self
pub fn public_keys(&self) -> &PublicKeys
pub fn private_keys(&self) -> Option<&PrivateKeys>
pub fn has_private_keys(&self) -> bool
pub fn has_encrypted_private_keys(&self) -> bool
pub fn private_key_salt(&self) -> Option<&Salt>
Sourcepub fn private_key_envelope(
&self,
password: Option<&str>,
) -> Result<Option<Envelope>>
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 presentOk(Some(Envelope))containing:- Decrypted
PrivateKeysif unencrypted - Decrypted
PrivateKeysif encrypted and correct password provided - Encrypted envelope if encrypted and no password provided
- Decrypted
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 PrivateKeyspub fn signing_public_key(&self) -> &SigningPublicKey
pub fn encapsulation_public_key(&self) -> &EncapsulationPublicKey
pub fn endpoints(&self) -> &HashSet<URI>
pub fn endpoints_mut(&mut self) -> &mut HashSet<URI>
pub fn add_endpoint(&mut self, endpoint: URI)
pub fn permissions(&self) -> &Permissions
pub fn permissions_mut(&mut self) -> &mut Permissions
pub fn add_permission(&mut self, privilege: Privilege)
Source§impl Key
impl Key
pub fn into_envelope_opt( self, private_key_options: XIDPrivateKeyOptions, ) -> Envelope
Source§impl Key
impl Key
Sourcepub fn try_from_envelope(
envelope: &Envelope,
password: Option<&[u8]>,
) -> Result<Self>
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 EnvelopeEncodable for Key
impl EnvelopeEncodable for Key
Source§impl HasNickname for Key
impl HasNickname for Key
Source§impl HasPermissions for Key
impl HasPermissions for Key
fn permissions(&self) -> &Permissions
fn permissions_mut(&mut self) -> &mut Permissions
fn allow(&self) -> &HashSet<Privilege>
fn deny(&self) -> &HashSet<Privilege>
fn allow_mut(&mut self) -> &mut HashSet<Privilege>
fn deny_mut(&mut self) -> &mut HashSet<Privilege>
fn add_allow(&mut self, privilege: Privilege)
fn add_deny(&mut self, privilege: Privilege)
fn remove_allow(&mut self, privilege: &Privilege)
fn remove_deny(&mut self, privilege: &Privilege)
fn clear_all_permissions(&mut self)
Source§impl PublicKeysProvider for Key
impl PublicKeysProvider for Key
Source§fn public_keys(&self) -> PublicKeys
fn public_keys(&self) -> PublicKeys
Returns a complete set of public keys for cryptographic operations. Read more
Source§impl ReferenceProvider for &Key
impl ReferenceProvider for &Key
Source§fn reference(&self) -> Reference
fn reference(&self) -> Reference
Returns a cryptographic reference that uniquely identifies this object. Read more
Source§fn ref_hex_short(&self) -> String
fn ref_hex_short(&self) -> String
Returns the first four bytes of the reference as a hexadecimal string. Read more
impl Eq for Key
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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