Nut/OS  4.10.3
API Reference
asn1.h
Go to the documentation of this file.
00001 #ifndef PRO_ASN1_H
00002 #define PRO_ASN1_H
00003 
00004 /*
00005  * Copyright 1998-2007 by egnite Software GmbH
00006  * Copyright 1988, 1989, 1991, 1992 by Carnegie Mellon University
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the distribution.
00017  * 3. Neither the name of the copyright holders nor the names of
00018  *    contributors may be used to endorse or promote products derived
00019  *    from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00028  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00029  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00031  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * For additional information see http://www.ethernut.de/
00035  */
00036 
00046 #include <sys/types.h>
00047 #include <stdint.h>
00048 
00049 #ifndef MAX_OID_LEN
00050 #define MAX_OID_LEN     32
00051 #endif
00052 
00053 #define MAX_SUBID   0xFFFFFFFF
00054 
00055 #define MIN_OID_LEN     2
00056 
00057 #define ASN_BOOLEAN     0x01
00058 #define ASN_INTEGER     0x02
00059 #define ASN_BIT_STR     0x03
00060 #define ASN_OCTET_STR   0x04
00061 #define ASN_NULL        0x05
00062 #define ASN_OBJECT_ID   0x06
00063 #define ASN_SEQUENCE    0x10
00064 #define ASN_SET         0x11
00065 
00066 #define ASN_UNIVERSAL   0x00
00067 #define ASN_APPLICATION 0x40
00068 #define ASN_CONTEXT     0x80
00069 #define ASN_PRIVATE     0xC0
00070 
00071 #define ASN_PRIMITIVE   0x00
00072 #define ASN_CONSTRUCTOR 0x20
00073 
00074 #define ASN_LONG_LEN        0x80
00075 #define ASN_EXTENSION_ID    0x1F
00076 
00077 /* RFC 1157. */
00078 #define ASN_IPADDRESS   (ASN_APPLICATION | 0)
00079 #define ASN_COUNTER     (ASN_APPLICATION | 1)
00080 #define ASN_GAUGE       (ASN_APPLICATION | 2)
00081 #define ASN_UNSIGNED    (ASN_APPLICATION | 2)
00082 #define ASN_TIMETICKS   (ASN_APPLICATION | 3)
00083 #define ASN_OPAQUE      (ASN_APPLICATION | 4)
00084 
00085 /*RFC 1442. */ 
00086 #define ASN_NSAP        (ASN_APPLICATION | 5)
00087 #define ASN_COUNTER64   (ASN_APPLICATION | 6)
00088 #define ASN_UINTEGER    (ASN_APPLICATION | 7)
00089 
00090 #define ACL_RONLY       0xAAAA  /* read access for everyone */
00091 #define ACL_RWRITE      0xAABA  /* add write access for community private */
00092 #define ACL_NOACCESS    0x0000  /* no access for anybody */
00093 
00094 #define ASN_BIT8        0x80
00095 
00096 typedef uint32_t OID;
00097 
00098 /* 
00099  * Internal 64 bit representation.
00100  */
00101 typedef struct {
00102     uint32_t high;
00103     uint32_t low;
00104 } UNSIGNED64;
00105 
00106 extern CONST uint8_t *AsnHeaderParse(CONST uint8_t *, size_t *, uint8_t *);
00107 extern uint8_t *AsnHeaderBuild(uint8_t *, size_t *, uint8_t, size_t);
00108 
00109 extern CONST uint8_t * AsnSequenceParse(CONST uint8_t *, size_t *, uint8_t);
00110 extern uint8_t *AsnSequenceBuild(uint8_t *, size_t *, uint8_t, size_t);
00111 
00112 extern CONST uint8_t *AsnIntegerParse(CONST uint8_t *, size_t *, uint8_t *, long *);
00113 extern uint8_t *AsnIntegerBuild(uint8_t *, size_t *, uint8_t, long *);
00114 
00115 extern CONST uint8_t *AsnUnsignedParse(CONST uint8_t *, size_t *, uint8_t *, uint32_t *);
00116 extern uint8_t *AsnUnsignedBuild(uint8_t *, size_t *, uint8_t, uint32_t *);
00117 
00118 extern CONST uint8_t *AsnOctetStringParse(CONST uint8_t *, size_t *, uint8_t *, uint8_t *, size_t *);
00119 extern uint8_t *AsnOctetStringBuild(uint8_t *, size_t *, uint8_t, CONST uint8_t *, size_t);
00120 
00121 extern CONST uint8_t *AsnOidParse(CONST uint8_t *, size_t *, uint8_t *, OID *, size_t *);
00122 extern uint8_t *AsnOidBuild(uint8_t *, size_t *, uint8_t, CONST OID *, size_t);
00123 
00124 extern CONST uint8_t *AsnNullParse(CONST uint8_t *, size_t *, uint8_t *);
00125 extern uint8_t *AsnNullBuild(uint8_t *, size_t *, uint8_t);
00126 
00127 extern CONST uint8_t *AsnBitStringParse(CONST uint8_t *, size_t *, uint8_t *, uint8_t *, size_t *);
00128 extern uint8_t *AsnBitStringBuild(uint8_t *, size_t *, uint8_t, CONST uint8_t *, size_t);
00129 
00130 extern CONST uint8_t *AsnUnsigned64Parse(CONST uint8_t *, size_t *, uint8_t *, UNSIGNED64 *);
00131 extern uint8_t *AsnUnsigned64Build(uint8_t *, size_t *, uint8_t, CONST UNSIGNED64 *);
00132 
00133 
00134 #endif