Skip to main content

Context

Struct Context 

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

Configuration for the PKCS#11 interface.

Implementations§

Source§

impl Context

Source

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.

Source

pub fn tokens(&self) -> Result<impl Iterator<Item = Token>>

Returns an iterator over all of the tokens.

Source

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.

Source

pub fn keys(&self) -> Result<impl Iterator<Item = Key>>

Returns an iterator over all of the keys.

Source

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.

Source

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.

Source

pub fn check_no_keys_have_label(&self, label: &str) -> Result<()>

Returns an error if any keys have the specified label.

Source

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.

Source

pub fn import( &self, session: &Session, token: Token, composite_session_token: Option<(&Session, 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.

Source

pub fn generate_eddsa<T>( &self, session: &Session, token: Token, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

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.

Source

pub fn generate_ed25519<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

Generates a new Ed25519 key.

Source

pub fn generate_ed448<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

Generates a new Ed448 key.

Source

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>
where T: Into<Option<SystemTime>>,

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.

Source

pub fn generate_mldsa65_ed25519<T>( &self, session: &Session, token: Token, pqc_session_token: Option<(&Session, Token)>, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

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.

The traditional component is generated on session/token, and the post-quantum component is generated on the pqc_session_token. If pqc_session_token is None, then the post quantum component is generated on the same token as the traditional component.

The traditional component is returned as the Key’s primary component. The post quantum component is returned as its composite component.

Source

pub fn generate_mldsa87_ed448<T>( &self, session: &Session, token: Token, pqc_session_token: Option<(&Session, Token)>, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

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.

The traditional component is generated on session/token, and the post-quantum component is generated on the pqc_session_token. If pqc_session_token is None, then the post quantum component is generated on the same token as the traditional component.

The traditional component is returned as the Key’s primary component. The post quantum component is returned as its composite component.

Source

pub fn generate_slh_dsa_128s<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

Generates a new SLH-DSA-128s key.

Source

pub fn generate_slh_dsa_128f<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

Generates a new SLH-DSA-128f key.

Source

pub fn generate_slh_dsa_256s<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

Generates a new SLH-DSA-256s key.

Source

pub fn generate_x25519<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

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.

Source

pub fn generate_mlkem768_x25519<T>( &self, session: &Session, token: Token, pqc_session_token: Option<(&Session, Token)>, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

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.

The traditional component is generated on session/token, and the post-quantum component is generated on the pqc_session_token. If pqc_session_token is None, then the post quantum component is generated on the same token as the traditional component.

The traditional component is returned as the Key’s primary component. The post quantum component is returned as its composite component.

Source

pub fn generate_x448<T>( &self, session: &Session, token: Token, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

Generates a new X448 key.

Source

pub fn generate_mlkem1024_x448<T>( &self, session: &Session, token: Token, pqc_session_token: Option<(&Session, Token)>, profile: Profile, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

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.

The traditional component is generated on session/token, and the post-quantum component is generated on the pqc_session_token. If pqc_session_token is None, then the post quantum component is generated on the same token as the traditional component.

The traditional component is returned as the Key’s primary component. The post quantum component is returned as its composite component.

Source

pub fn generate_rsa_for_signing<T>( &self, session: &Session, token: Token, profile: Profile, bits: usize, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

Generates a new signing-capable RSA key.

Source

pub fn generate_rsa_for_encryption<T>( &self, session: &Session, token: Token, profile: Profile, bits: usize, creation_time: T, key_label: Option<&str>, ) -> Result<Key>
where T: Into<Option<SystemTime>>,

Generates a new encryption-capable RSA key.

Source§

impl Context

Source

pub fn new() -> Result<Self>

Creates a new context.

This reads the default configuration file. To disable this or to read an alternate configuration file use ContextBuilder to create the context.

Source

pub fn config(&self) -> &Config

Returns the configuration.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.