@@ -20,14 +20,16 @@ use std::convert::{TryFrom, TryInto};
20
20
21
21
use crate :: error:: RvError :: BufferTooSmall ;
22
22
23
+ use super :: Function ;
24
+
23
25
impl Pkcs11 {
24
26
#[ inline( always) ]
25
27
fn get_slots ( & self , with_token : CK_BBOOL ) -> Result < Vec < Slot > > {
26
28
let mut slot_count = 0 ;
27
29
let rval = unsafe {
28
30
get_pkcs11 ! ( self , C_GetSlotList ) ( with_token, std:: ptr:: null_mut ( ) , & mut slot_count)
29
31
} ;
30
- Rv :: from ( rval) . into_result ( ) ?;
32
+ Rv :: from ( rval) . into_result ( Function :: GetSlotList ) ?;
31
33
32
34
let mut slots;
33
35
loop {
@@ -41,7 +43,7 @@ impl Pkcs11 {
41
43
// and we want to loop again with a resized buffer.
42
44
if !matches ! ( Rv :: from( rval) , Rv :: Error ( BufferTooSmall ) ) {
43
45
// Account for other possible error types
44
- Rv :: from ( rval) . into_result ( ) ?;
46
+ Rv :: from ( rval) . into_result ( Function :: GetSlotList ) ?;
45
47
// Otherwise, we have a valid list to process
46
48
break ;
47
49
}
@@ -92,7 +94,7 @@ impl Pkcs11 {
92
94
pin. expose_secret ( ) . len ( ) . try_into ( ) ?,
93
95
label. as_ptr ( ) as * mut u8 ,
94
96
) )
95
- . into_result ( )
97
+ . into_result ( Function :: InitToken )
96
98
}
97
99
}
98
100
@@ -104,7 +106,7 @@ impl Pkcs11 {
104
106
slot. into ( ) ,
105
107
& mut slot_info,
106
108
) )
107
- . into_result ( ) ?;
109
+ . into_result ( Function :: GetSlotInfo ) ?;
108
110
Ok ( SlotInfo :: from ( slot_info) )
109
111
}
110
112
}
@@ -117,7 +119,7 @@ impl Pkcs11 {
117
119
slot. into ( ) ,
118
120
& mut token_info,
119
121
) )
120
- . into_result ( ) ?;
122
+ . into_result ( Function :: GetTokenInfo ) ?;
121
123
TokenInfo :: try_from ( token_info)
122
124
}
123
125
}
@@ -132,7 +134,7 @@ impl Pkcs11 {
132
134
std:: ptr:: null_mut ( ) ,
133
135
& mut mechanism_count,
134
136
) )
135
- . into_result ( ) ?;
137
+ . into_result ( Function :: GetMechanismList ) ?;
136
138
}
137
139
138
140
let mut mechanisms = vec ! [ 0 ; mechanism_count. try_into( ) ?] ;
@@ -143,7 +145,7 @@ impl Pkcs11 {
143
145
mechanisms. as_mut_ptr ( ) ,
144
146
& mut mechanism_count,
145
147
) )
146
- . into_result ( ) ?;
148
+ . into_result ( Function :: GetMechanismList ) ?;
147
149
}
148
150
149
151
// Truncate mechanisms if count decreased.
@@ -164,7 +166,7 @@ impl Pkcs11 {
164
166
type_. into ( ) ,
165
167
& mut mechanism_info,
166
168
) )
167
- . into_result ( ) ?;
169
+ . into_result ( Function :: GetMechanismInfo ) ?;
168
170
Ok ( MechanismInfo :: from ( mechanism_info) )
169
171
}
170
172
}
@@ -174,7 +176,7 @@ impl Pkcs11 {
174
176
let mut slot: CK_SLOT_ID = 0 ;
175
177
let wait_for_slot_event = get_pkcs11 ! ( self , C_WaitForSlotEvent ) ;
176
178
let rv = wait_for_slot_event ( flags, & mut slot, std:: ptr:: null_mut ( ) ) ;
177
- Rv :: from ( rv) . into_result ( ) ?;
179
+ Rv :: from ( rv) . into_result ( Function :: WaitForSlotEvent ) ?;
178
180
Ok ( Slot :: new ( slot) )
179
181
}
180
182
}
@@ -187,7 +189,7 @@ impl Pkcs11 {
187
189
/// Get the latest slot event (insertion or removal of a token)
188
190
pub fn get_slot_event ( & self ) -> Result < Option < Slot > > {
189
191
match self . wait_for_slot_event_impl ( CKF_DONT_BLOCK ) {
190
- Err ( Error :: Pkcs11 ( RvError :: NoEvent ) ) => Ok ( None ) ,
192
+ Err ( Error :: Pkcs11 ( RvError :: NoEvent , Function :: WaitForSlotEvent ) ) => Ok ( None ) ,
191
193
Ok ( slot) => Ok ( Some ( slot) ) ,
192
194
Err ( x) => Err ( x) ,
193
195
}
0 commit comments