@@ -51,14 +51,14 @@ use crate::error::ErrorStack;
51
51
use crate :: pkey_ctx:: PkeyCtx ;
52
52
use crate :: rsa:: Rsa ;
53
53
use crate :: symm:: Cipher ;
54
- use crate :: util:: { invoke_passwd_cb, CallbackState } ;
54
+ use crate :: util:: { c_str , invoke_passwd_cb, CallbackState } ;
55
55
use crate :: { cvt, cvt_p} ;
56
56
use cfg_if:: cfg_if;
57
57
use foreign_types:: { ForeignType , ForeignTypeRef } ;
58
58
use libc:: { c_int, c_long} ;
59
59
use openssl_macros:: corresponds;
60
60
use std:: convert:: { TryFrom , TryInto } ;
61
- use std:: ffi:: CString ;
61
+ use std:: ffi:: { CStr , CString } ;
62
62
use std:: fmt;
63
63
#[ cfg( all( not( any( boringssl, awslc) ) , ossl110) ) ]
64
64
use std:: mem;
@@ -154,6 +154,41 @@ impl TryFrom<Id> for &'static str {
154
154
}
155
155
}
156
156
157
+ impl TryFrom < Id > for & ' static CStr {
158
+ type Error = ( ) ;
159
+ fn try_from ( id : Id ) -> Result < Self , Self :: Error > {
160
+ match id {
161
+ Id :: RSA => Ok ( c_str ( b"RSA\0 " ) ) ,
162
+ #[ cfg( any( ossl111, libressl310, boringssl, awslc) ) ]
163
+ Id :: RSA_PSS => Ok ( c_str ( b"RSA-PSS\0 " ) ) ,
164
+ #[ cfg( not( boringssl) ) ]
165
+ Id :: HMAC => Ok ( c_str ( b"HMAC\0 " ) ) ,
166
+ #[ cfg( not( any( boringssl, awslc) ) ) ]
167
+ Id :: CMAC => Ok ( c_str ( b"CMAC\0 " ) ) ,
168
+ Id :: DSA => Ok ( c_str ( b"DSA\0 " ) ) ,
169
+ Id :: DH => Ok ( c_str ( b"DH\0 " ) ) ,
170
+ #[ cfg( ossl110) ]
171
+ Id :: DHX => Ok ( c_str ( b"DHX\0 " ) ) ,
172
+ Id :: EC => Ok ( c_str ( b"EC\0 " ) ) ,
173
+ #[ cfg( ossl111) ]
174
+ Id :: SM2 => Ok ( c_str ( b"SM2\0 " ) ) ,
175
+ #[ cfg( any( ossl110, boringssl, libressl360, awslc) ) ]
176
+ Id :: HKDF => Ok ( c_str ( b"HKDF\0 " ) ) ,
177
+ #[ cfg( any( ossl111, boringssl, libressl370, awslc) ) ]
178
+ Id :: ED25519 => Ok ( c_str ( b"Ed25519\0 " ) ) ,
179
+ #[ cfg( ossl111) ]
180
+ Id :: ED448 => Ok ( c_str ( b"Ed448\0 " ) ) ,
181
+ #[ cfg( any( ossl111, boringssl, libressl370, awslc) ) ]
182
+ Id :: X25519 => Ok ( c_str ( b"X25519\0 " ) ) ,
183
+ #[ cfg( ossl111) ]
184
+ Id :: X448 => Ok ( c_str ( b"X448\0 " ) ) ,
185
+ #[ cfg( ossl111) ]
186
+ Id :: POLY1305 => Ok ( c_str ( b"POLY1305\0 " ) ) ,
187
+ _ => Err ( ( ) ) ,
188
+ }
189
+ }
190
+ }
191
+
157
192
/// A trait indicating that a key has parameters.
158
193
pub unsafe trait HasParams { }
159
194
0 commit comments