Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump cryptoki to 0.7.0. Add pkcs11 function to errors. #3

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "r2d2-cryptoki"
version = "0.2.1"
version = "0.3.0"
edition = "2021"
authors = ["Spruce Systems, Inc."]
license = "MIT OR Apache-2.0"
Expand All @@ -12,7 +12,7 @@ documentation = "https://docs.rs/r2d2-cryptoki/"
serde = ["cryptoki/serde"]

[dependencies]
cryptoki = "0.6.0"
cryptoki = "0.7.0"
r2d2 = "0.8.10"

[dev-dependencies]
Expand Down
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use cryptoki;
pub use r2d2;

use cryptoki::{
context::Pkcs11,
context::{Function, Pkcs11},
error::RvError,
session::{Session, SessionState, UserType},
slot::{Limit, Slot},
Expand Down Expand Up @@ -101,9 +101,9 @@ impl SessionManager {
}
};
let res = match limit {
Limit::Max(m) => Some(m.try_into().unwrap_or(u32::max_value())),
Limit::Max(m) => Some(m.try_into().unwrap_or(u32::MAX)),
Limit::Unavailable => None,
Limit::Infinite => Some(u32::max_value()),
Limit::Infinite => Some(u32::MAX),
};
Ok(if let Some(true) = res.map(|r| r > maximum) {
Some(maximum)
Expand Down Expand Up @@ -136,7 +136,7 @@ impl ManageConnection for SessionManager {
};
if let Some(user_type) = maybe_user_info {
match session.login(user_type.0, Some(user_type.1)) {
Err(Self::Error::Pkcs11(RvError::UserAlreadyLoggedIn)) => {}
Err(Self::Error::Pkcs11(RvError::UserAlreadyLoggedIn, Function::Login)) => {}
res => res?,
};
}
Expand All @@ -147,7 +147,10 @@ impl ManageConnection for SessionManager {
let actual_state = session.get_session_info()?.session_state();
let expected_state = &self.session_type;
if actual_state != expected_state.as_state() {
Err(Self::Error::Pkcs11(RvError::UserNotLoggedIn))
Err(Self::Error::Pkcs11(
RvError::UserNotLoggedIn,
Function::GetSessionInfo,
))
} else {
Ok(())
}
Expand Down
Loading