@@ -495,10 +495,13 @@ impl<T> Session<T> {
495
495
mode : Mode ,
496
496
min_version : TlsVersion ,
497
497
certificates : Certificates ,
498
+ sha : impl Peripheral < P = SHA > ,
498
499
) -> Result < Self , TlsError > {
499
- // TODO: Take peripheral from user
500
- let sha = Sha :: new ( unsafe { SHA :: steal ( ) } ) ;
501
- critical_section:: with ( |cs| SHARED_SHA . borrow_ref_mut ( cs) . replace ( sha) ) ;
500
+ critical_section:: with ( |cs| {
501
+ SHARED_SHA
502
+ . borrow_ref_mut ( cs)
503
+ . replace ( unsafe { core:: mem:: transmute ( Sha :: new ( sha) ) } )
504
+ } ) ;
502
505
503
506
let ( drbg_context, ssl_context, ssl_config, crt, client_crt, private_key) =
504
507
certificates. init_ssl ( servername, mode, min_version) ?;
@@ -641,6 +644,7 @@ impl<T> Drop for Session<T> {
641
644
if self . owns_rsa {
642
645
RSA_REF = core:: mem:: transmute ( None :: < RSA > ) ;
643
646
}
647
+ critical_section:: with ( |cs| SHARED_SHA . borrow_ref_mut ( cs) . take ( ) ) ;
644
648
mbedtls_ssl_close_notify ( self . ssl_context ) ;
645
649
mbedtls_ctr_drbg_free ( self . drbg_context ) ;
646
650
mbedtls_ssl_config_free ( self . ssl_config ) ;
@@ -751,10 +755,13 @@ pub mod asynch {
751
755
752
756
rx_buffer : & ' a mut [ u8 ; RX_SIZE ] ,
753
757
tx_buffer : & ' a mut [ u8 ; TX_SIZE ] ,
758
+ sha : impl Peripheral < P = SHA > ,
754
759
) -> Result < Self , TlsError > {
755
- // TODO: Take peripheral from user
756
- let sha = Sha :: new ( unsafe { SHA :: steal ( ) } ) ;
757
- critical_section:: with ( |cs| SHARED_SHA . borrow_ref_mut ( cs) . replace ( sha) ) ;
760
+ critical_section:: with ( |cs| {
761
+ SHARED_SHA
762
+ . borrow_ref_mut ( cs)
763
+ . replace ( unsafe { core:: mem:: transmute ( Sha :: new ( sha) ) } )
764
+ } ) ;
758
765
759
766
let ( drbg_context, ssl_context, ssl_config, crt, client_crt, private_key) =
760
767
certificates. init_ssl ( servername, mode, min_version) ?;
@@ -797,6 +804,7 @@ pub mod asynch {
797
804
if self . owns_rsa {
798
805
RSA_REF = core:: mem:: transmute ( None :: < RSA > ) ;
799
806
}
807
+ critical_section:: with ( |cs| SHARED_SHA . borrow_ref_mut ( cs) . take ( ) ) ;
800
808
mbedtls_ssl_close_notify ( self . ssl_context ) ;
801
809
mbedtls_ctr_drbg_free ( self . drbg_context ) ;
802
810
mbedtls_ssl_config_free ( self . ssl_config ) ;
0 commit comments