⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asn1.h

📁 openssl是ssl的开源项目
💻 H
📖 第 1 页 / 共 2 页
字号:
/* crypto/asn1/asn1.h *//* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. *  * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to.  The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code.  The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). *  * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *    "This product includes cryptographic software written by *     Eric Young (eay@cryptsoft.com)" *    The word 'cryptographic' can be left out if the rouines from the library *    being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from  *    the apps directory (application code) you must include an acknowledgement: *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" *  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *  * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed.  i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */#ifndef HEADER_ASN1_H#define HEADER_ASN1_H#ifdef  __cplusplusextern "C" {#endif#include <time.h>#include "bn.h"#include "stack.h"#define V_ASN1_UNIVERSAL		0x00#define	V_ASN1_APPLICATION		0x40#define V_ASN1_CONTEXT_SPECIFIC		0x80#define V_ASN1_PRIVATE			0xc0#define V_ASN1_CONSTRUCTED		0x20#define V_ASN1_PRIMATIVE_TAG		0x1f#define V_ASN1_APP_CHOOSE		-2	/* let the recipent choose */#define V_ASN1_UNDEF			-1#define V_ASN1_EOC			0#define V_ASN1_BOOLEAN			1	/**/#define V_ASN1_INTEGER			2#define V_ASN1_NEG_INTEGER		(2+0x100)#define V_ASN1_BIT_STRING		3#define V_ASN1_OCTET_STRING		4#define V_ASN1_NULL			5#define V_ASN1_OBJECT			6#define V_ASN1_OBJECT_DESCRIPTOR	7#define V_ASN1_EXTERNAL			8#define V_ASN1_REAL			9#define V_ASN1_ENUMERATED		10	/* microsoft weirdness */#define V_ASN1_SEQUENCE			16#define V_ASN1_SET			17#define V_ASN1_NUMERICSTRING		18	/**/#define V_ASN1_PRINTABLESTRING		19#define V_ASN1_T61STRING		20#define V_ASN1_TELETEXSTRING		20	/* alias */#define V_ASN1_VIDEOTEXSTRING		21	/**/#define V_ASN1_IA5STRING		22#define V_ASN1_UTCTIME			23#define V_ASN1_GENERALIZEDTIME		24	/**/#define V_ASN1_GRAPHICSTRING		25	/**/#define V_ASN1_ISO64STRING		26	/**/#define V_ASN1_VISIBLESTRING		26	/* alias */#define V_ASN1_GENERALSTRING		27	/**/#define V_ASN1_UNIVERSALSTRING		28	/**/#define V_ASN1_BMPSTRING		30/* For use with d2i_ASN1_type_bytes() */#define B_ASN1_NUMERICSTRING	0x0001#define B_ASN1_PRINTABLESTRING	0x0002#define B_ASN1_T61STRING	0x0004#define B_ASN1_VIDEOTEXSTRING	0x0008#define B_ASN1_IA5STRING	0x0010#define B_ASN1_GRAPHICSTRING	0x0020#define B_ASN1_ISO64STRING	0x0040#define B_ASN1_GENERALSTRING	0x0080#define B_ASN1_UNIVERSALSTRING	0x0100#define B_ASN1_OCTET_STRING	0x0200#define B_ASN1_BIT_STRING	0x0400#define B_ASN1_BMPSTRING	0x0800#define B_ASN1_UNKNOWN		0x1000typedef struct asn1_ctx_st	{	unsigned char *p;/* work char pointer */	int eos;	/* end of sequence read for indefinite encoding */	int error;	/* error code to use when returning an error */	int inf;	/* constructed if 0x20, indefinite is 0x21 */	int tag;	/* tag from last 'get object' */	int xclass;	/* class from last 'get object' */	long slen;	/* length of last 'get object' */	unsigned char *max; /* largest value of p alowed */	unsigned char *q;/* temporary variable */	unsigned char **pp;/* variable */	int line;	/* used in error processing */	} ASN1_CTX;/* These are used internally in the ASN1_OBJECT to keep track of * whether the names and data need to be free()ed */#define ASN1_OBJECT_FLAG_DYNAMIC	 0x01	/* internal use */#define ASN1_OBJECT_FLAG_CRITICAL	 0x02	/* critical x509v3 object id */#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04	/* internal use */#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 	 0x08	/* internal use */typedef struct asn1_object_st	{	char *sn,*ln;	int nid;	int length;	unsigned char *data;	int flags;	/* Should we free this one */	} ASN1_OBJECT;#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value *//* This is the base type that holds just about everything :-) */typedef struct asn1_string_st	{	int length;	int type;	unsigned char *data;	/* The value of the following field depends on the type being	 * held.  It is mostly being used for BIT_STRING so if the	 * input data has a non-zero 'unused bits' value, it will be	 * handled correctly */	long flags;	} ASN1_STRING;#ifndef DEBUG#define ASN1_INTEGER		ASN1_STRING#define ASN1_BIT_STRING		ASN1_STRING#define ASN1_OCTET_STRING	ASN1_STRING#define ASN1_PRINTABLESTRING	ASN1_STRING#define ASN1_T61STRING		ASN1_STRING#define ASN1_IA5STRING		ASN1_STRING#define ASN1_UTCTIME		ASN1_STRING#define ASN1_GENERALIZEDTIME	ASN1_STRING#define ASN1_GENERALSTRING	ASN1_STRING#define ASN1_UNIVERSALSTRING	ASN1_STRING#define ASN1_BMPSTRING		ASN1_STRING#elsetypedef struct asn1_string_st ASN1_INTEGER;typedef struct asn1_string_st ASN1_BIT_STRING;typedef struct asn1_string_st ASN1_OCTET_STRING;typedef struct asn1_string_st ASN1_PRINTABLESTRING;typedef struct asn1_string_st ASN1_T61STRING;typedef struct asn1_string_st ASN1_IA5STRING;typedef struct asn1_string_st ASN1_GENERALSTRING;typedef struct asn1_string_st ASN1_UNIVERSALSTRING;typedef struct asn1_string_st ASN1_BMPSTRING;typedef struct asn1_string_st ASN1_UTCTIME;typedef struct asn1_string_st ASN1_GENERALIZEDTIME;#endiftypedef struct asn1_type_st	{	int type;	union	{		char *ptr;		ASN1_STRING *		asn1_string;		ASN1_OBJECT *		object;		ASN1_INTEGER *		integer;		ASN1_BIT_STRING *	bit_string;		ASN1_OCTET_STRING *	octet_string;		ASN1_PRINTABLESTRING *	printablestring;		ASN1_T61STRING *	t61string;		ASN1_IA5STRING *	ia5string;		ASN1_GENERALSTRING *	generalstring;		ASN1_BMPSTRING *	bmpstring;		ASN1_UNIVERSALSTRING *	universalstring;		ASN1_UTCTIME *		utctime;		ASN1_GENERALIZEDTIME *	generalizedtime;		/* set and sequence are left complete and still		 * contain the set or sequence bytes */		ASN1_STRING *		set;		ASN1_STRING *		sequence;		} value;	} ASN1_TYPE;typedef struct asn1_method_st	{	int (*i2d)();	char *(*d2i)();	char *(*create)();	void (*destroy)();	} ASN1_METHOD;/* This is used when parsing some Netscape objects */typedef struct asn1_header_st	{	ASN1_OCTET_STRING *header;	char *data;	ASN1_METHOD *meth;	} ASN1_HEADER;#define ASN1_STRING_length(x)	((x)->length)#define ASN1_STRING_type(x)	((x)->type)#define ASN1_STRING_data(x)	((x)->data)/* Macros for string operations */#define ASN1_BIT_STRING_new()	(ASN1_BIT_STRING *)\		ASN1_STRING_type_new(V_ASN1_BIT_STRING)#define ASN1_BIT_STRING_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\		ASN1_STRING_dup((ASN1_STRING *)a)#define ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\		(ASN1_STRING *)a,(ASN1_STRING *)b)#define ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)/* i2d_ASN1_BIT_STRING() is a function *//* d2i_ASN1_BIT_STRING() is a function */#define ASN1_INTEGER_new()	(ASN1_INTEGER *)\		ASN1_STRING_type_new(V_ASN1_INTEGER)#define ASN1_INTEGER_free(a)		ASN1_STRING_free((ASN1_STRING *)a)#define ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)#define ASN1_INTEGER_cmp(a,b)	ASN1_STRING_cmp(\		(ASN1_STRING *)a,(ASN1_STRING *)b)/* ASN1_INTEGER_set() is a function, also see BN_to_ASN1_INTEGER() *//* ASN1_INTEGER_get() is a function, also see ASN1_INTEGER_to_BN() *//* i2d_ASN1_INTEGER() is a function *//* d2i_ASN1_INTEGER() is a function */#define ASN1_OCTET_STRING_new()	(ASN1_OCTET_STRING *)\		ASN1_STRING_type_new(V_ASN1_OCTET_STRING)#define ASN1_OCTET_STRING_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\		ASN1_STRING_dup((ASN1_STRING *)a)#define ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\		(ASN1_STRING *)a,(ASN1_STRING *)b)#define ASN1_OCTET_STRING_set(a,b,c)	ASN1_STRING_set((ASN1_STRING *)a,b,c)#define ASN1_OCTET_STRING_print(a,b)	ASN1_STRING_print(a,(ASN1_STRING *)b)#define M_i2d_ASN1_OCTET_STRING(a,pp) \		i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\		V_ASN1_OCTET_STRING)/* d2i_ASN1_OCTET_STRING() is a function */#define ASN1_PRINTABLE_new()	ASN1_STRING_type_new(V_ASN1_T61STRING)#define ASN1_PRINTABLE_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\		pp,a->type,V_ASN1_UNIVERSAL)#define M_d2i_ASN1_PRINTABLE(a,pp,l) \		d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \			B_ASN1_PRINTABLESTRING| \			B_ASN1_T61STRING| \			B_ASN1_IA5STRING| \			B_ASN1_BIT_STRING| \			B_ASN1_UNIVERSALSTRING|\			B_ASN1_BMPSTRING|\			B_ASN1_UNKNOWN)#define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING_STRING *)\		ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)#define ASN1_PRINTABLESTRING_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \		i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\		V_ASN1_UNIVERSAL)#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \		(ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\		((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)#define ASN1_T61STRING_new()	(ASN1_T61STRING_STRING *)\		ASN1_STRING_type_new(V_ASN1_T61STRING)#define ASN1_T61STRING_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define M_i2d_ASN1_T61STRING(a,pp) \		i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\		V_ASN1_UNIVERSAL)#define M_d2i_ASN1_T61STRING(a,pp,l) \		(ASN1_T61STRING *)d2i_ASN1_type_bytes\		((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)#define ASN1_IA5STRING_new()	(ASN1_IA5STRING *)\		ASN1_STRING_type_new(V_ASN1_IA5STRING)#define ASN1_IA5STRING_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define M_i2d_ASN1_IA5STRING(a,pp) \		i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\			V_ASN1_UNIVERSAL)#define M_d2i_ASN1_IA5STRING(a,pp,l) \		(ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\			B_ASN1_IA5STRING)#define ASN1_UTCTIME_new()	(ASN1_UTCTIME *)\		ASN1_STRING_type_new(V_ASN1_UTCTIME)#define ASN1_UTCTIME_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)/* i2d_ASN1_UTCTIME() is a function *//* d2i_ASN1_UTCTIME() is a function *//* ASN1_UTCTIME_set() is a function *//* ASN1_UTCTIME_check() is a function */#define ASN1_GENERALIZEDTIME_new()	(ASN1_GENERALIZEDTIME *)\		ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)#define ASN1_GENERALIZEDTIME_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define ASN1_GENERALIZEDTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup(\	(ASN1_STRING *)a)/* DOES NOT EXIST YET i2d_ASN1_GENERALIZEDTIME() is a function *//* DOES NOT EXIST YET d2i_ASN1_GENERALIZEDTIME() is a function *//* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_set() is a function *//* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_check() is a function */#define ASN1_GENERALSTRING_new()	(ASN1_GENERALSTRING *)\		ASN1_STRING_type_new(V_ASN1_GENERALSTRING)#define ASN1_GENERALSTRING_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define M_i2d_ASN1_GENERALSTRING(a,pp) \		i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\			V_ASN1_UNIVERSAL)#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \		(ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\		((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)#define ASN1_UNIVERSALSTRING_new()	(ASN1_UNIVERSALSTRING *)\		ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)#define ASN1_UNIVERSALSTRING_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \		i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\			V_ASN1_UNIVERSAL)#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \		(ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\		((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)#define ASN1_BMPSTRING_new()	(ASN1_BMPSTRING *)\		ASN1_STRING_type_new(V_ASN1_BMPSTRING)#define ASN1_BMPSTRING_free(a)	ASN1_STRING_free((ASN1_STRING *)a)#define M_i2d_ASN1_BMPSTRING(a,pp) \		i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\			V_ASN1_UNIVERSAL)#define M_d2i_ASN1_BMPSTRING(a,pp,l) \		(ASN1_BMPSTRING *)d2i_ASN1_type_bytes\		((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)#ifndef NOPROTOASN1_TYPE *	ASN1_TYPE_new(void );void		ASN1_TYPE_free(ASN1_TYPE *a);int		i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp);ASN1_TYPE *	d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length);int ASN1_TYPE_get(ASN1_TYPE *a);void ASN1_TYPE_set(ASN1_TYPE *a, int type, char *value);ASN1_OBJECT *	ASN1_OBJECT_new(void );void		ASN1_OBJECT_free(ASN1_OBJECT *a);int		i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);ASN1_OBJECT *	d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,			long length);ASN1_STRING *	ASN1_STRING_new(void );void		ASN1_STRING_free(ASN1_STRING *a);ASN1_STRING *	ASN1_STRING_dup(ASN1_STRING *a);ASN1_STRING *	ASN1_STRING_type_new(int type );int 		ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);int 		ASN1_STRING_set(ASN1_STRING *str,unsigned char *data, int len);int		i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,			long length);int		ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);int		ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);int		i2d_ASN1_BOOLEAN(int a,unsigned char **pp);int 		d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);int		i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -