Skip to content

Commit

Permalink
add missing methods to SessionLike
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Gautier <[email protected]>
  • Loading branch information
baloo committed Feb 28, 2024
1 parent 28b92e4 commit 64f57a5
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion cryptoki-rustcrypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use cryptoki::{
error::Result,
mechanism::Mechanism,
object::{Attribute, AttributeType, ObjectHandle},
session::Session,
session::{Session, UserType},
types::AuthPin,
};

pub use cryptoki;
Expand All @@ -23,8 +24,17 @@ pub trait SessionLike {
object: ObjectHandle,
attributes: &[AttributeType],
) -> Result<Vec<Attribute>>;
fn update_attributes(&self, object: ObjectHandle, template: &[Attribute]) -> Result<()>;
fn sign(&self, mechanism: &Mechanism, key: ObjectHandle, data: &[u8]) -> Result<Vec<u8>>;
fn generate_random_slice(&self, random_data: &mut [u8]) -> Result<()>;
fn wrap_key(
&self,
mechanism: &Mechanism,
wrapping_key: ObjectHandle,
key: ObjectHandle,
) -> Result<Vec<u8>>;
fn login(&self, user_type: UserType, pin: Option<&AuthPin>) -> Result<()>;
fn logout(&self) -> Result<()>;
}

impl SessionLike for Session {
Expand All @@ -41,12 +51,30 @@ impl SessionLike for Session {
) -> Result<Vec<Attribute>> {
Session::get_attributes(self, object, attributes)
}
fn update_attributes(&self, object: ObjectHandle, template: &[Attribute]) -> Result<()> {
Session::update_attributes(self, object, template)
}

fn sign(&self, mechanism: &Mechanism, key: ObjectHandle, data: &[u8]) -> Result<Vec<u8>> {
Session::sign(self, mechanism, key, data)
}
fn generate_random_slice(&self, random_data: &mut [u8]) -> Result<()> {
Session::generate_random_slice(self, random_data)
}
fn wrap_key(
&self,
mechanism: &Mechanism,
wrapping_key: ObjectHandle,
key: ObjectHandle,
) -> Result<Vec<u8>> {
Session::wrap_key(self, mechanism, wrapping_key, key)
}
fn login(&self, user_type: UserType, pin: Option<&AuthPin>) -> Result<()> {
Session::login(self, user_type, pin)
}
fn logout(&self) -> Result<()> {
Session::logout(self)
}
}

impl<'s> SessionLike for &'s Session {
Expand All @@ -63,12 +91,30 @@ impl<'s> SessionLike for &'s Session {
) -> Result<Vec<Attribute>> {
Session::get_attributes(self, object, attributes)
}
fn update_attributes(&self, object: ObjectHandle, template: &[Attribute]) -> Result<()> {
Session::update_attributes(self, object, template)
}

fn sign(&self, mechanism: &Mechanism, key: ObjectHandle, data: &[u8]) -> Result<Vec<u8>> {
Session::sign(self, mechanism, key, data)
}
fn generate_random_slice(&self, random_data: &mut [u8]) -> Result<()> {
Session::generate_random_slice(self, random_data)
}
fn wrap_key(
&self,
mechanism: &Mechanism,
wrapping_key: ObjectHandle,
key: ObjectHandle,
) -> Result<Vec<u8>> {
Session::wrap_key(self, mechanism, wrapping_key, key)
}
fn login(&self, user_type: UserType, pin: Option<&AuthPin>) -> Result<()> {
Session::login(self, user_type, pin)
}
fn logout(&self) -> Result<()> {
Session::logout(self)
}
}

pub trait CryptokiImport {
Expand Down

0 comments on commit 64f57a5

Please sign in to comment.