ASN1_TYPE_GET(3ossl)
π ASN1_TYPE_GET(3ossl) β OpenSSL ASN1_TYPE utility functions β¨
πΈ NAME πΈ
Okay bestie, this whole page is about the ASN1_TYPE utility functions, and they are: ASN1_TYPE_get, ASN1_TYPE_set, ASN1_TYPE_set1, ASN1_TYPE_cmp, ASN1_TYPE_unpack_sequence, and ASN1_TYPE_pack_sequence. Thatβs the squad. π«Ά
β¨ 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. The ASN1_TYPE structure can hold any ASN.1 type or constructed type β like a SEQUENCE β and itβs effectively equivalent to the ASN.1 ANY type. Iconic little container, honestly. π
ASN1_TYPE_get()β returns the type ofa, or0if it fails. Vibe check on the type, basically.ASN1_TYPE_set()β sets the value ofatotypeandvalue. It uses the pointervalueinternally, so you must not free it up after the call. Do not touch that pointer afterward, bestie. πASN1_TYPE_set1()β sets the value ofatotype, using a copy ofvalue. So this one does the copying for you. Slay.ASN1_TYPE_cmp()β compares ASN.1 typesaandband returns0if they are identical and nonzero otherwise. Equal means0here, which is giving reverse logic, but thatβs C for you. π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. Free it, okay? Thatβs the rule. π§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. Pointer-to-pointer behavior, main character energy. π₯
π¦ NOTES π¦
The type and meaning of the value parameter for ASN1_TYPE_set() and ASN1_TYPE_set1() is determined by the type parameter. Hereβs the tea:
- 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,
valueis anASN1_STRINGstructure.
If type corresponds to a primitive type (or a string type), then the contents of the ASN1_STRING contain 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. Verbatim means verbatim, no edits. π
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. So like, same vibe β same bytes. π
If either or both of the parameters passed to ASN1_TYPE_cmp() is NULL, the return value is nonzero. Technically, if both parameters 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. This is one of those βhandle it yourself, bestieβ situations. π«Ά
β RETURN VALUES β
ASN1_TYPE_get()returns the type of theASN1_TYPEargument.ASN1_TYPE_set()does not return a value. Itβs a void icon.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 from OpenSSL 3.5.0, dated 2026-09-25. Go forth and handle your ASN1_TYPEs, bestie πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms