static int decodeCertificateAttributes(unsigned char *cd, int cdlen, struct p15CertificateDescription *p15) { int rc,tag,len; unsigned char *po, *obj; if (cdlen <= 0) { // Nothing to decode return 0; } po = obj = cd; tag = asn1Tag(&po); if (tag != ASN1_SEQUENCE) { return -1; } len = asn1Length(&po); rc = decodeCommonObjectAttributes(po, len, &p15->coa); if (rc < 0) { return rc; } po += len; if ((po - cd) >= cdlen) { return 0; } obj = po; tag = asn1Tag(&po); if (tag != ASN1_SEQUENCE) { return -1; } len = asn1Length(&po); rc = decodeCommonCertificateAttributes(po, len, p15); if (rc < 0) { return rc; } po += len; return 0; }
static int decodePrivateKeyAttributes(unsigned char *prkd, int prkdlen, struct p15PrivateKeyDescription *p15) { int rc,tag,len; unsigned char *po, *obj; if (prkdlen <= 0) { // Nothing to decode return 0; } po = obj = prkd; tag = asn1Tag(&po); if (tag != ASN1_SEQUENCE) { return -1; } len = asn1Length(&po); rc = decodeCommonObjectAttributes(po, len, &p15->coa); if (rc < 0) { return rc; } po += len; if ((po - prkd) >= prkdlen) { return 0; } obj = po; tag = asn1Tag(&po); if (tag != ASN1_SEQUENCE) { return -1; } len = asn1Length(&po); rc = decodeCommonKeyAttributes(po, len, p15); if (rc < 0) { return rc; } po += len; if ((po - prkd) >= prkdlen) { return 0; } obj = po; tag = asn1Tag(&po); if (tag == 0xA0) { len = asn1Length(&po); po += len; if ((po - prkd) >= prkdlen) { return 0; } obj = po; tag = asn1Tag(&po); } len = asn1Length(&po); if ((tag != 0xA1) || (len <= 0)) { return -1; } tag = asn1Tag(&po); len = asn1Length(&po); if ((tag != ASN1_SEQUENCE) || (len <= 0)) { return -1; } rc = decodeKeyAttributes(po, len, p15); if (rc < 0) { return rc; } return 0; }