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 KeyOps for Key
impl KeyOps for Key
Source§fn sign(&self, msg: &[u8]) -> SecureEnvResult<Vec<u8>>
fn sign(&self, msg: &[u8]) -> SecureEnvResult<Vec<u8>>
Signing is an operation that requires authentication. Make sure to manually authenticate before calling this operation
fn get_public_key(&self) -> SecureEnvResult<Vec<u8>>
Source§impl SecureEnvironmentOps<Key> for SecureEnvironment
impl SecureEnvironmentOps<Key> for SecureEnvironment
fn generate_keypair( id: impl Into<String>, backed_by_biometrics: bool, ) -> SecureEnvResult<Key>
fn get_keypair_by_id(id: impl Into<String>) -> SecureEnvResult<Key>
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