Function psa_crypto::operations::key_management::destroy[][src]

pub unsafe fn destroy(key: Id) -> Result<()>
Expand description

Destroy a key

Safety

It is unsafe to destroy a key that is concurrently used for any cryptographic operation. This crate does not currently provide a mechanism to ensure thread safety of destroy_key but might do in the future. It is undefined behaviour to concurrently destroy and use a key.

This function can be safely called if the caller ensures that no other threads are concurrently using copies of the same Id (that includes different Id instances that were created using the same id parameter with the from_persistent_key_id function).

Example

use psa_crypto::operations::key_management;
use psa_crypto::types::key::{Attributes, Type, Lifetime, Policy, UsageFlags};
use psa_crypto::types::algorithm::{AsymmetricSignature, Hash};

psa_crypto::init().unwrap();
let my_key = key_management::generate(attributes, None).unwrap();
// Safe because no other threads is using this ID.
unsafe {key_management::destroy(my_key).unwrap() };