Struct Key

Source
pub struct Key(/* private fields */);
Expand description

Key structure which allows for signing and retrieval of the public key

§Examples

§Get the public Key

use secure_env::{SecureEnvironment, SecureEnvironmentOps, Key, KeyOps};

let key = SecureEnvironment::generate_keypair("documentation-public-key-token").unwrap();
let public_key_bytes = key.get_public_key().unwrap();

assert_eq!(public_key_bytes.len(), 33);

§Sign a message

use secure_env::{SecureEnvironment, SecureEnvironmentOps, Key, KeyOps};

let key = SecureEnvironment::generate_keypair("documentation-sign-key-token").unwrap();
let signature = key.sign(b"Hello World").unwrap();

assert_eq!(signature.len(), 64);

§Verify the signed message with askar_crypto

use secure_env::{SecureEnvironment, SecureEnvironmentOps, Key, KeyOps};
use askar_crypto::{alg::p256::P256KeyPair, repr::KeyPublicBytes};

let msg = b"Hello World!";
let key = SecureEnvironment::generate_keypair("my-test-sign-key").unwrap();

let public_key = key.get_public_key().unwrap();
let signature = key.sign(b"Hello World!").unwrap();

let verify_key = P256KeyPair::from_public_bytes(&public_key).unwrap();
let is_signature_valid = verify_key.verify_signature(msg, &signature);

assert!(is_signature_valid);

Trait Implementations§

Source§

impl Clone for Key

Source§

fn clone(&self) -> Key

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 Key

Source§

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

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

impl KeyOps for Key

Source§

fn sign(&self, msg: &[u8]) -> SecureEnvResult<Vec<u8>>

Signing is an operation that requires authentication. Make sure to manually authenticate before calling this operation

Source§

fn get_public_key(&self) -> SecureEnvResult<Vec<u8>>

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 SecureEnvironmentOps<Key> for SecureEnvironment

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