DragonFly On-Line Manual Pages
ASN1_PUT_OBJECT(3) DragonFly Library Functions Manual ASN1_PUT_OBJECT(3)
ASN1_put_object, ASN1_put_eoc - start and end the BER encoding of an
arbitrary ASN.1 data element
ASN1_put_object(unsigned char **ber_out, int constructed, int length,
int tag, int class);
ASN1_put_eoc(unsigned char **ber_out);
ASN1_put_object() begins writing the BER encoding of an arbitrary ASN.1
data element to the buffer *ber_out by writing the identifier and the
length bytes. Making sure that there is sufficient space in the buffer
is the responsibility of the caller. This function does not write any
content bytes nor any end-of-content bytes.
The tag class can be V_ASN1_UNIVERSAL, V_ASN1_APPLICATION,
V_ASN1_CONTEXT_SPECIFIC, or V_ASN1_PRIVATE and is written to the two most
significant bits of the first byte written.
The constructed argument can have the following values:
0 Start a primitive value by setting the third most significant bit of
the first byte written to 0. Always use the definite form.
1 Start a constructed value by setting the third most significant bit
of the first byte written to 1, and use the definite form.
2 Start a constructed value and use the indefinite form,
If the tag is less than 0x1f, it is written to the five least significant
bits of the only identifier byte written. Otherwise, these five bits are
all set to 1, and the tag is encoded in one or more following identifier
bytes as needed.
After completing the identifier byte(s), when using the definite form,
the given length is encoded in one or more bytes as needed. Otherwise,
the special byte 0x80 is written instead and the length argument is
At the end, *ber_out is set to the byte following the last byte written.
The calling code can then start writing content bytes.
If the indefinite form was selected, the calling code is also responsible
for calling ASN1_put_eoc() which writes an end-of-content marker to
*ber_out, consisting of two NUL bytes, and advances *ber_out by two
ASN1_put_eoc() returns the number of bytes written, which is always 2.
ASN1_item_i2d(3), ASN1_TYPE_get(3), i2d_ASN1_NULL(3), i2d_ASN1_OBJECT(3),
ASN1_put_object() first appeared in SSLeay 0.5.1 and has been available
since OpenBSD 2.4.
ASN1_put_eoc() first appeared in OpenSSL 0.9.8 and has been available
since OpenBSD 4.5.
Neither ASN1_put_object() nor ASN1_put_eoc() do any sanity checking.
When called in inconsistent ways, invalid content may result in *ber_out,
- a tag number less than 0x1f with a non-universal class
- a tag number equal to 0x00 or 0x1f
- a BOOLEAN, INTEGER, NULL etc. with the constructed bit set
- a SEQUENCE or SET etc. without the constructed bit set
- a length that makes no sense for the given tag
- a length that disagrees with the following data
- a BOOLEAN, INTEGER, NULL etc. in indefinite form
- an end-of-content marker even though no indefinite form was started
If the calling code wants to find out how many bytes were written, it
needs to save a copy of the pointer *ber_out before calling
DragonFly 5.9-DEVELOPMENT August 26, 2019 DragonFly 5.9-DEVELOPMENT