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

📄 asn.h

📁 ASN.1样例工程代码
💻 H
字号:
/*****************************************************************************
File:     asn.h
Contents: Header file for basic ASN.1 functions.
System:   ASN development.
Created:
Author:   Charles W. Gardiner <gardiner@bbn.com>

Remarks:

COPYRIGHT 1995 BBN Systems and Technologies, A Division of BBN Inc.
150 CambridgePark Drive
Cambridge, Ma. 02140
617-873-4000
*****************************************************************************/
/* sfcsid[] = "@(#)asn.h 224P" */
#ifndef _ASN_H
#define _ASN_H

#define uchar unsigned char
#ifndef ushort
#define ushort unsigned short
#endif
#define ulong unsigned long

#define NO_ERR 0
#define BAD_ASN1 1
#define BAD_ALG 2
#define BAD_VERS 3
#define BAD_IANM 4
#define BAD_SUBJ 5

struct asn
    {
#ifdef __cplusplus
    const
#endif
    uchar *stringp;
    ulong lth;
    ushort level;
    };

union shiftbox
    {
    ushort wd;
    uchar ch[2];
    };

struct xrdn	/* NOTES: Offsets refer to offset from start of table */
    {           /*        Table must end in item with zero oid_lth */
    ushort oid_lth,	/* length of ObjID */
        oid,          	/* offset to ObjID string */
        tag; 		/*   " "   " null-terminated array of offsets to
			   allowed null-terminated tag strings */
    };

#define MAX_RDN_TYPES 64

#define ASN_INDEF_FLAG 0x8000	/* used in asn.level to show indef length */

#define ASN_ANY     0
#define ASN_BOOLEAN 1
#define ASN_INTEGER 2
#define ASN_BITSTRING 3
#define ASN_OCTETSTRING 4
#define ASN_NULL   5
#define ASN_OBJ_ID  6
#define ASN_ENUMERATED   10
#define ASN_NUMERIC_STRING   0x12
#define ASN_PRINTABLE_STRING 0x13
#define ASN_T61_STRING 0x14
#define ASN_VIDEOTEX_STRING 0x15
#define ASN_IA5_STRING 0x16
#define ASN_UTCTIME 0x17
#define ASN_GENTIME 0x18
#define ASN_XT_TAG  0x1F
#define ASN_CONSTRUCTED 0x20
#define ASN_SEQUENCE 0x30
#define ASN_SET 0x31
#define ASN_APPL_SPEC   0x40
#define ASN_APPL_CONSTR (ASN_APPL_SPEC | ASN_CONSTRUCTED)
#define ASN_CONT_SPEC   0x80
#define ASN_CONT_CONSTR (ASN_CONT_SPEC | ASN_CONSTRUCTED)
#define ASN_PRIV_SPEC   0xc0
#define ASN_PRIV_CONSTR (ASN_PRIV_SPEC | ASN_CONSTRUCTED)
#define ASN_INDEF_LTH   0x80
#define ASN_INDEF      ASN_INDEF_LTH
#define ASN_CHOICE (0x100 | ASN_CONSTRUCTED)
#define ASN_NONE       0x101
#define ASN_FUNCTION   0x102
#define ASN_NOTASN1    0x103
#define ASN_NOTYPE     0x104
#define ASN_IA_UID   (ASN_INDEF | 1)
#define ASN_SUBJ_UID (ASN_INDEF | 2)
#define ASN_SC_BYTE0 0x9F	/* used converting RSA SC to ASN.1 */
#define ASN_STD_TYP 0x55       /* value of first byte of obj IDs */
#define ASN_ALG_LTH 3          /* min length of algorithm obj ID */
#define ASN_RDN_OBJ_LTH 3      /*  "    "  "    name       "   " */
#define ASN_RDN_TYP 4          /* value of 2nd byte of name      obj ID */
#define ASN_RDN_COM 3          /*   "   "  3rd  "   " common name  "  " */
#define ASN_RDN_CTRY 6         /*   "   "   "   "   " country name "  " */
#define ASN_RDN_ORG 10	       /*   "   "   "   "   " organization "  " */
#define ASN_RDN_OU 11          /*   "   "   "   "   " org unit     "  " */
#define ASN_RSA_ENCR_ALG "\125\010\001\001"        /* 0x55080101 */
#define ASN_RSA_SIGN_ALG "\125\010\003\002"        /* 0x55080302 */
#define ASN_NULL_DESC    "\005\000"
#define ASN_MAX_VERS  1 	/* highest signing version allowed */

#define FULL_LENGTH(a) (uchar *)asn_start(a) - a->stringp + a->lth


#define UTCBASE 70
#define UTCYR 0
#define UTCYRSIZ 2
#define UTCMO (UTCYR + UTCYRSIZ)
#define UTCMOSIZ 2
#define UTCDA  (UTCMO + UTCMOSIZ)
#define UTCDASIZ 2
#define UTCHR  (UTCDA + UTCDASIZ)
#define UTCHRSIZ 2
#define UTCMI  (UTCHR + UTCHRSIZ)
#define UTCMISIZ 2
#define UTCSE (UTCMI + UTCMISIZ)
#define UTCSESIZ 2
#define UTCSFXHR 1
#define UTCSFXMI (UTCSFXHR + UTCHRSIZ)
#define UTCT_SIZE 16
#define GENTBASE (1900 + UTCBASE)
#define GENTYR 0
#define GENTYRSIZ 4
#define GENTSE (UTCSE + GENTYRSIZ - UTCYRSIZ)

extern uchar asn_typ(), *asn_typ_lth ();

#ifndef __cplusplus
extern int make_asn_table(struct asn **, uchar *, ulong);
extern struct asn *find_asn_tag( /* va_alist */ );
extern int put_asn_tag_lth_string(uchar *, ulong, ulong, ulong, uchar *);
extern int set_asn_lth(uchar *, uchar *);
extern struct asn *skip_asn(struct asn *, struct asn *, int);
extern unsigned char *asn_set(struct asn *);
extern unsigned char *asn_start(struct asn *);
extern unsigned long asn_tag(uchar **);
extern int bit_to_octet(uchar *, uchar *, int);
extern int count_asns(uchar *);
extern int decode_asn(struct asn **, struct asn *, uchar *, ulong, ushort);
extern int encode_asn(struct asn **, struct asn *, uchar *, ushort);
extern unsigned long get_asn_num(struct asn *);
extern unsigned long get_asn_time(struct asn *);
extern int octet_to_bit(uchar *, uchar *, int);
extern int put_asn_lth(uchar *, ulong);
extern int put_asn_num(uchar *, ulong, ulong);
extern int put_asn_tag(uchar *, ulong);
extern int put_asn_time(uchar *, ulong);
#endif
#endif /* _ASN_H */

⌨️ 快捷键说明

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