LockId

Struct LockId 

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

An identifier for a corresponding LockKey that can be used to encrypt data for that key.

This contains a cryptographic public encryption key.

§Example


// We've been given a LockId that we're sending encrypted data to.
println!("LockId(Base58): {}", key.id());

// Encrypt some data for that LockId
let data = b"I am sensitive information, about to be encrypted";
let lockbox = id.encrypt_data(data.as_ref());

// The lockbox can be encoded onto a vec or used as raw bytes.
let mut to_send = Vec::new();
to_send.extend_from_slice(lockbox.as_bytes());

Implementations§

Source§

impl LockId

Source

pub fn encrypt_data(&self, content: &[u8]) -> DataLockbox

Encrypt a byte slice into a DataLockbox.

Source

pub fn encrypt_data_with_rng<R>( &self, csprng: &mut R, content: &[u8], ) -> DataLockbox
where R: CryptoRng + RngCore,

Encrypt a byte slice into a DataLockbox. Requires a cryptographic RNG to generate the needed nonce.

Source

pub fn version(&self) -> u8

Get the cryptographic algorithm version used for this ID.

Source

pub fn raw_public_key(&self) -> &[u8]

Get the raw public encryption key contained within.

Source

pub fn as_vec(&self) -> Vec<u8>

Convert into a byte vector. For extending an existing byte vector, see encode_vec.

Source

pub fn from_base58(s: &str) -> Result<LockId, CryptoError>

Attempt to parse a base58-encoded LockId.

Source

pub fn to_base58(&self) -> String

Convert into a base58-encoded LockId.

Source

pub fn encode_vec(&self, buf: &mut Vec<u8>)

Encode onto an existing byte vector. Writes out the version followed by the public signing key. It does not include any length information in the encoding.

Source

pub fn size(&self) -> usize

Get the length of this Identity once encoded as bytes.

Trait Implementations§

Source§

impl Clone for LockId

Source§

fn clone(&self) -> LockId

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 LockId

Source§

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

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

impl<'de> Deserialize<'de> for LockId

Source§

fn deserialize<D>( deserializer: D, ) -> Result<LockId, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

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

impl Display for LockId

Source§

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

Display as a base58-encoded string.

Source§

impl From<LockId> for Value

Source§

fn from(v: LockId) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<LockId> for ValueRef<'a>

Source§

fn from(v: LockId) -> Self

Converts to this type from the input type.
Source§

impl Hash for LockId

Source§

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

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 LowerHex for LockId

Source§

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

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

impl PartialEq for LockId

Source§

fn eq(&self, other: &LockId) -> 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 Serialize for LockId

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&[u8]> for LockId

Source§

type Error = CryptoError

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

fn try_from(value: &[u8]) -> Result<LockId, <LockId as TryFrom<&[u8]>>::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for LockId

Source§

type Error = Value

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

fn try_from(v: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<ValueRef<'a>> for LockId

Source§

type Error = ValueRef<'a>

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

fn try_from(v: ValueRef<'a>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl UpperHex for LockId

Source§

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

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

impl Eq for LockId

Source§

impl StructuralPartialEq for LockId

Auto Trait Implementations§

§

impl Freeze for LockId

§

impl RefUnwindSafe for LockId

§

impl Send for LockId

§

impl Sync for LockId

§

impl Unpin for LockId

§

impl UnwindSafe for LockId

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.
Source§

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