@@ -35,7 +35,6 @@ use std::fmt;
3535use std:: mem;
3636use std:: path:: Path ;
3737use std:: ptr;
38- use std:: sync:: Arc ;
3938use std:: sync:: RwLock ;
4039
4140/// Enum for various function lists
@@ -101,10 +100,10 @@ impl Drop for Pkcs11Impl {
101100}
102101
103102/// Main PKCS11 context. Should usually be unique per application.
104- #[ derive( Clone , Debug ) ]
103+ #[ derive( Debug ) ]
105104pub struct Pkcs11 {
106- pub ( crate ) impl_ : Arc < Pkcs11Impl > ,
107- initialized : Arc < RwLock < bool > > ,
105+ pub ( crate ) impl_ : Pkcs11Impl ,
106+ initialized : RwLock < bool > ,
108107}
109108
110109impl Pkcs11 {
@@ -155,11 +154,11 @@ impl Pkcs11 {
155154 let list30_ptr: * mut cryptoki_sys:: CK_FUNCTION_LIST_3_0 =
156155 ifce. pFunctionList as * mut cryptoki_sys:: CK_FUNCTION_LIST_3_0 ;
157156 return Ok ( Pkcs11 {
158- impl_ : Arc :: new ( Pkcs11Impl {
157+ impl_ : Pkcs11Impl {
159158 _pkcs11_lib : pkcs11_lib,
160159 function_list : FunctionList :: V3_0 ( * list30_ptr) ,
161- } ) ,
162- initialized : Arc :: new ( RwLock :: new ( false ) ) ,
160+ } ,
161+ initialized : RwLock :: new ( false ) ,
163162 } ) ;
164163 }
165164 /* fall back to the 2.* API */
@@ -174,21 +173,17 @@ impl Pkcs11 {
174173 let list_ptr = * list. as_ptr ( ) ;
175174
176175 Ok ( Pkcs11 {
177- impl_ : Arc :: new ( Pkcs11Impl {
176+ impl_ : Pkcs11Impl {
178177 _pkcs11_lib : pkcs11_lib,
179178 function_list : FunctionList :: V2 ( v2tov3 ( * list_ptr) ) ,
180- } ) ,
181- initialized : Arc :: new ( RwLock :: new ( false ) ) ,
179+ } ,
180+ initialized : RwLock :: new ( false ) ,
182181 } )
183182 }
184183
185184 /// Initialize the PKCS11 library
186185 pub fn initialize ( & self , init_args : CInitializeArgs ) -> Result < ( ) > {
187- let mut init_lock = self
188- . initialized
189- . as_ref ( )
190- . write ( )
191- . expect ( "lock not to be poisoned" ) ;
186+ let mut init_lock = self . initialized . write ( ) . expect ( "lock not to be poisoned" ) ;
192187 if * init_lock {
193188 Err ( Error :: AlreadyInitialized ) ?
194189 }
@@ -197,11 +192,7 @@ impl Pkcs11 {
197192
198193 /// Check whether the PKCS11 library has been initialized
199194 pub fn is_initialized ( & self ) -> bool {
200- * self
201- . initialized
202- . as_ref ( )
203- . read ( )
204- . expect ( "lock not to be poisoned" )
195+ * self . initialized . read ( ) . expect ( "lock not to be poisoned" )
205196 }
206197
207198 /// Finalize the PKCS11 library. Indicates that the application no longer needs to use PKCS11.
0 commit comments