ASN1_TYPE_GET(3)
okay so bestie, this is ASN1_TYPE_GET(3) from the Library Functions Manual, and we're about to make ASN.1's "anything goes" type make sense. No cap, it's giving chaotic but iconic π
β¨
π NAME π
ASN1_TYPE_new, ASN1_TYPE_free, ASN1_TYPE_get, ASN1_TYPE_set, ASN1_TYPE_set1, ASN1_TYPE_set_octetstring, ASN1_TYPE_get_octetstring, ASN1_TYPE_set_int_octetstring, ASN1_TYPE_get_int_octetstring, ASN1_TYPE_cmp β ASN.1 objects of arbitrary type
β¨ SYNOPSIS β¨
library βlibcryptoβ #include <openssl/asn1.h>
ASN1_TYPE *
ASN1_TYPE_new(void);
void
ASN1_TYPE_free(ASN1_TYPE *a);
int
ASN1_TYPE_get(const ASN1_TYPE *a);
void
ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
int
ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
int
ASN1_TYPE_set_octetstring(ASN1_TYPE *a, const unsigned char *data,
int len);
int
ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *buffer,
int buflen);
int
ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
const unsigned char *data, int len);
int
ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *a, ,,
long *num,unsigned char *buffer, ,, int buflen);
int
ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
π DESCRIPTION π
The ASN1_TYPE data type and the V_ASN1_ANY type identifier constant represent the ASN.1 ANY type. An ASN1_TYPE object can store an ASN.1 value of arbitrary type, including constructed types such as a SEQUENCE. It also remembers internally which type it currently holds. iykyk π¦
ASN1_TYPE_new()β allocates and initializes an emptyASN1_TYPEobject of typeV_ASN1_UNDEF.ASN1_TYPE_free()β freesa, including the value stored in it, if any. Ifais aNULLpointer, no action occurs.ASN1_TYPE_get()β returns the type currently held bya, represented by one of theV_ASN1_*constants defined in<openssl/asn1.h>.ASN1_TYPE_set()β frees the value contained ina, if any, and sets the value and type now held ina. This function uses the pointer value internally, so it must not be freed up after the call.ASN1_TYPE_set1()β sets the type held byatotypeand its value to a copy ofvalue. If copying succeeds, the previous value that was contained inais freed. If copying fails,aremains unchanged.
The type and meaning of the value argument of ASN1_TYPE_set() and ASN1_TYPE_set1() are determined by the type argument. If type is V_ASN1_NULL, value is ignored. If type is V_ASN1_BOOLEAN, then the boolean is set to TRUE if value is not NULL. If type is V_ASN1_OBJECT, then value is an ASN1_OBJECT structure. Otherwise type is an ASN1_STRING structure. If type corresponds to a primitive type or a string type, then the contents of the ASN1_STRING contains the content octets of the type. If type corresponds to a constructed type or a tagged type (V_ASN1_SEQUENCE, V_ASN1_SET, or V_ASN1_OTHER), then the ASN1_STRING contains the entire ASN.1 encoding verbatim, including tag and length octets.
ASN1_TYPE_set_octetstring()β allocates a newASN1_OCTET_STRINGobject, copieslenbytes ofdatainto it usingASN1_STRING_set(3), and replaces the value ofawith it by callingASN1_TYPE_set()with a type ofV_ASN1_OCTET_STRING.ASN1_TYPE_get_octetstring()β copies the contents of theASN1_OCTET_STRINGobject contained ina, but not more thanbuflenbytes, into the buffer provided by the caller.ASN1_TYPE_set_int_octetstring()β frees the value contained ina, if any, sets its type toV_ASN1_SEQUENCE, and sets its value to a two-element ASN.1 sequence consisting of an ASN.1INTEGERobject with the valuenumand an ASN.1OCTET STRINGobject containing a copy of thelenbytes pointed to bydata.ASN1_TYPE_get_int_octetstring()β copies the integer value from the first element of the ASN.1 sequenceato*numunlessnumis aNULLpointer and copies the octet string value from the second element, but not more thanbuflenbytes, into the buffer provided by the caller unlessbufferis aNULLpointer.ASN1_TYPE_cmp()β checks thataandbhold the same type, the same value, and are encoded in the same way.
If the types agree and the values have the same meaning but are encoded differently, they are considered different. For example, a boolean value is represented using a single content octet. Under BER, any non-zero octet represents the TRUE value, but ASN1_TYPE_cmp() will only report a match if the content octet is the same.
If either or both of the arguments passed to ASN1_TYPE_cmp() is NULL, the result is a mismatch. Technically, if both arguments are NULL, the two types could be absent OPTIONAL fields and so should match, however passing NULL values could also indicate a programming error (for example an unparsable type which returns NULL) for types which do not match. So applications should handle the case of two absent values separately. π
π₯ RETURN VALUES π₯
ASN1_TYPE_new()β returns the newASN1_TYPEobject orNULLif an error occurs.ASN1_TYPE_get()β returns the type currently held byaor0if an error occurs. The latter can happen ifadoes not contain a value even though its type is notV_ASN1_NULL. For example, it will always happen for empty objects newly constructed withASN1_TYPE_new().ASN1_TYPE_set1(),ASN1_TYPE_set_octetstring(), andASN1_TYPE_set_int_octetstring()β return1on success or0on failure.ASN1_TYPE_get_octetstring()β returns the number of data bytes contained in theASN1_OCTET_STRINGobject contained inaor-1ifais not of the typeV_ASN1_OCTET_STRINGor does not contain any object. If the return value is greater than thebuflenargument, the content was truncated when copied to the buffer.ASN1_TYPE_get_int_octetstring()β returns the number of data bytes contained in theASN1_OCTET_STRINGobject that is the second element of the ASN.1 sequenceaor-1ifais not of the typeV_ASN1_SEQUENCEor if decoding fails. If the return value is greater than thebuflenargument, the content was truncated when copied to the buffer.ASN1_TYPE_cmp()β returns0for a match or non-zero for a mismatch.
π SEE ALSO π
ASN1_generate_nconf(3), ASN1_get_object(3), ASN1_item_free(3), ASN1_OBJECT_new(3), ASN1_parse_dump(3), ASN1_put_object(3), ASN1_STRING_dup(3), ASN1_STRING_new(3), crypto(3), d2i_ASN1_NULL(3), d2i_ASN1_SEQUENCE_ANY(3), d2i_ASN1_TYPE(3), OBJ_dup(3)
π HISTORY π
ASN1_TYPE_new()andASN1_TYPE_free()first appeared in SSLeay 0.5.1,ASN1_TYPE_get()andASN1_TYPE_set()in SSLeay 0.8.0, andASN1_TYPE_set_octetstring(),ASN1_TYPE_get_octetstring(),ASN1_TYPE_set_int_octetstring(), andASN1_TYPE_get_int_octetstring()in SSLeay 0.9.0. These functions have been available since OpenBSD 2.4.ASN1_TYPE_set1()first appeared in OpenSSL 0.9.8h and has been available since OpenBSD 4.5.ASN1_TYPE_cmp()first appeared in OpenSSL 0.9.8zd, 1.0.0p, and 1.0.1k and has been available since OpenBSD 4.9.
okay that's the whole iconic lore π this page is from Debian, dated June 8, 2025, and it's ASN1_TYPE_GET(3) β periodt. πβ¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2017, 2021 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2015, 2016 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms