@@ -488,10 +488,13 @@ impl<T> Session<T> {
488
488
mode : Mode ,
489
489
min_version : TlsVersion ,
490
490
certificates : Certificates ,
491
+ sha : impl Peripheral < P = SHA > ,
491
492
) -> 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
+ } ) ;
495
498
496
499
let ( drbg_context, ssl_context, ssl_config, crt, client_crt, private_key) =
497
500
certificates. init_ssl ( servername, mode, min_version) ?;
@@ -634,6 +637,7 @@ impl<T> Drop for Session<T> {
634
637
if self . owns_rsa {
635
638
RSA_REF = core:: mem:: transmute ( None :: < RSA > ) ;
636
639
}
640
+ critical_section:: with ( |cs| SHARED_SHA . borrow_ref_mut ( cs) . take ( ) ) ;
637
641
mbedtls_ssl_close_notify ( self . ssl_context ) ;
638
642
mbedtls_ctr_drbg_free ( self . drbg_context ) ;
639
643
mbedtls_ssl_config_free ( self . ssl_config ) ;
@@ -744,10 +748,13 @@ pub mod asynch {
744
748
745
749
rx_buffer : & ' a mut [ u8 ; RX_SIZE ] ,
746
750
tx_buffer : & ' a mut [ u8 ; TX_SIZE ] ,
751
+ sha : impl Peripheral < P = SHA > ,
747
752
) -> 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
+ } ) ;
751
758
752
759
let ( drbg_context, ssl_context, ssl_config, crt, client_crt, private_key) =
753
760
certificates. init_ssl ( servername, mode, min_version) ?;
@@ -790,6 +797,7 @@ pub mod asynch {
790
797
if self . owns_rsa {
791
798
RSA_REF = core:: mem:: transmute ( None :: < RSA > ) ;
792
799
}
800
+ critical_section:: with ( |cs| SHARED_SHA . borrow_ref_mut ( cs) . take ( ) ) ;
793
801
mbedtls_ssl_close_notify ( self . ssl_context ) ;
794
802
mbedtls_ctr_drbg_free ( self . drbg_context ) ;
795
803
mbedtls_ssl_config_free ( self . ssl_config ) ;
0 commit comments