define and use d2i_RSAPublicKey
This commit is contained in:
@@ -559,3 +559,38 @@ i2d_RSAPublicKey(RSA *rsa, unsigned char **pp)
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
RSA *
|
||||
d2i_RSAPublicKey(RSA *rsa, const unsigned char **pp, size_t len)
|
||||
{
|
||||
RSAPublicKey data;
|
||||
RSA *k = rsa;
|
||||
size_t size;
|
||||
int ret;
|
||||
|
||||
ret = decode_RSAPublicKey(*pp, len, &data, &size);
|
||||
if (ret)
|
||||
return NULL;
|
||||
|
||||
*pp += size;
|
||||
|
||||
if (k == NULL) {
|
||||
k = RSA_new();
|
||||
if (k == NULL) {
|
||||
free_RSAPublicKey(&data);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
k->n = heim_int2BN(&data.modulus);
|
||||
k->e = heim_int2BN(&data.publicExponent);
|
||||
|
||||
free_RSAPublicKey(&data);
|
||||
|
||||
if (k->n == NULL || k->e == NULL) {
|
||||
RSA_free(k);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return k;
|
||||
}
|
||||
|
@@ -64,6 +64,7 @@
|
||||
#define d2i_RSAPrivateKey hc_d2i_RSAPrivateKey
|
||||
#define i2d_RSAPrivateKey hc_i2d_RSAPrivateKey
|
||||
#define i2d_RSAPublicKey hc_i2d_RSAPublicKey
|
||||
#define d2i_RSAPublicKey hc_d2i_RSAPublicKey
|
||||
|
||||
/*
|
||||
*
|
||||
@@ -173,5 +174,6 @@ RSA * d2i_RSAPrivateKey(RSA *, const unsigned char **, size_t);
|
||||
int i2d_RSAPrivateKey(RSA *, unsigned char **);
|
||||
|
||||
int i2d_RSAPublicKey(RSA *, unsigned char **);
|
||||
RSA * d2i_RSAPublicKey(RSA *, const unsigned char **, size_t);
|
||||
|
||||
#endif /* _HEIM_RSA_H */
|
||||
|
Reference in New Issue
Block a user