pub struct Context { /* private fields */ }Expand description
Configuration for the PKCS#11 interface.
Implementations§
Source§impl Context
impl Context
Sourcepub fn backends(&self) -> Result<&[Backend]>
pub fn backends(&self) -> Result<&[Backend]>
Returns a reference to the PKCS#11 contexts.
The context has bound the specified libraries. As this loads the modules, this function may return an error if a module can’t be loaded.
Sourcepub fn tokens(&self) -> Result<impl Iterator<Item = Token>>
pub fn tokens(&self) -> Result<impl Iterator<Item = Token>>
Returns an iterator over all of the tokens.
Sourcepub fn select_one_token(&self, selector: &TokenSelector) -> Result<Token>
pub fn select_one_token(&self, selector: &TokenSelector) -> Result<Token>
Selects the unique token designated by selector.
Returns an error if no tokens or more than one token matches the selector.
Sourcepub fn keys(&self) -> Result<impl Iterator<Item = Key>>
pub fn keys(&self) -> Result<impl Iterator<Item = Key>>
Returns an iterator over all of the keys.
Sourcepub fn select_one_key(
&self,
selector: &KeySelector,
scope: SelectorScope,
) -> Result<Key>
pub fn select_one_key( &self, selector: &KeySelector, scope: SelectorScope, ) -> Result<Key>
Select the unique key designated by selector.
Returns an error if no keys or more than one key matches the selector.
Sourcepub fn select_keys(
&self,
selector: &KeySelector,
scope: SelectorScope,
) -> Result<Vec<Key>>
pub fn select_keys( &self, selector: &KeySelector, scope: SelectorScope, ) -> Result<Vec<Key>>
Selects the keys designated by selector.
Returns Ok(vec![]) if there are no matches. That is, no
matches is not an error.
Sourcepub fn check_no_keys_have_label(&self, label: &str) -> Result<()>
pub fn check_no_keys_have_label(&self, label: &str) -> Result<()>
Returns an error if any keys have the specified label.
Sourcepub fn check_no_keys_have_id(&self, id: &str) -> Result<()>
pub fn check_no_keys_have_id(&self, id: &str) -> Result<()>
Returns an error if any keys have the specified key ID.
Source§impl Context
Key import.
impl Context
Key import.
Sourcepub fn import(
&self,
session: &Session,
token: Token,
key_label: Option<&str>,
key: &Key<SecretParts, UnspecifiedRole>,
capability: KeyCapability,
) -> Result<Key>
pub fn import( &self, session: &Session, token: Token, key_label: Option<&str>, key: &Key<SecretParts, UnspecifiedRole>, capability: KeyCapability, ) -> Result<Key>
Import a key to the specified token.
The key must already be unencrypted. (See Key::decrypt_secret.)
Source§impl Context
Key generation.
impl Context
Key generation.
Sourcepub fn generate_eddsa<T>(
&self,
session: &Session,
token: Token,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_eddsa<T>( &self, session: &Session, token: Token, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new EdDSA key.
EdDSA keys are based on elliptical curve cryptography, and can be used for signing. They are only defined for version 4 keys.
To generate a version 6 key, use Context::generate_ed25519.
Sourcepub fn generate_ed25519<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_ed25519<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new Ed25519 key.
Sourcepub fn generate_ed448<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_ed448<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new Ed448 key.
Sourcepub fn generate_legacy_cv25519<T>(
&self,
session: &Session,
token: Token,
creation_time: T,
hash_algo: Option<HashAlgorithm>,
sym_algo: Option<SymmetricAlgorithm>,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_legacy_cv25519<T>( &self, session: &Session, token: Token, creation_time: T, hash_algo: Option<HashAlgorithm>, sym_algo: Option<SymmetricAlgorithm>, key_label: Option<&str>, ) -> Result<Key>
Generates a new cv25519 key.
cv25519 keys are based on elliptical curve cryptography, and
can be used for encryption. They are only defined for version
4 keys, and they take two parameters: a hash function, and a
symmetric algorithm. If either parameter is None, we use
the recommended values as per RFC 9580, section 11.5.1. ECDH
Parameters.
To generate a version 6 key, use Context::generate_x25519.
Sourcepub fn generate_mldsa65_ed25519<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_mldsa65_ed25519<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new MLDSA65+Ed25519 key.
This generates two PKCS#11 keys: an MLDSA65 key and an Ed25519 key. The two keys are linked via their key ID. Hence, either can be specified and the other will be found automatically.
Sourcepub fn generate_mldsa87_ed448<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_mldsa87_ed448<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new MLDSA87+Ed448 key.
This generates two PKCS#11 keys: an MLDSA87 key and an ED448 key. The two keys are linked via their key ID. Hence, either can be specified and the other will be found automatically.
Sourcepub fn generate_slh_dsa_128s<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_slh_dsa_128s<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new SLH-DSA-128s key.
Sourcepub fn generate_slh_dsa_128f<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_slh_dsa_128f<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new SLH-DSA-128f key.
Sourcepub fn generate_slh_dsa_256s<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_slh_dsa_256s<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new SLH-DSA-256s key.
Sourcepub fn generate_x25519<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_x25519<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new X25519 key.
[x25519 keys] are based on elliptical curve cryptography, and can be used for encryption.
If profile is RFC4880, then a version 4 key is created
using the default parameters. See
Context::generate_legacy_cv25519 for more information
about version 4 keys. Note: version 6 keys don’t have any
free parameters.
Sourcepub fn generate_mlkem768_x25519<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_mlkem768_x25519<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new MLKEM768+X25519 key.
This generates two PKCS#11 keys: an MLKEM768 key and a X25519 key. The two keys are linked via their key ID. Hence, either can be specified and the other will be found automatically.
Sourcepub fn generate_x448<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_x448<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new X448 key.
Sourcepub fn generate_mlkem1024_x448<T>(
&self,
session: &Session,
token: Token,
profile: Profile,
creation_time: T,
key_label: Option<&str>,
) -> Result<Key>
pub fn generate_mlkem1024_x448<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
Generates a new MLKEM1024+X448 key.
This generates two PKCS#11 keys: an MLKEM1024 key and a X448 key. The two keys are linked via their key ID. Hence, either can be specified and the other will be found automatically.