diff options
author | Dr. Stephen Henson <steve@openssl.org> | 1999-12-26 19:20:03 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 1999-12-26 19:20:03 +0000 |
commit | e6f3c5850e64145eaecdcf44737e873530f7d37b (patch) | |
tree | d83cd535b57c79bf22474aa401a512c6550c34b6 /crypto/x509/x_all.c | |
parent | b96eb06f7907da2fef89c0c7b89ce4dedc593ecc (diff) | |
download | openssl-e6f3c5850e64145eaecdcf44737e873530f7d37b.tar.gz |
New {i2d,d2i}_PrivateKey_{bio, fp} functions.
Diffstat (limited to 'crypto/x509/x_all.c')
-rw-r--r-- | crypto/x509/x_all.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/crypto/x509/x_all.c b/crypto/x509/x_all.c index 887999f89d..e1d70dfdfe 100644 --- a/crypto/x509/x_all.c +++ b/crypto/x509/x_all.c @@ -481,6 +481,24 @@ int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key) return ret; } +int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey) + { + return(ASN1_i2d_fp(i2d_PrivateKey,fp,(unsigned char *)pkey)); + } + +EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, int type, EVP_PKEY **a) +{ + BIO *bp; + EVP_PKEY *ret; + if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { + ASN1err(ASN1_F_D2I_PRIVATEKEY_FP,ERR_R_MALLOC_FAILURE); + return NULL; + } + ret = d2i_PrivateKey_bio(bp, type, a); + BIO_free(bp); + return ret; +} + #endif PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, @@ -507,3 +525,56 @@ int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) PKCS8_PRIV_KEY_INFO_free(p8inf); return ret; } + +int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey) + { + return(ASN1_i2d_bio(i2d_PrivateKey,bp,(unsigned char *)pkey)); + } + +EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, int type, EVP_PKEY **a) + { + EVP_PKEY *ret; + + if ((a == NULL) || (*a == NULL)) + { + if ((ret=EVP_PKEY_new()) == NULL) + { + ASN1err(ASN1_F_D2I_PRIVATEKEY_BIO,ERR_R_EVP_LIB); + return(NULL); + } + } + else ret= *a; + + ret->save_type=type; + ret->type=EVP_PKEY_type(type); + switch (ret->type) + { +#ifndef NO_RSA + case EVP_PKEY_RSA: + if ((ret->pkey.rsa=d2i_RSAPrivateKey_bio(bp,NULL)) == NULL) + { + ASN1err(ASN1_F_D2I_PRIVATEKEY_BIO,ERR_R_ASN1_LIB); + goto err; + } + break; +#endif +#ifndef NO_DSA + case EVP_PKEY_DSA: + if ((ret->pkey.dsa=d2i_DSAPrivateKey_bio(bp, NULL)) == NULL) + { + ASN1err(ASN1_F_D2I_PRIVATEKEY_BIO,ERR_R_ASN1_LIB); + goto err; + } + break; +#endif + default: + ASN1err(ASN1_F_D2I_PRIVATEKEY_BIO,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); + goto err; + /* break; */ + } + if (a != NULL) (*a)=ret; + return(ret); +err: + if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); + return(NULL); + } |