@@ -32,24 +32,24 @@ var (
3232 SHA512_Method Method = C .X_EVP_sha512 ()
3333)
3434
35- type KeyType int
36-
35+ // Constants for the various key types.
36+ // Mapping of name -> NID taken from openssl/evp.h
3737const (
38- KeyTypeNone KeyType = C . EVP_PKEY_NONE
39- KeyTypeRSA KeyType = C . EVP_PKEY_RSA
40- KeyTypeRSA2 KeyType = C . EVP_PKEY_RSA2
41- KeyTypeDSA KeyType = C . EVP_PKEY_DSA
42- KeyTypeDSA1 KeyType = C . EVP_PKEY_DSA1
43- KeyTypeDSA2 KeyType = C . EVP_PKEY_DSA2
44- KeyTypeDSA3 KeyType = C . EVP_PKEY_DSA3
45- KeyTypeDSA4 KeyType = C . EVP_PKEY_DSA4
46- KeyTypeDH KeyType = C . EVP_PKEY_DH
47- KeyTypeDHX KeyType = C . EVP_PKEY_DHX
48- KeyTypeEC KeyType = C . EVP_PKEY_EC
49- KeyTypeHMAC KeyType = C . EVP_PKEY_HMAC
50- KeyTypeCMAC KeyType = C . EVP_PKEY_CMAC
51- KeyTypeTLS1PRF KeyType = C . EVP_PKEY_TLS1_PRF
52- KeyTypeHKDF KeyType = C . EVP_PKEY_HKDF
38+ KeyTypeNone = NID_undef
39+ KeyTypeRSA = NID_rsaEncryption
40+ KeyTypeRSA2 = NID_rsa
41+ KeyTypeDSA = NID_dsa
42+ KeyTypeDSA1 = NID_dsa_2
43+ KeyTypeDSA2 = NID_dsaWithSHA
44+ KeyTypeDSA3 = NID_dsaWithSHA1
45+ KeyTypeDSA4 = NID_dsaWithSHA1_2
46+ KeyTypeDH = NID_dhKeyAgreement
47+ KeyTypeDHX = NID_dhpublicnumber
48+ KeyTypeEC = NID_x9_62_id_ecPublicKey
49+ KeyTypeHMAC = NID_hmac
50+ KeyTypeCMAC = NID_cmac
51+ KeyTypeTLS1PRF = NID_tls1_prf
52+ KeyTypeHKDF = NID_hdkf
5353)
5454
5555type PublicKey interface {
@@ -66,7 +66,7 @@ type PublicKey interface {
6666
6767 // KeyType returns an identifier for what kind of key is represented by this
6868 // object.
69- KeyType () KeyType
69+ KeyType () NID
7070
7171 // BaseType returns an identifier for what kind of key is represented
7272 // by this object.
@@ -75,7 +75,7 @@ type PublicKey interface {
7575 //
7676 // For example, a key with a `KeyType() == KeyTypeRSA` and a key with a
7777 // `KeyType() == KeyTypeRSA2` would both have `BaseType() == KeyTypeRSA`.
78- BaseType () KeyType
78+ BaseType () NID
7979
8080 evpPKey () * C.EVP_PKEY
8181}
@@ -101,12 +101,12 @@ type pKey struct {
101101
102102func (key * pKey ) evpPKey () * C.EVP_PKEY { return key .key }
103103
104- func (key * pKey ) KeyType () KeyType {
105- return KeyType (C .EVP_PKEY_id (key .key ))
104+ func (key * pKey ) KeyType () NID {
105+ return NID (C .EVP_PKEY_id (key .key ))
106106}
107107
108- func (key * pKey ) BaseType () KeyType {
109- return KeyType (C .EVP_PKEY_base_id (key .key ))
108+ func (key * pKey ) BaseType () NID {
109+ return NID (C .EVP_PKEY_base_id (key .key ))
110110}
111111
112112func (key * pKey ) SignPKCS1v15 (method Method , data []byte ) ([]byte , error ) {
@@ -162,7 +162,7 @@ func (key *pKey) MarshalPKCS1PrivateKeyPEM() (pem_block []byte,
162162 // PEM_write_bio_PrivateKey_traditional will use the key-specific PKCS1
163163 // format if one is available for that key type, otherwise it will encode
164164 // to a PKCS8 key.
165- if int (C .PEM_write_bio_PrivateKey_traditional (bio , key .key , nil , nil ,
165+ if int (C .X_PEM_write_bio_PrivateKey_traditional (bio , key .key , nil , nil ,
166166 C .int (0 ), nil , nil )) != 1 {
167167 return nil , errors .New ("failed dumping private key" )
168168 }
0 commit comments