Add support for non-optional ASN.1 object that are empty

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1195 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
sth 2003-06-12 21:14:04 +00:00
parent de20691dd4
commit aecd987286
1 changed files with 15 additions and 7 deletions

View File

@ -1230,18 +1230,26 @@ static int asn1_encode_entry(struct sc_context *ctx, const struct sc_asn1_entry
return r; return r;
} }
if (buflen != 0) { /* Treatment of OPTIONAL elements:
r = asn1_write_element(ctx, entry->tag, * - if the encoding has 0 length, and the element is OPTIONAL,
buf, buflen, obj, objlen); * we don't write anything
if (r) * - if the encoding has 0 length, but the element is non-OPTIONAL,
error(ctx, "error writing ASN.1 tag and length: %s\n", * constructed, we write a empty element (e.g. a SEQUENCE of length 0).
sc_strerror(r)); * - any other empty objects are considered bogus
} else if (entry->flags & SC_ASN1_OPTIONAL) { */
if ((entry->flags & SC_ASN1_OPTIONAL) && buflen == 0) {
/* This happens when we try to encode e.g. the /* This happens when we try to encode e.g. the
* subClassAttributes, which may be empty */ * subClassAttributes, which may be empty */
*obj = NULL; *obj = NULL;
*objlen = 0; *objlen = 0;
r = 0; r = 0;
} else
if (buflen != 0 || (entry->tag & SC_ASN1_CONS)) {
r = asn1_write_element(ctx, entry->tag,
buf, buflen, obj, objlen);
if (r)
error(ctx, "error writing ASN.1 tag and length: %s\n",
sc_strerror(r));
} else { } else {
error(ctx, "cannot encode empty non-optional ASN.1 object"); error(ctx, "cannot encode empty non-optional ASN.1 object");
r = SC_ERROR_INVALID_ASN1_OBJECT; r = SC_ERROR_INVALID_ASN1_OBJECT;