@@ -34,7 +34,6 @@ use log::error;
3434use std:: fmt;
3535use std:: path:: Path ;
3636use std:: ptr;
37- use std:: sync:: Arc ;
3837use std:: sync:: RwLock ;
3938
4039/// Enum for various function lists
@@ -100,10 +99,10 @@ impl Drop for Pkcs11Impl {
10099}
101100
102101/// Main PKCS11 context. Should usually be unique per application.
103- #[ derive( Clone , Debug ) ]
102+ #[ derive( Debug ) ]
104103pub struct Pkcs11 {
105- pub ( crate ) impl_ : Arc < Pkcs11Impl > ,
106- initialized : Arc < RwLock < bool > > ,
104+ pub ( crate ) impl_ : Pkcs11Impl ,
105+ initialized : RwLock < bool > ,
107106}
108107
109108impl Pkcs11 {
@@ -154,21 +153,21 @@ impl Pkcs11 {
154153 let list32_ptr: * mut cryptoki_sys:: CK_FUNCTION_LIST_3_2 =
155154 ifce. pFunctionList as * mut cryptoki_sys:: CK_FUNCTION_LIST_3_2 ;
156155 return Ok ( Pkcs11 {
157- impl_ : Arc :: new ( Pkcs11Impl {
156+ impl_ : Pkcs11Impl {
158157 _pkcs11_lib : pkcs11_lib,
159158 function_list : FunctionList :: V3_2 ( * list32_ptr) ,
160- } ) ,
161- initialized : Arc :: new ( RwLock :: new ( false ) ) ,
159+ } ,
160+ initialized : RwLock :: new ( false ) ,
162161 } ) ;
163162 }
164163 let list30_ptr: * mut cryptoki_sys:: CK_FUNCTION_LIST_3_0 =
165164 ifce. pFunctionList as * mut cryptoki_sys:: CK_FUNCTION_LIST_3_0 ;
166165 return Ok ( Pkcs11 {
167- impl_ : Arc :: new ( Pkcs11Impl {
166+ impl_ : Pkcs11Impl {
168167 _pkcs11_lib : pkcs11_lib,
169168 function_list : FunctionList :: V3_0 ( v30tov32 ( * list30_ptr) ) ,
170- } ) ,
171- initialized : Arc :: new ( RwLock :: new ( false ) ) ,
169+ } ,
170+ initialized : RwLock :: new ( false ) ,
172171 } ) ;
173172 }
174173 /* fall back to the 2.* API */
@@ -180,21 +179,17 @@ impl Pkcs11 {
180179 . into_result ( Function :: GetFunctionList ) ?;
181180
182181 Ok ( Pkcs11 {
183- impl_ : Arc :: new ( Pkcs11Impl {
182+ impl_ : Pkcs11Impl {
184183 _pkcs11_lib : pkcs11_lib,
185184 function_list : FunctionList :: V2 ( v2tov3 ( * list_ptr) ) ,
186- } ) ,
187- initialized : Arc :: new ( RwLock :: new ( false ) ) ,
185+ } ,
186+ initialized : RwLock :: new ( false ) ,
188187 } )
189188 }
190189
191190 /// Initialize the PKCS11 library
192191 pub fn initialize ( & self , init_args : CInitializeArgs ) -> Result < ( ) > {
193- let mut init_lock = self
194- . initialized
195- . as_ref ( )
196- . write ( )
197- . expect ( "lock not to be poisoned" ) ;
192+ let mut init_lock = self . initialized . write ( ) . expect ( "lock not to be poisoned" ) ;
198193 if * init_lock {
199194 Err ( Error :: AlreadyInitialized ) ?
200195 }
@@ -203,11 +198,7 @@ impl Pkcs11 {
203198
204199 /// Check whether the PKCS11 library has been initialized
205200 pub fn is_initialized ( & self ) -> bool {
206- * self
207- . initialized
208- . as_ref ( )
209- . read ( )
210- . expect ( "lock not to be poisoned" )
201+ * self . initialized . read ( ) . expect ( "lock not to be poisoned" )
211202 }
212203
213204 /// Finalize the PKCS11 library. Indicates that the application no longer needs to use PKCS11.
0 commit comments