44
55use crate :: error:: CryptographyResult ;
66use crate :: types;
7- use openssl:: symm :: Cipher ;
7+ use openssl:: cipher :: Cipher ;
88use std:: collections:: HashMap ;
99
1010struct RegistryKey {
@@ -54,7 +54,7 @@ impl std::hash::Hash for RegistryKey {
5454
5555struct RegisteryBuilder < ' p > {
5656 py : pyo3:: Python < ' p > ,
57- m : HashMap < RegistryKey , openssl:: symm :: Cipher > ,
57+ m : HashMap < RegistryKey , & ' static openssl:: cipher :: CipherRef > ,
5858}
5959
6060impl < ' p > RegisteryBuilder < ' p > {
@@ -70,7 +70,7 @@ impl<'p> RegisteryBuilder<'p> {
7070 algorithm : & pyo3:: PyAny ,
7171 mode : & pyo3:: PyAny ,
7272 key_size : Option < u16 > ,
73- cipher : openssl:: symm :: Cipher ,
73+ cipher : & ' static openssl:: cipher :: CipherRef ,
7474 ) -> CryptographyResult < ( ) > {
7575 self . m . insert (
7676 RegistryKey :: new ( self . py , algorithm. into ( ) , mode. into ( ) , key_size) ?,
@@ -80,16 +80,17 @@ impl<'p> RegisteryBuilder<'p> {
8080 Ok ( ( ) )
8181 }
8282
83- fn build ( self ) -> HashMap < RegistryKey , openssl:: symm :: Cipher > {
83+ fn build ( self ) -> HashMap < RegistryKey , & ' static openssl:: cipher :: CipherRef > {
8484 self . m
8585 }
8686}
8787
8888fn get_cipher_registry (
8989 py : pyo3:: Python < ' _ > ,
90- ) -> CryptographyResult < & HashMap < RegistryKey , openssl:: symm:: Cipher > > {
91- static REGISTRY : pyo3:: sync:: GILOnceCell < HashMap < RegistryKey , openssl:: symm:: Cipher > > =
92- pyo3:: sync:: GILOnceCell :: new ( ) ;
90+ ) -> CryptographyResult < & HashMap < RegistryKey , & ' static openssl:: cipher:: CipherRef > > {
91+ static REGISTRY : pyo3:: sync:: GILOnceCell <
92+ HashMap < RegistryKey , & ' static openssl:: cipher:: CipherRef > ,
93+ > = pyo3:: sync:: GILOnceCell :: new ( ) ;
9394
9495 REGISTRY . get_or_try_init ( py, || {
9596 let mut m = RegisteryBuilder :: new ( py) ;
@@ -123,11 +124,11 @@ fn get_cipher_registry(
123124 m. add ( triple_des, cbc, Some ( 192 ) , Cipher :: des_ede3_cbc ( ) ) ?;
124125
125126 #[ cfg( not( CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_CAMELLIA" ) ) ]
126- m. add ( camellia, cbc, Some ( 128 ) , Cipher :: camellia_128_cbc ( ) ) ?;
127+ m. add ( camellia, cbc, Some ( 128 ) , Cipher :: camellia128_cbc ( ) ) ?;
127128 #[ cfg( not( CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_CAMELLIA" ) ) ]
128- m. add ( camellia, cbc, Some ( 192 ) , Cipher :: camellia_192_cbc ( ) ) ?;
129+ m. add ( camellia, cbc, Some ( 192 ) , Cipher :: camellia192_cbc ( ) ) ?;
129130 #[ cfg( not( CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_CAMELLIA" ) ) ]
130- m. add ( camellia, cbc, Some ( 256 ) , Cipher :: camellia_256_cbc ( ) ) ?;
131+ m. add ( camellia, cbc, Some ( 256 ) , Cipher :: camellia256_cbc ( ) ) ?;
131132
132133 #[ cfg( not( CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_SM4" ) ) ]
133134 m. add ( sm4, cbc, Some ( 128 ) , Cipher :: sm4_cbc ( ) ) ?;
@@ -148,11 +149,11 @@ fn get_cipher_registry(
148149 } )
149150}
150151
151- pub ( crate ) fn get_cipher (
152+ pub ( crate ) fn get_cipher < ' a > (
152153 py : pyo3:: Python < ' _ > ,
153154 algorithm : & pyo3:: PyAny ,
154155 mode_cls : & pyo3:: PyAny ,
155- ) -> CryptographyResult < Option < openssl:: symm :: Cipher > > {
156+ ) -> CryptographyResult < Option < & ' a openssl:: cipher :: CipherRef > > {
156157 let registry = get_cipher_registry ( py) ?;
157158
158159 let key_size = algorithm
0 commit comments