Path: blob/main/crypto/heimdal/lib/asn1/asn1-template.h
34889 views
/*1* Copyright (c) 1997 - 2006 Kungliga Tekniska H�gskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Portions Copyright (c) 2009 Apple Inc. All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13*14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* 3. Neither the name of the Institute nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435/* asn1 templates */3637#ifndef __TEMPLATE_H__38#define __TEMPLATE_H__3940/* tag:41* 0..20 tag42* 21 type43* 22..23 class44* 24..27 flags45* 28..31 op46*/4748/* parse:49* 0..11 type50* 12..23 unused51* 24..27 flags52* 28..31 op53*/5455#define A1_OP_MASK (0xf0000000)56#define A1_OP_TYPE (0x10000000)57#define A1_OP_TYPE_EXTERN (0x20000000)58#define A1_OP_TAG (0x30000000)59#define A1_OP_PARSE (0x40000000)60#define A1_OP_SEQOF (0x50000000)61#define A1_OP_SETOF (0x60000000)62#define A1_OP_BMEMBER (0x70000000)63#define A1_OP_CHOICE (0x80000000)6465#define A1_FLAG_MASK (0x0f000000)66#define A1_FLAG_OPTIONAL (0x01000000)67#define A1_FLAG_IMPLICIT (0x02000000)6869#define A1_TAG_T(CLASS,TYPE,TAG) ((A1_OP_TAG) | (((CLASS) << 22) | ((TYPE) << 21) | (TAG)))70#define A1_TAG_CLASS(x) (((x) >> 22) & 0x3)71#define A1_TAG_TYPE(x) (((x) >> 21) & 0x1)72#define A1_TAG_TAG(x) ((x) & 0x1fffff)7374#define A1_TAG_LEN(t) ((uintptr_t)(t)->ptr)75#define A1_HEADER_LEN(t) ((uintptr_t)(t)->ptr)7677#define A1_PARSE_T(type) ((A1_OP_PARSE) | (type))78#define A1_PARSE_TYPE_MASK 0xfff79#define A1_PARSE_TYPE(x) (A1_PARSE_TYPE_MASK & (x))8081#define A1_PF_INDEFINTE 0x182#define A1_PF_ALLOW_BER 0x28384#define A1_HF_PRESERVE 0x185#define A1_HF_ELLIPSIS 0x28687#define A1_HBF_RFC1510 0x1888990struct asn1_template {91uint32_t tt;92size_t offset;93const void *ptr;94};9596typedef int (*asn1_type_decode)(const unsigned char *, size_t, void *, size_t *);97typedef int (*asn1_type_encode)(unsigned char *, size_t, const void *, size_t *);98typedef size_t (*asn1_type_length)(const void *);99typedef void (*asn1_type_release)(void *);100typedef int (*asn1_type_copy)(const void *, void *);101102struct asn1_type_func {103asn1_type_encode encode;104asn1_type_decode decode;105asn1_type_length length;106asn1_type_copy copy;107asn1_type_release release;108size_t size;109};110111struct template_of {112unsigned int len;113void *val;114};115116enum template_types {117A1T_IMEMBER = 0,118A1T_HEIM_INTEGER,119A1T_INTEGER,120A1T_INTEGER64,121A1T_UNSIGNED,122A1T_UNSIGNED64,123A1T_GENERAL_STRING,124A1T_OCTET_STRING,125A1T_OCTET_STRING_BER,126A1T_IA5_STRING,127A1T_BMP_STRING,128A1T_UNIVERSAL_STRING,129A1T_PRINTABLE_STRING,130A1T_VISIBLE_STRING,131A1T_UTF8_STRING,132A1T_GENERALIZED_TIME,133A1T_UTC_TIME,134A1T_HEIM_BIT_STRING,135A1T_BOOLEAN,136A1T_OID,137A1T_TELETEX_STRING,138A1T_NULL139};140141142#endif143144145