Unwind M_ASN1_* macros for primitive types.

At one point in the SSLeay days, all the ASN1_STRING typedefs were
separate structs (but only in debug builds) and the M_ASN1_* macros
included type casts to handle this.

This is long gone, but we still have the M_ASN1_* macros. Remove the
casts and switch code within the library to call the macros. Some
subtleties:

- The "MSTRING" types (what OpenSSL calls its built-in CHOICEs
  containing some set of string types) are weird because the M_FOO_new()
  macro and the tasn_new.c FOO_new() function behave differently. I've
  split those into a separate CL.

- ASN1_STRING_type, etc., call into the macro, which accesses the field
  directly. This CL inverts the dependency.

- ASN1_INTEGER_new and ASN1_INTEGER_free, etc., are generated via
  IMPLEMENT_ASN1_STRING_FUNCTIONS in tasn_typ.c. I've pointed
  M_ASN1_INTEGER_new and M_ASN1_INTEGER_free to these fields. (The free
  function is a no-op, but consistent.)

- The other macros like M_ASN1_BIT_STRING_dup largely do not have
  corresponding functions. I've aligned with OpenSSL in just using the
  generic ASN1_STRING_dup function. But some others, like
  M_ASN1_OCTET_STRING_dup have a corresponding ASN1_OCTET_STRING_dup
  function. OpenSSL retained these, so I have too.

Update-Note: Some external code uses the M_ASN1_* macros. This should
remain compatible, but some type errors may have gotten through
unnoticed. This CL restores type-checking.

Change-Id: I8656abc7d0f179192e05a852c97483c021ad9b20
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/44045
Reviewed-by: Adam Langley <agl@google.com>
chromium-5359
David Benjamin 4 years ago committed by Adam Langley
parent 7a26f97c9f
commit c6ffcde8cd
  1. 6
      crypto/asn1/a_bitstr.c
  2. 4
      crypto/asn1/a_enum.c
  3. 10
      crypto/asn1/a_int.c
  4. 6
      crypto/asn1/a_octet.c
  5. 4
      crypto/asn1/a_utctm.c
  6. 6
      crypto/asn1/asn1_lib.c
  7. 6
      crypto/asn1/asn1_test.cc
  8. 2
      crypto/x509/x509_cmp.c
  9. 2
      crypto/x509/x509_r2x.c
  10. 8
      crypto/x509/x509_set.c
  11. 6
      crypto/x509/x509cset.c
  12. 4
      crypto/x509/x_pkey.c
  13. 6
      crypto/x509v3/v3_akey.c
  14. 6
      crypto/x509v3/v3_alt.c
  15. 6
      crypto/x509v3/v3_bitst.c
  16. 8
      crypto/x509v3/v3_conf.c
  17. 4
      crypto/x509v3/v3_cpols.c
  18. 7
      crypto/x509v3/v3_ia5.c
  19. 2
      crypto/x509v3/v3_prn.c
  20. 10
      crypto/x509v3/v3_skey.c
  21. 133
      include/openssl/asn1.h

@ -67,7 +67,7 @@
int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len) int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
{ {
return M_ASN1_BIT_STRING_set(x, d, len); return ASN1_STRING_set(x, d, len);
} }
int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *a, unsigned char **pp) int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *a, unsigned char **pp)
@ -146,7 +146,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
} }
if ((a == NULL) || ((*a) == NULL)) { if ((a == NULL) || ((*a) == NULL)) {
if ((ret = M_ASN1_BIT_STRING_new()) == NULL) if ((ret = ASN1_BIT_STRING_new()) == NULL)
return (NULL); return (NULL);
} else } else
ret = (*a); ret = (*a);
@ -188,7 +188,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
return (ret); return (ret);
err: err:
if ((ret != NULL) && ((a == NULL) || (*a != ret))) if ((ret != NULL) && ((a == NULL) || (*a != ret)))
M_ASN1_BIT_STRING_free(ret); ASN1_BIT_STRING_free(ret);
return (NULL); return (NULL);
} }

@ -153,7 +153,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai)
int len, j; int len, j;
if (ai == NULL) if (ai == NULL)
ret = M_ASN1_ENUMERATED_new(); ret = ASN1_ENUMERATED_new();
else else
ret = ai; ret = ai;
if (ret == NULL) { if (ret == NULL) {
@ -179,7 +179,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai)
return (ret); return (ret);
err: err:
if (ret != ai) if (ret != ai)
M_ASN1_ENUMERATED_free(ret); ASN1_ENUMERATED_free(ret);
return (NULL); return (NULL);
} }

@ -67,7 +67,7 @@
ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x) ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x)
{ {
return M_ASN1_INTEGER_dup(x); return ASN1_STRING_dup(x);
} }
int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
@ -206,7 +206,7 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
} }
if ((a == NULL) || ((*a) == NULL)) { if ((a == NULL) || ((*a) == NULL)) {
if ((ret = M_ASN1_INTEGER_new()) == NULL) if ((ret = ASN1_INTEGER_new()) == NULL)
return (NULL); return (NULL);
ret->type = V_ASN1_INTEGER; ret->type = V_ASN1_INTEGER;
} else } else
@ -282,7 +282,7 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
err: err:
OPENSSL_PUT_ERROR(ASN1, i); OPENSSL_PUT_ERROR(ASN1, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret))) if ((ret != NULL) && ((a == NULL) || (*a != ret)))
M_ASN1_INTEGER_free(ret); ASN1_INTEGER_free(ret);
return (NULL); return (NULL);
} }
@ -374,7 +374,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
int len, j; int len, j;
if (ai == NULL) if (ai == NULL)
ret = M_ASN1_INTEGER_new(); ret = ASN1_INTEGER_new();
else else
ret = ai; ret = ai;
if (ret == NULL) { if (ret == NULL) {
@ -404,7 +404,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
return (ret); return (ret);
err: err:
if (ret != ai) if (ret != ai)
M_ASN1_INTEGER_free(ret); ASN1_INTEGER_free(ret);
return (NULL); return (NULL);
} }

@ -61,17 +61,17 @@
ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x) ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x)
{ {
return M_ASN1_OCTET_STRING_dup(x); return ASN1_STRING_dup(x);
} }
int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
const ASN1_OCTET_STRING *b) const ASN1_OCTET_STRING *b)
{ {
return M_ASN1_OCTET_STRING_cmp(a, b); return ASN1_STRING_cmp(a, b);
} }
int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d,
int len) int len)
{ {
return M_ASN1_OCTET_STRING_set(x, d, len); return ASN1_STRING_set(x, d, len);
} }

@ -197,7 +197,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
if (s == NULL) { if (s == NULL) {
free_s = 1; free_s = 1;
s = M_ASN1_UTCTIME_new(); s = ASN1_UTCTIME_new();
} }
if (s == NULL) if (s == NULL)
goto err; goto err;
@ -234,7 +234,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
return (s); return (s);
err: err:
if (free_s && s) if (free_s && s)
M_ASN1_UTCTIME_free(s); ASN1_UTCTIME_free(s);
return NULL; return NULL;
} }

@ -422,17 +422,17 @@ int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
int ASN1_STRING_length(const ASN1_STRING *x) int ASN1_STRING_length(const ASN1_STRING *x)
{ {
return M_ASN1_STRING_length(x); return x->length;
} }
int ASN1_STRING_type(const ASN1_STRING *x) int ASN1_STRING_type(const ASN1_STRING *x)
{ {
return M_ASN1_STRING_type(x); return x->type;
} }
unsigned char *ASN1_STRING_data(ASN1_STRING *x) unsigned char *ASN1_STRING_data(ASN1_STRING *x)
{ {
return M_ASN1_STRING_data(x); return x->data;
} }
const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x) const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x)

@ -70,9 +70,9 @@ TEST(ASN1Test, LargeTags) {
} }
TEST(ASN1Test, IntegerSetting) { TEST(ASN1Test, IntegerSetting) {
bssl::UniquePtr<ASN1_INTEGER> by_bn(M_ASN1_INTEGER_new()); bssl::UniquePtr<ASN1_INTEGER> by_bn(ASN1_INTEGER_new());
bssl::UniquePtr<ASN1_INTEGER> by_long(M_ASN1_INTEGER_new()); bssl::UniquePtr<ASN1_INTEGER> by_long(ASN1_INTEGER_new());
bssl::UniquePtr<ASN1_INTEGER> by_uint64(M_ASN1_INTEGER_new()); bssl::UniquePtr<ASN1_INTEGER> by_uint64(ASN1_INTEGER_new());
bssl::UniquePtr<BIGNUM> bn(BN_new()); bssl::UniquePtr<BIGNUM> bn(BN_new());
const std::vector<int64_t> kValues = { const std::vector<int64_t> kValues = {

@ -77,7 +77,7 @@ int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b)
ai = a->cert_info; ai = a->cert_info;
bi = b->cert_info; bi = b->cert_info;
i = M_ASN1_INTEGER_cmp(ai->serialNumber, bi->serialNumber); i = ASN1_INTEGER_cmp(ai->serialNumber, bi->serialNumber);
if (i) if (i)
return (i); return (i);
return (X509_NAME_cmp(ai->issuer, bi->issuer)); return (X509_NAME_cmp(ai->issuer, bi->issuer));

@ -79,7 +79,7 @@ X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey)
xi = ret->cert_info; xi = ret->cert_info;
if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0) { if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0) {
if ((xi->version = M_ASN1_INTEGER_new()) == NULL) if ((xi->version = ASN1_INTEGER_new()) == NULL)
goto err; goto err;
if (!ASN1_INTEGER_set(xi->version, 2)) if (!ASN1_INTEGER_set(xi->version, 2))
goto err; goto err;

@ -75,12 +75,12 @@ int X509_set_version(X509 *x, long version)
if (x == NULL) if (x == NULL)
return (0); return (0);
if (version == 0) { if (version == 0) {
M_ASN1_INTEGER_free(x->cert_info->version); ASN1_INTEGER_free(x->cert_info->version);
x->cert_info->version = NULL; x->cert_info->version = NULL;
return (1); return (1);
} }
if (x->cert_info->version == NULL) { if (x->cert_info->version == NULL) {
if ((x->cert_info->version = M_ASN1_INTEGER_new()) == NULL) if ((x->cert_info->version = ASN1_INTEGER_new()) == NULL)
return (0); return (0);
} }
return (ASN1_INTEGER_set(x->cert_info->version, version)); return (ASN1_INTEGER_set(x->cert_info->version, version));
@ -94,9 +94,9 @@ int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial)
return (0); return (0);
in = x->cert_info->serialNumber; in = x->cert_info->serialNumber;
if (in != serial) { if (in != serial) {
in = M_ASN1_INTEGER_dup(serial); in = ASN1_INTEGER_dup(serial);
if (in != NULL) { if (in != NULL) {
M_ASN1_INTEGER_free(x->cert_info->serialNumber); ASN1_INTEGER_free(x->cert_info->serialNumber);
x->cert_info->serialNumber = in; x->cert_info->serialNumber = in;
} }
} }

@ -66,7 +66,7 @@ int X509_CRL_set_version(X509_CRL *x, long version)
if (x == NULL) if (x == NULL)
return (0); return (0);
if (x->crl->version == NULL) { if (x->crl->version == NULL) {
if ((x->crl->version = M_ASN1_INTEGER_new()) == NULL) if ((x->crl->version = ASN1_INTEGER_new()) == NULL)
return (0); return (0);
} }
return (ASN1_INTEGER_set(x->crl->version, version)); return (ASN1_INTEGER_set(x->crl->version, version));
@ -224,9 +224,9 @@ int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial)
return (0); return (0);
in = x->serialNumber; in = x->serialNumber;
if (in != serial) { if (in != serial) {
in = M_ASN1_INTEGER_dup(serial); in = ASN1_INTEGER_dup(serial);
if (in != NULL) { if (in != NULL) {
M_ASN1_INTEGER_free(x->serialNumber); ASN1_INTEGER_free(x->serialNumber);
x->serialNumber = in; x->serialNumber = in;
} }
} }

@ -78,7 +78,7 @@ X509_PKEY *X509_PKEY_new(void)
ret->enc_algor = X509_ALGOR_new(); ret->enc_algor = X509_ALGOR_new();
if (ret->enc_algor == NULL) if (ret->enc_algor == NULL)
goto err; goto err;
ret->enc_pkey = M_ASN1_OCTET_STRING_new(); ret->enc_pkey = ASN1_OCTET_STRING_new();
if (ret->enc_pkey == NULL) if (ret->enc_pkey == NULL)
goto err; goto err;
return ret; return ret;
@ -97,7 +97,7 @@ void X509_PKEY_free(X509_PKEY *x)
if (x->enc_algor != NULL) if (x->enc_algor != NULL)
X509_ALGOR_free(x->enc_algor); X509_ALGOR_free(x->enc_algor);
if (x->enc_pkey != NULL) if (x->enc_pkey != NULL)
M_ASN1_OCTET_STRING_free(x->enc_pkey); ASN1_OCTET_STRING_free(x->enc_pkey);
if (x->dec_pkey != NULL) if (x->dec_pkey != NULL)
EVP_PKEY_free(x->dec_pkey); EVP_PKEY_free(x->dec_pkey);
if ((x->key_data != NULL) && (x->key_free)) if ((x->key_data != NULL) && (x->key_free))

@ -172,7 +172,7 @@ static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
if ((issuer && !ikeyid) || (issuer == 2)) { if ((issuer && !ikeyid) || (issuer == 2)) {
isname = X509_NAME_dup(X509_get_issuer_name(cert)); isname = X509_NAME_dup(X509_get_issuer_name(cert));
serial = M_ASN1_INTEGER_dup(X509_get_serialNumber(cert)); serial = ASN1_INTEGER_dup(X509_get_serialNumber(cert));
if (!isname || !serial) { if (!isname || !serial) {
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS); OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
goto err; goto err;
@ -201,7 +201,7 @@ static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
err: err:
X509_NAME_free(isname); X509_NAME_free(isname);
M_ASN1_INTEGER_free(serial); ASN1_INTEGER_free(serial);
M_ASN1_OCTET_STRING_free(ikeyid); ASN1_OCTET_STRING_free(ikeyid);
return NULL; return NULL;
} }

@ -386,7 +386,7 @@ static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
while ((i = X509_NAME_get_index_by_NID(nm, while ((i = X509_NAME_get_index_by_NID(nm,
NID_pkcs9_emailAddress, i)) >= 0) { NID_pkcs9_emailAddress, i)) >= 0) {
ne = X509_NAME_get_entry(nm, i); ne = X509_NAME_get_entry(nm, i);
email = M_ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne)); email = ASN1_STRING_dup(X509_NAME_ENTRY_get_data(ne));
if (move_p) { if (move_p) {
X509_NAME_delete_entry(nm, i); X509_NAME_delete_entry(nm, i);
X509_NAME_ENTRY_free(ne); X509_NAME_ENTRY_free(ne);
@ -410,7 +410,7 @@ static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
err: err:
GENERAL_NAME_free(gen); GENERAL_NAME_free(gen);
M_ASN1_IA5STRING_free(email); ASN1_IA5STRING_free(email);
return 0; return 0;
} }
@ -517,7 +517,7 @@ GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out,
} }
if (is_string) { if (is_string) {
if (!(gen->d.ia5 = M_ASN1_IA5STRING_new()) || if (!(gen->d.ia5 = ASN1_IA5STRING_new()) ||
!ASN1_STRING_set(gen->d.ia5, (unsigned char *)value, !ASN1_STRING_set(gen->d.ia5, (unsigned char *)value,
strlen(value))) { strlen(value))) {
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE); OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);

@ -113,7 +113,7 @@ ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
ASN1_BIT_STRING *bs; ASN1_BIT_STRING *bs;
size_t i; size_t i;
const BIT_STRING_BITNAME *bnam; const BIT_STRING_BITNAME *bnam;
if (!(bs = M_ASN1_BIT_STRING_new())) { if (!(bs = ASN1_BIT_STRING_new())) {
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE); OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
@ -124,7 +124,7 @@ ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
!strcmp(bnam->lname, val->name)) { !strcmp(bnam->lname, val->name)) {
if (!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) { if (!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) {
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE); OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
M_ASN1_BIT_STRING_free(bs); ASN1_BIT_STRING_free(bs);
return NULL; return NULL;
} }
break; break;
@ -133,7 +133,7 @@ ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
if (!bnam->lname) { if (!bnam->lname) {
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT); OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
X509V3_conf_err(val); X509V3_conf_err(val);
M_ASN1_BIT_STRING_free(bs); ASN1_BIT_STRING_free(bs);
return NULL; return NULL;
} }
} }

@ -199,7 +199,7 @@ static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method,
p = ext_der; p = ext_der;
method->i2d(ext_struc, &p); method->i2d(ext_struc, &p);
} }
if (!(ext_oct = M_ASN1_OCTET_STRING_new())) if (!(ext_oct = ASN1_OCTET_STRING_new()))
goto merr; goto merr;
ext_oct->data = ext_der; ext_oct->data = ext_der;
ext_oct->length = ext_len; ext_oct->length = ext_len;
@ -207,7 +207,7 @@ static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method,
ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct); ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);
if (!ext) if (!ext)
goto merr; goto merr;
M_ASN1_OCTET_STRING_free(ext_oct); ASN1_OCTET_STRING_free(ext_oct);
return ext; return ext;
@ -289,7 +289,7 @@ static X509_EXTENSION *v3_generic_extension(const char *ext, const char *value,
goto err; goto err;
} }
if (!(oct = M_ASN1_OCTET_STRING_new())) { if (!(oct = ASN1_OCTET_STRING_new())) {
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE); OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
@ -302,7 +302,7 @@ static X509_EXTENSION *v3_generic_extension(const char *ext, const char *value,
err: err:
ASN1_OBJECT_free(obj); ASN1_OBJECT_free(obj);
M_ASN1_OCTET_STRING_free(oct); ASN1_OCTET_STRING_free(oct);
if (ext_der) if (ext_der)
OPENSSL_free(ext_der); OPENSSL_free(ext_der);
return extension; return extension;

@ -245,7 +245,7 @@ static POLICYINFO *policy_section(X509V3_CTX *ctx,
OPENSSL_PUT_ERROR(X509V3, ERR_R_INTERNAL_ERROR); OPENSSL_PUT_ERROR(X509V3, ERR_R_INTERNAL_ERROR);
goto err; goto err;
} }
qual->d.cpsuri = M_ASN1_IA5STRING_new(); qual->d.cpsuri = ASN1_IA5STRING_new();
if (qual->d.cpsuri == NULL) { if (qual->d.cpsuri == NULL) {
goto err; goto err;
} }
@ -319,7 +319,7 @@ static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
for (i = 0; i < sk_CONF_VALUE_num(unot); i++) { for (i = 0; i < sk_CONF_VALUE_num(unot); i++) {
cnf = sk_CONF_VALUE_value(unot, i); cnf = sk_CONF_VALUE_value(unot, i);
if (!strcmp(cnf->name, "explicitText")) { if (!strcmp(cnf->name, "explicitText")) {
not->exptext = M_ASN1_VISIBLESTRING_new(); not->exptext = ASN1_VISIBLESTRING_new();
if (not->exptext == NULL) if (not->exptext == NULL)
goto merr; goto merr;
if (!ASN1_STRING_set(not->exptext, cnf->value, if (!ASN1_STRING_set(not->exptext, cnf->value,

@ -108,11 +108,10 @@ static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_ARGUMENT); OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_ARGUMENT);
return NULL; return NULL;
} }
if (!(ia5 = M_ASN1_IA5STRING_new())) if (!(ia5 = ASN1_IA5STRING_new()))
goto err; goto err;
if (!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char *)str, if (!ASN1_STRING_set(ia5, str, strlen(str))) {
strlen(str))) { ASN1_IA5STRING_free(ia5);
M_ASN1_IA5STRING_free(ia5);
goto err; goto err;
} }
return ia5; return ia5;

@ -183,7 +183,7 @@ int X509V3_extensions_print(BIO *bp, const char *title,
return 0; return 0;
if (!X509V3_EXT_print(bp, ex, flag, indent + 4)) { if (!X509V3_EXT_print(bp, ex, flag, indent + 4)) {
BIO_printf(bp, "%*s", indent + 4, ""); BIO_printf(bp, "%*s", indent + 4, "");
M_ASN1_OCTET_STRING_print(bp, ex->value); ASN1_STRING_print(bp, ex->value);
} }
if (BIO_write(bp, "\n", 1) <= 0) if (BIO_write(bp, "\n", 1) <= 0)
return 0; return 0;

@ -88,13 +88,13 @@ ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
ASN1_OCTET_STRING *oct; ASN1_OCTET_STRING *oct;
long length; long length;
if (!(oct = M_ASN1_OCTET_STRING_new())) { if (!(oct = ASN1_OCTET_STRING_new())) {
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE); OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
if (!(oct->data = x509v3_hex_to_bytes(str, &length))) { if (!(oct->data = x509v3_hex_to_bytes(str, &length))) {
M_ASN1_OCTET_STRING_free(oct); ASN1_OCTET_STRING_free(oct);
return NULL; return NULL;
} }
@ -115,7 +115,7 @@ static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
if (strcmp(str, "hash")) if (strcmp(str, "hash"))
return s2i_ASN1_OCTET_STRING(method, ctx, str); return s2i_ASN1_OCTET_STRING(method, ctx, str);
if (!(oct = M_ASN1_OCTET_STRING_new())) { if (!(oct = ASN1_OCTET_STRING_new())) {
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE); OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
@ -142,7 +142,7 @@ static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
(pk->data, pk->length, pkey_dig, &diglen, EVP_sha1(), NULL)) (pk->data, pk->length, pkey_dig, &diglen, EVP_sha1(), NULL))
goto err; goto err;
if (!M_ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) { if (!ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE); OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
@ -150,6 +150,6 @@ static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
return oct; return oct;
err: err:
M_ASN1_OCTET_STRING_free(oct); ASN1_OCTET_STRING_free(oct);
return NULL; return NULL;
} }

@ -460,46 +460,53 @@ typedef struct BIT_STRING_BITNAME_st {
const char *sname; const char *sname;
} BIT_STRING_BITNAME; } BIT_STRING_BITNAME;
// M_ASN1_* are legacy aliases for various |ASN1_STRING| functions. Use the
#define M_ASN1_STRING_length(x) ((x)->length) // functions themselves.
#define M_ASN1_STRING_type(x) ((x)->type) #define M_ASN1_STRING_length(x) ASN1_STRING_length(x)
#define M_ASN1_STRING_data(x) ((x)->data) #define M_ASN1_STRING_type(x) ASN1_STRING_type(x)
#define M_ASN1_STRING_data(x) ASN1_STRING_data(x)
// Macros for string operations #define M_ASN1_BIT_STRING_new() ASN1_BIT_STRING_new()
#define M_ASN1_BIT_STRING_new() \ #define M_ASN1_BIT_STRING_free(a) ASN1_BIT_STRING_free(a)
(ASN1_BIT_STRING *)ASN1_STRING_type_new(V_ASN1_BIT_STRING) #define M_ASN1_BIT_STRING_dup(a) ASN1_STRING_dup(a)
#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) #define M_ASN1_BIT_STRING_cmp(a, b) ASN1_STRING_cmp(a, b)
#define M_ASN1_BIT_STRING_dup(a) \ #define M_ASN1_BIT_STRING_set(a, b, c) ASN1_BIT_STRING_set(a, b, c)
(ASN1_BIT_STRING *)ASN1_STRING_dup((const ASN1_STRING *)a) #define M_ASN1_INTEGER_new() ASN1_INTEGER_new()
#define M_ASN1_BIT_STRING_cmp(a, b) \ #define M_ASN1_INTEGER_free(a) ASN1_INTEGER_free(a)
ASN1_STRING_cmp((const ASN1_STRING *)a, (const ASN1_STRING *)b) #define M_ASN1_INTEGER_dup(a) ASN1_INTEGER_dup(a)
#define M_ASN1_BIT_STRING_set(a, b, c) ASN1_STRING_set((ASN1_STRING *)a, b, c) #define M_ASN1_INTEGER_cmp(a, b) ASN1_INTEGER_cmp(a, b)
#define M_ASN1_ENUMERATED_new() ASN1_ENUMERATED_new()
#define M_ASN1_INTEGER_new() \ #define M_ASN1_ENUMERATED_free(a) ASN1_ENUMERATED_free(a)
(ASN1_INTEGER *)ASN1_STRING_type_new(V_ASN1_INTEGER) #define M_ASN1_ENUMERATED_dup(a) ASN1_STRING_dup(a)
#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a) #define M_ASN1_ENUMERATED_cmp(a, b) ASN1_STRING_cmp(a, b)
#define M_ASN1_INTEGER_dup(a) \ #define M_ASN1_OCTET_STRING_new() ASN1_OCTET_STRING_new()
(ASN1_INTEGER *)ASN1_STRING_dup((const ASN1_STRING *)a) #define M_ASN1_OCTET_STRING_free(a) ASN1_OCTET_STRING_free()
#define M_ASN1_INTEGER_cmp(a, b) \ #define M_ASN1_OCTET_STRING_dup(a) ASN1_OCTET_STRING_dup(a)
ASN1_STRING_cmp((const ASN1_STRING *)a, (const ASN1_STRING *)b) #define M_ASN1_OCTET_STRING_cmp(a, b) ASN1_OCTET_STRING_cmp(a, b)
#define M_ASN1_OCTET_STRING_set(a, b, c) ASN1_OCTET_STRING_set(a, b, c)
#define M_ASN1_ENUMERATED_new() \ #define M_ASN1_OCTET_STRING_print(a, b) ASN1_STRING_print(a, b)
(ASN1_ENUMERATED *)ASN1_STRING_type_new(V_ASN1_ENUMERATED) #define M_ASN1_PRINTABLESTRING_new() ASN1_PRINTABLESTRING_new()
#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a) #define M_ASN1_PRINTABLESTRING_free(a) ASN1_PRINTABLESTRING_free(a)
#define M_ASN1_ENUMERATED_dup(a) \ #define M_ASN1_IA5STRING_new() ASN1_IA5STRING_new()
(ASN1_ENUMERATED *)ASN1_STRING_dup((const ASN1_STRING *)a) #define M_ASN1_IA5STRING_free(a) ASN1_IA5STRING_free(a)
#define M_ASN1_ENUMERATED_cmp(a, b) \ #define M_ASN1_IA5STRING_dup(a) ASN1_STRING_dup(a)
ASN1_STRING_cmp((const ASN1_STRING *)a, (const ASN1_STRING *)b) #define M_ASN1_UTCTIME_new() ASN1_UTCTIME_new()
#define M_ASN1_UTCTIME_free(a) ASN1_UTCTIME_free(a)
#define M_ASN1_OCTET_STRING_new() \ #define M_ASN1_UTCTIME_dup(a) ASN1_STRING_dup(a)
(ASN1_OCTET_STRING *)ASN1_STRING_type_new(V_ASN1_OCTET_STRING) #define M_ASN1_T61STRING_new() ASN1_T61STRING_new()
#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) #define M_ASN1_T61STRING_free(a) ASN1_T61STRING_free(a)
#define M_ASN1_OCTET_STRING_dup(a) \ #define M_ASN1_GENERALIZEDTIME_new() ASN1_GENERALIZEDTIME_new()
(ASN1_OCTET_STRING *)ASN1_STRING_dup((const ASN1_STRING *)a) #define M_ASN1_GENERALIZEDTIME_free(a) ASN1_GENERALIZEDTIME_free(a)
#define M_ASN1_OCTET_STRING_cmp(a, b) \ #define M_ASN1_GENERALIZEDTIME_dup(a) ASN1_STRING_dup(a)
ASN1_STRING_cmp((const ASN1_STRING *)a, (const ASN1_STRING *)b) #define M_ASN1_GENERALSTRING_new() ASN1_GENERALSTRING_new()
#define M_ASN1_OCTET_STRING_set(a, b, c) ASN1_STRING_set((ASN1_STRING *)a, b, c) #define M_ASN1_GENERALSTRING_free(a) ASN1_GENERALSTRING_free(a)
#define M_ASN1_OCTET_STRING_print(a, b) ASN1_STRING_print(a, (ASN1_STRING *)b) #define M_ASN1_UNIVERSALSTRING_new() ASN1_UNIVERSALSTRING_new()
#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_UNIVERSALSTRING_free(a)
#define M_ASN1_BMPSTRING_new() ASN1_BMPSTRING_new()
#define M_ASN1_BMPSTRING_free(a) ASN1_BMPSTRING_free(a)
#define M_ASN1_VISIBLESTRING_new() ASN1_VISIBLESTRING_new()
#define M_ASN1_VISIBLESTRING_free(a) ASN1_VISIBLESTRING_free(a)
#define M_ASN1_UTF8STRING_new() ASN1_UTF8STRING_new()
#define M_ASN1_UTF8STRING_free(a) ASN1_UTF8STRING_free(a)
#define B_ASN1_TIME B_ASN1_UTCTIME | B_ASN1_GENERALIZEDTIME #define B_ASN1_TIME B_ASN1_UTCTIME | B_ASN1_GENERALIZEDTIME
@ -524,56 +531,10 @@ typedef struct BIT_STRING_BITNAME_st {
#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) #define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a) #define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_PRINTABLESTRING_new() \
(ASN1_PRINTABLESTRING *)ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_T61STRING_new() \
(ASN1_T61STRING *)ASN1_STRING_type_new(V_ASN1_T61STRING)
#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_IA5STRING_new() \
(ASN1_IA5STRING *)ASN1_STRING_type_new(V_ASN1_IA5STRING)
#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_IA5STRING_dup(a) \
(ASN1_IA5STRING *)ASN1_STRING_dup((const ASN1_STRING *)a)
#define M_ASN1_UTCTIME_new() \
(ASN1_UTCTIME *)ASN1_STRING_type_new(V_ASN1_UTCTIME)
#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_UTCTIME_dup(a) \
(ASN1_UTCTIME *)ASN1_STRING_dup((const ASN1_STRING *)a)
#define M_ASN1_GENERALIZEDTIME_new() \
(ASN1_GENERALIZEDTIME *)ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_GENERALIZEDTIME_dup(a) \
(ASN1_GENERALIZEDTIME *)ASN1_STRING_dup((const ASN1_STRING *)a)
#define M_ASN1_TIME_new() (ASN1_TIME *)ASN1_STRING_type_new(V_ASN1_UTCTIME) #define M_ASN1_TIME_new() (ASN1_TIME *)ASN1_STRING_type_new(V_ASN1_UTCTIME)
#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) #define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((const ASN1_STRING *)a) #define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((const ASN1_STRING *)a)
#define M_ASN1_GENERALSTRING_new() \
(ASN1_GENERALSTRING *)ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_UNIVERSALSTRING_new() \
(ASN1_UNIVERSALSTRING *)ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_BMPSTRING_new() \
(ASN1_BMPSTRING *)ASN1_STRING_type_new(V_ASN1_BMPSTRING)
#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_VISIBLESTRING_new() \
(ASN1_VISIBLESTRING *)ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_ASN1_UTF8STRING_new() \
(ASN1_UTF8STRING *)ASN1_STRING_type_new(V_ASN1_UTF8STRING)
#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
OPENSSL_EXPORT int ASN1_TYPE_get(const ASN1_TYPE *a); OPENSSL_EXPORT int ASN1_TYPE_get(const ASN1_TYPE *a);

Loading…
Cancel
Save