@@ -488,10 +488,13 @@ impl<T> Session<T> {
488488 mode : Mode ,
489489 min_version : TlsVersion ,
490490 certificates : Certificates ,
491+ sha : impl Peripheral < P = SHA > ,
491492 ) -> Result < Self , TlsError > {
492- // TODO: Take peripheral from user
493- let sha = Sha :: new ( unsafe { SHA :: steal ( ) } ) ;
494- critical_section:: with ( |cs| SHARED_SHA . borrow_ref_mut ( cs) . replace ( sha) ) ;
493+ critical_section:: with ( |cs| {
494+ SHARED_SHA
495+ . borrow_ref_mut ( cs)
496+ . replace ( unsafe { core:: mem:: transmute ( Sha :: new ( sha) ) } )
497+ } ) ;
495498
496499 let ( drbg_context, ssl_context, ssl_config, crt, client_crt, private_key) =
497500 certificates. init_ssl ( servername, mode, min_version) ?;
@@ -634,6 +637,7 @@ impl<T> Drop for Session<T> {
634637 if self . owns_rsa {
635638 RSA_REF = core:: mem:: transmute ( None :: < RSA > ) ;
636639 }
640+ critical_section:: with ( |cs| SHARED_SHA . borrow_ref_mut ( cs) . take ( ) ) ;
637641 mbedtls_ssl_close_notify ( self . ssl_context ) ;
638642 mbedtls_ctr_drbg_free ( self . drbg_context ) ;
639643 mbedtls_ssl_config_free ( self . ssl_config ) ;
@@ -744,10 +748,13 @@ pub mod asynch {
744748
745749 rx_buffer : & ' a mut [ u8 ; RX_SIZE ] ,
746750 tx_buffer : & ' a mut [ u8 ; TX_SIZE ] ,
751+ sha : impl Peripheral < P = SHA > ,
747752 ) -> Result < Self , TlsError > {
748- // TODO: Take peripheral from user
749- let sha = Sha :: new ( unsafe { SHA :: steal ( ) } ) ;
750- critical_section:: with ( |cs| SHARED_SHA . borrow_ref_mut ( cs) . replace ( sha) ) ;
753+ critical_section:: with ( |cs| {
754+ SHARED_SHA
755+ . borrow_ref_mut ( cs)
756+ . replace ( unsafe { core:: mem:: transmute ( Sha :: new ( sha) ) } )
757+ } ) ;
751758
752759 let ( drbg_context, ssl_context, ssl_config, crt, client_crt, private_key) =
753760 certificates. init_ssl ( servername, mode, min_version) ?;
@@ -790,6 +797,7 @@ pub mod asynch {
790797 if self . owns_rsa {
791798 RSA_REF = core:: mem:: transmute ( None :: < RSA > ) ;
792799 }
800+ critical_section:: with ( |cs| SHARED_SHA . borrow_ref_mut ( cs) . take ( ) ) ;
793801 mbedtls_ssl_close_notify ( self . ssl_context ) ;
794802 mbedtls_ctr_drbg_free ( self . drbg_context ) ;
795803 mbedtls_ssl_config_free ( self . ssl_config ) ;
0 commit comments