ASN1_TYPE_GET(3ossl)
πΈ NAME
Okay so this page is ASN1_TYPE_GET(3ossl) from OpenSSL, and it's the whole vibe for the ASN1_TYPE utility functions, bestie: ASN1_TYPE_get, ASN1_TYPE_set, ASN1_TYPE_set1, ASN1_TYPE_cmp, ASN1_TYPE_unpack_sequence, and ASN1_TYPE_pack_sequence. Slay.
β¨ 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
These functions let you manipulate an ASN1_TYPE structure. And the way that ASN1_TYPE is set up? It can contain any ASN.1 type or constructed type, like a SEQUENCE. It's effectively equivalent to the ASN.1 ANY type. Iconic behavior, honestly.
ASN1_TYPE_get()β returns the type ofa, or0if it fails.ASN1_TYPE_set()β sets the value ofatotypeandvalue. Careful, bestie: this function uses the pointervalueinternally, so it must not be freed up after the call.ASN1_TYPE_set1()β sets the value ofatotype, using a copy ofvalue.ASN1_TYPE_cmp()β compares ASN.1 typesaandband returns0if they are identical and nonzero otherwise.ASN1_TYPE_unpack_sequence()β attempts to parse theSEQUENCEpresent intusing the ASN.1 structureit. If successful, it returns a pointer to the ASN.1 structure corresponding toit, which must be freed by the caller. If it fails, it returnsNULL.ASN1_TYPE_pack_sequence()β attempts to encode the ASN.1 structurescorresponding toitinto anASN1_TYPE. If successful, 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.
π§ NOTES
The type and meaning of the value parameter for ASN1_TYPE_set() and ASN1_TYPE_set1() is determined by the type parameter. Like, that's the main character of this whole operation, okay?
- If
typeisV_ASN1_NULL,valueis ignored. - If
typeisV_ASN1_BOOLEAN, then the boolean is set toTRUEifvalueis notNULL. - If
typeisV_ASN1_OBJECT, thenvalueis anASN1_OBJECTstructure. - Otherwise,
typeis anASN1_STRINGstructure. - 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_SET, orV_ASN1_OTHER), then theASN1_STRINGcontains the entire ASN.1 encoding verbatim, including tag and length octets. Verbatim, bestie.
Now a little caveat moment: ASN1_TYPE_cmp() may not return zero if two types are equivalent but have different encodings. For example, the single content octet of the boolean TRUE value under BER can have any nonzero encoding, but ASN1_TYPE_cmp() will only return zero if the values are the same. No cap.
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. However, 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. Lowkey important, fr fr.
π RETURN VALUES
ASN1_TYPE_get()β returns the type of theASN1_TYPEargument.ASN1_TYPE_set()β does not return a value.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>.
Okay that's the whole page, bestie π This one's from OpenSSL 3.5.6, dated 2026-04-07. Go forth and slay those ASN1_TYPE vibes β¨ππ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms