Keys

Struct Keys 

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

Key storage (HSM) subsystem.

Provides secure key storage in the hardware security module.

§Example

use quantacore::{initialize, open_first_device, KeyType, KeyUsage};

initialize().unwrap();
let device = open_first_device().unwrap();
let keys = device.keys();

// Store a key
let key_data = vec![0u8; 32]; // Your key material
keys.store(
    0,  // slot
    KeyType::Secret,
    0,  // algorithm
    KeyUsage::ENCRYPT | KeyUsage::DECRYPT,
    "my-key",
    &key_data,
).unwrap();

// Load the key
let loaded = keys.load(0).unwrap();

// Get key info
let info = keys.get_info(0).unwrap();
println!("Key label: {}", info.label);

// Delete the key
keys.delete(0).unwrap();

Implementations§

Source§

impl Keys

Source

pub fn store( &self, slot: u32, key_type: KeyType, algorithm: i32, usage: KeyUsage, label: &str, key_data: &[u8], ) -> Result<()>

Store a key in the HSM.

§Arguments
  • slot - The slot number to store the key in
  • key_type - The type of key
  • algorithm - The algorithm identifier
  • usage - Allowed usage flags
  • label - A human-readable label (max 63 chars)
  • key_data - The raw key material
Source

pub fn load(&self, slot: u32) -> Result<Vec<u8>>

Load a key from the HSM.

§Arguments
  • slot - The slot number to load from
§Returns

The raw key material.

Source

pub fn get_info(&self, slot: u32) -> Result<KeyInfo>

Get information about a stored key.

§Arguments
  • slot - The slot number
§Returns

Information about the key in that slot.

Source

pub fn delete(&self, slot: u32) -> Result<()>

Delete a key from the HSM.

§Arguments
  • slot - The slot number to delete
Source

pub fn list(&self) -> Result<Vec<u32>>

List all occupied key slots.

§Returns

A vector of slot numbers that contain keys.

Source

pub fn get_slot_count(&self) -> Result<u32>

Get the total number of key slots.

Source

pub fn get_free_slot(&self) -> Result<u32>

Find the first free slot.

§Returns

The slot number, or an error if no free slots.

Source

pub fn clear_all(&self) -> Result<()>

Clear all keys from the HSM.

WARNING: This permanently deletes all stored keys!

Source

pub fn is_slot_occupied(&self, slot: u32) -> Result<bool>

Check if a slot is occupied.

Source

pub fn store_keypair( &self, slot: u32, algorithm: i32, label: &str, public_key: &[u8], secret_key: &[u8], ) -> Result<()>

Store a key pair (public + secret).

This is a convenience method that stores both keys in adjacent slots.

§Arguments
  • slot - The base slot (public key goes here, secret at slot+1)
  • algorithm - Algorithm identifier
  • label - Label prefix
  • public_key - Public key bytes
  • secret_key - Secret key bytes

Trait Implementations§

Source§

impl Clone for Keys

Source§

fn clone(&self) -> Keys

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Keys

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Keys

§

impl RefUnwindSafe for Keys

§

impl Send for Keys

§

impl Sync for Keys

§

impl Unpin for Keys

§

impl UnwindSafe for Keys

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.