Skip to content

Commit b4c221d

Browse files
committed
Don't raise an error when the close fails because the session is invalid as it means it's already closed
1 parent 2702bba commit b4c221d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

cryptoki/src/session/session_management.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
//! Session management functions
44
55
use crate::context::Function;
6-
use crate::error::{Result, Rv};
6+
use crate::error::{Error, Result, Rv, RvError};
77
use crate::session::{Session, SessionInfo, UserType};
88
use crate::types::{AuthPin, RawAuthPin};
99

1010
#[cfg(doc)]
1111
use cryptoki_sys::CKF_PROTECTED_AUTHENTICATION_PATH;
1212
use cryptoki_sys::CK_SESSION_INFO;
13-
use log::error;
13+
use log::{error, warn};
1414
use secrecy::ExposeSecret;
1515
use std::convert::{TryFrom, TryInto};
1616

@@ -27,7 +27,14 @@ impl Drop for Session {
2727
}
2828

2929
if let Err(err) = close(self) {
30-
error!("Failed to close session: {err}");
30+
match err {
31+
Error::Pkcs11(RvError::SessionHandleInvalid, _) =>
32+
33+
34+
35+
warn!("Failed to close session: Session handle invalid - it may have already been closed."),
36+
_ => error!("Failed to close session: {err}"),
37+
}
3138
}
3239
}
3340
}

0 commit comments

Comments
 (0)