ASN1_TYPE_GET(3ossl)
π ASN1_TYPE_GET(3ossl) π
okay bestie, welcome to the OpenSSL corner of the manual pages, this one's filed under ASN1_TYPE_GET(3ossl) and it's literally all about the ASN.1 ANY-type situation. grab a boba, we're doing this π§β¨
πΈ NAME πΈ
ASN1_TYPE_get, ASN1_TYPE_set, ASN1_TYPE_set1, ASN1_TYPE_cmp, ASN1_TYPE_unpack_sequence, ASN1_TYPE_pack_sequence β the ASN1_TYPE utility functions, aka your little toolkit for poking at ASN1_TYPE structs π
β¨ SYNOPSIS β¨
#include <openssl/asn1.h>
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_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t);
ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s,
ASN1_TYPE **t);
π¦ DESCRIPTION π¦
So these functions let you mess with an ASN1_TYPE structure β and bestie, that structure is flexible. It can hold literally any ASN.1 type, or a constructed type like a SEQUENCE. it's giving "the ASN.1 ANY type but make it a struct". main character energy fr fr π
ASN1_TYPE_get()β returns the type ofa, or0if it fails. that's it, that's the whole thing πASN1_TYPE_set()β sets the value ofatotypeandvalue. β οΈ IMPORTANT: this one uses the pointervalueinternally, so you must not free it up after the call. not me warning you twice, but like, don't.ASN1_TYPE_set1()β sets the value ofatotypeand a copy ofvalue. so this one's the safe, copying, no-take-backs version πΈASN1_TYPE_cmp()β compares ASN.1 typesaandband returns0if they're identical, nonzero otherwise. periodt.ASN1_TYPE_unpack_sequence()β attempts to parse theSEQUENCEpresent intusing the ASN.1 structureit. if it slays, it returns a pointer to the ASN.1 structure corresponding toit, which must be freed by the caller (yes, that's you π«΅). if it fails, it returnsNULL.ASN1_TYPE_pack_sequence()β attempts to encode the ASN.1 structurescorresponding toitinto anASN1_TYPE. if it works, the encodedASN1_TYPEis returned. iftand*tare notNULL, the encoded type is written tot, overwriting any existing data. iftis notNULLbut*tisNULL, the returnedASN1_TYPEis written to*t. little pointer-to-pointer choreography, we love to see it π©°
π NOTES π
okay this is the part where the value parameter gets specific, because its type and meaning depend entirely on the type parameter. let's break it down:
- if
typeisV_ASN1_NULL,valueis ignored. bye girl π - if
typeisV_ASN1_BOOLEAN, then the boolean is set toTRUEifvalueis notNULL. - if
typeisV_ASN1_OBJECT, thenvalueis anASN1_OBJECTstructure. - otherwise,
typeis anASN1_STRINGstructure. (yes, exactly as written, bestie, don't come for me π«Ά)- if
typecorresponds to a primitive type (or a string type), then the contents of theASN1_STRINGcontain the content octets of the type. - if
typecorresponds to a constructed type or a tagged type (V_ASN1_SEQUENCE,V_ASN1_SETorV_ASN1_OTHER), then theASN1_STRINGcontains the entire ASN.1 encoding verbatim β including the tag and length octets. no skips, no edits, full encoding, iconic.
- if
alsoASN1_TYPE_cmp()may not return zero if two types are equivalent but have different encodings. for example, the single content octet of the booleanTRUEvalue under BER can have any nonzero encoding, butASN1_TYPE_cmp()will only return zero if the values are the same. so like, equivalent β identical in this house π
and one more thing, and this one's a real gotcha:
if either or both of the parameters passed toASN1_TYPE_cmp()isNULL, the return value is nonzero. technically, if both parameters areNULL, the two types could be absentOPTIONALfields and so should match β but passingNULLvalues could also indicate a programming error (for example an unparsable type which returnsNULL) for types which do not match. so applications should handle the case of two absent values separately. don't makeNULLdo double duty, it's not fair to her π
π RETURN VALUES π
ASN1_TYPE_get()returns the type of theASN1_TYPEargument. βASN1_TYPE_set()does not return a value. it's void, she's mysterious, she gives nothing back πASN1_TYPE_set1()returns1for success and0for failure.ASN1_TYPE_cmp()returns0if the types are identical and nonzero otherwise.ASN1_TYPE_unpack_sequence()returns a pointer to an ASN.1 structure orNULLon failure.ASN1_TYPE_pack_sequence()returns anASN1_TYPEstructure if it succeeds orNULLon failure.
π COPYRIGHT π
Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
k bye bestie, this was ASN1_TYPE_GET(3ossl) from the OpenSSL 3.5.9 release, dated 2026-09-29 β go forth and pack those sequences, you absolute legend ππβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms