/* pop a tag */ BOOL asn1_pop_tag(ASN1_DATA *data) { struct nesting *nesting; size_t len; nesting = data->nesting; if (!nesting) { data->has_error = True; return False; } len = data->ofs - (nesting->start+1); /* yes, this is ugly. We don't know in advance how many bytes the length of a tag will take, so we assumed 1 byte. If we were wrong then we need to correct our mistake */ if (len > 0xFFFF) { data->data[nesting->start] = 0x83; if (!asn1_write_uint8(data, 0)) return False; if (!asn1_write_uint8(data, 0)) return False; if (!asn1_write_uint8(data, 0)) return False; memmove(data->data+nesting->start+4, data->data+nesting->start+1, len); data->data[nesting->start+1] = (len>>16) & 0xFF; data->data[nesting->start+2] = (len>>8) & 0xFF; data->data[nesting->start+3] = len&0xff; } else if (len > 255) {
/* push a tag onto the asn1 data buffer. Used for nested structures */ BOOL asn1_push_tag(ASN1_DATA *data, uint8 tag) { struct nesting *nesting; asn1_write_uint8(data, tag); nesting = (struct nesting *)malloc(sizeof(struct nesting)); if (!nesting) { data->has_error = True; return False; } nesting->start = data->ofs; nesting->next = data->nesting; data->nesting = nesting; return asn1_write_uint8(data, 0xff); }
/* push a tag onto the asn1 data buffer. Used for nested structures */ bool asn1_push_tag(struct asn1_data *data, uint8_t tag) { struct nesting *nesting; asn1_write_uint8(data, tag); nesting = talloc(data, struct nesting); if (!nesting) { data->has_error = true; return false; } nesting->start = data->ofs; nesting->next = data->nesting; data->nesting = nesting; return asn1_write_uint8(data, 0xff); }