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
impl Keys
Sourcepub fn store(
&self,
slot: u32,
key_type: KeyType,
algorithm: i32,
usage: KeyUsage,
label: &str,
key_data: &[u8],
) -> Result<()>
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 inkey_type- The type of keyalgorithm- The algorithm identifierusage- Allowed usage flagslabel- A human-readable label (max 63 chars)key_data- The raw key material
Sourcepub fn get_slot_count(&self) -> Result<u32>
pub fn get_slot_count(&self) -> Result<u32>
Get the total number of key slots.
Sourcepub fn get_free_slot(&self) -> Result<u32>
pub fn get_free_slot(&self) -> Result<u32>
Sourcepub fn clear_all(&self) -> Result<()>
pub fn clear_all(&self) -> Result<()>
Clear all keys from the HSM.
WARNING: This permanently deletes all stored keys!
Sourcepub fn is_slot_occupied(&self, slot: u32) -> Result<bool>
pub fn is_slot_occupied(&self, slot: u32) -> Result<bool>
Check if a slot is occupied.
Sourcepub fn store_keypair(
&self,
slot: u32,
algorithm: i32,
label: &str,
public_key: &[u8],
secret_key: &[u8],
) -> Result<()>
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 identifierlabel- Label prefixpublic_key- Public key bytessecret_key- Secret key bytes
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)