use crate::context::Pkcs11;
use cryptoki_sys::*;
use std::fmt::Formatter;
use std::marker::PhantomData;
mod decryption;
mod digesting;
mod encryption;
mod key_management;
mod object_management;
mod random;
mod session_info;
mod session_management;
mod signing_macing;
mod slot_token_management;
pub use session_info::{SessionInfo, SessionState};
#[derive(Debug)]
pub struct Session {
handle: CK_SESSION_HANDLE,
client: Pkcs11,
_guard: PhantomData<*mut u32>,
}
impl std::fmt::Display for Session {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.handle)
}
}
impl std::fmt::LowerHex for Session {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:08x}", self.handle)
}
}
impl std::fmt::UpperHex for Session {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:08X}", self.handle)
}
}
unsafe impl Send for Session {}
impl Session {
pub(crate) fn new(handle: CK_SESSION_HANDLE, client: Pkcs11) -> Self {
Session {
handle,
client,
_guard: PhantomData,
}
}
}
impl Session {
pub fn close(self) {}
pub(crate) fn handle(&self) -> CK_SESSION_HANDLE {
self.handle
}
pub(crate) fn client(&self) -> &Pkcs11 {
&self.client
}
}
#[derive(Copy, Clone, Debug)]
pub enum UserType {
So,
User,
ContextSpecific,
}
impl From<UserType> for CK_USER_TYPE {
fn from(user_type: UserType) -> CK_USER_TYPE {
match user_type {
UserType::So => CKU_SO,
UserType::User => CKU_USER,
UserType::ContextSpecific => CKU_CONTEXT_SPECIFIC,
}
}
}