root/trunk/src/libopensc/asn1.h

Revision 3084, 6.5 KB (checked in by aj, 2 years ago)

convert to utf-8.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * asn1.h: ASN.1 header file
3 *
4 * Copyright (C) 2001, 2002  Juha YrjölÀ <juha.yrjola@iki.fi>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21#ifndef _OPENSC_ASN1_H
22#define _OPENSC_ASN1_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#include <opensc/opensc.h>
29#include <opensc/pkcs15.h>
30
31struct sc_asn1_entry {
32        const char *name;
33        unsigned int type;
34        unsigned int tag;
35        unsigned int flags;
36        void *parm;
37        void *arg;
38};
39
40struct sc_asn1_pkcs15_object {
41        struct sc_pkcs15_object *p15_obj;
42        struct sc_asn1_entry *asn1_class_attr;
43        struct sc_asn1_entry *asn1_subclass_attr;
44        struct sc_asn1_entry *asn1_type_attr;
45};
46
47struct sc_asn1_pkcs15_algorithm_info {
48        int id;
49        struct sc_object_id oid;
50        int (*decode)(struct sc_context *, void **, const u8 *, size_t, int);
51        int (*encode)(struct sc_context *, void *, u8 **, size_t *, int);
52        void (*free)(void *);
53};
54
55
56/* Utility functions */
57void sc_format_asn1_entry(struct sc_asn1_entry *entry, void *parm, void *arg,
58                          int set_present);
59void sc_copy_asn1_entry(const struct sc_asn1_entry *src,
60                        struct sc_asn1_entry *dest);
61                       
62/* DER tag and length parsing */
63int sc_asn1_decode(struct sc_context *ctx, struct sc_asn1_entry *asn1,
64                   const u8 *in, size_t len, const u8 **newp, size_t *left);
65int sc_asn1_decode_choice(struct sc_context *ctx, struct sc_asn1_entry *asn1,
66                   const u8 *in, size_t len, const u8 **newp, size_t *left);
67int sc_asn1_encode(struct sc_context *ctx, const struct sc_asn1_entry *asn1,
68                   u8 **buf, size_t *bufsize);
69int _sc_asn1_decode(struct sc_context *, struct sc_asn1_entry *,
70                   const u8 *, size_t, const u8 **, size_t *,
71                   int, int);
72int _sc_asn1_encode(struct sc_context *, const struct sc_asn1_entry *,
73                   u8 **, size_t *, int);
74
75const u8 *sc_asn1_find_tag(struct sc_context *ctx, const u8 * buf,
76                           size_t buflen, unsigned int tag, size_t *taglen);
77const u8 *sc_asn1_verify_tag(struct sc_context *ctx, const u8 * buf,
78                             size_t buflen, unsigned int tag, size_t *taglen);
79const u8 *sc_asn1_skip_tag(struct sc_context *ctx, const u8 ** buf,
80                           size_t *buflen, unsigned int tag, size_t *taglen);
81
82/* DER encoding */
83
84/* Argument 'ptr' is set to the location of the next possible ASN.1 object.
85 * If NULL, no action on 'ptr' is performed. */
86int sc_asn1_put_tag(int tag, const u8 * data, size_t datalen, u8 * out, size_t outlen, u8 ** ptr);
87
88/* ASN.1 printing functions */
89void sc_asn1_print_tags(const u8 * buf, size_t buflen);
90
91/* ASN.1 object decoding functions */
92int sc_asn1_utf8string_to_ascii(const u8 * buf, size_t buflen,
93                                u8 * outbuf, size_t outlen);
94int sc_asn1_decode_bit_string(const u8 * inbuf, size_t inlen,
95                              void *outbuf, size_t outlen);
96/* non-inverting version */
97int sc_asn1_decode_bit_string_ni(const u8 * inbuf, size_t inlen,
98                                 void *outbuf, size_t outlen);
99int sc_asn1_decode_integer(const u8 * inbuf, size_t inlen, int *out);
100int sc_asn1_decode_object_id(const u8 * inbuf, size_t inlen,
101                             struct sc_object_id *id);
102
103/* algorithm encoding/decoding */
104int sc_asn1_decode_algorithm_id(struct sc_context *,
105                                const u8 *, size_t,
106                                struct sc_algorithm_id *, int);
107int sc_asn1_encode_algorithm_id(struct sc_context *,
108                                u8 **, size_t *,
109                                const struct sc_algorithm_id *, int);
110void sc_asn1_clear_algorithm_id(struct sc_algorithm_id *);
111
112#define SC_ASN1_CLASS_MASK              0x30000000
113#define SC_ASN1_UNI                     0x00000000 /* Universal */
114#define SC_ASN1_APP                     0x10000000 /* Application */
115#define SC_ASN1_CTX                     0x20000000 /* Context */
116#define SC_ASN1_PRV                     0x30000000 /* Private */
117#define SC_ASN1_CONS                    0x01000000
118
119#define SC_ASN1_TAG_MASK                0x00FFFFFF
120
121#define SC_ASN1_PRESENT                 0x00000001
122#define SC_ASN1_OPTIONAL                0x00000002
123#define SC_ASN1_ALLOC                   0x00000004
124#define SC_ASN1_UNSIGNED                0x00000008
125
126#define SC_ASN1_BOOLEAN                 1
127#define SC_ASN1_INTEGER                 2
128#define SC_ASN1_BIT_STRING              3
129#define SC_ASN1_BIT_STRING_NI           128
130#define SC_ASN1_OCTET_STRING            4
131#define SC_ASN1_NULL                    5
132#define SC_ASN1_OBJECT                  6
133#define SC_ASN1_ENUMERATED              10
134#define SC_ASN1_UTF8STRING              12
135#define SC_ASN1_SEQUENCE                16
136#define SC_ASN1_SET                     17
137#define SC_ASN1_PRINTABLESTRING         19
138#define SC_ASN1_UTCTIME                 23
139#define SC_ASN1_GENERALIZEDTIME         24
140
141/* internal structures */
142#define SC_ASN1_STRUCT                  129
143#define SC_ASN1_CHOICE                  130
144#define SC_ASN1_BIT_FIELD               131     /* bit string as integer */
145
146/* 'complex' structures */
147#define SC_ASN1_PATH                    256
148#define SC_ASN1_PKCS15_ID               257
149#define SC_ASN1_PKCS15_OBJECT           258
150#define SC_ASN1_ALGORITHM_ID            259
151#define SC_ASN1_SE_INFO                 260
152
153/* use callback function */
154#define SC_ASN1_CALLBACK                384
155
156#define SC_ASN1_TAG_CLASS               0xC0
157#define SC_ASN1_TAG_UNIVERSAL           0x00
158#define SC_ASN1_TAG_APPLICATION         0x40
159#define SC_ASN1_TAG_CONTEXT             0x80
160#define SC_ASN1_TAG_PRIVATE             0xC0
161
162#define SC_ASN1_TAG_CONSTRUCTED         0x20
163#define SC_ASN1_TAG_PRIMITIVE           0x1F
164
165#define SC_ASN1_TAG_EOC                 0
166#define SC_ASN1_TAG_BOOLEAN             1
167#define SC_ASN1_TAG_INTEGER             2
168#define SC_ASN1_TAG_BIT_STRING          3
169#define SC_ASN1_TAG_OCTET_STRING        4
170#define SC_ASN1_TAG_NULL                5
171#define SC_ASN1_TAG_OBJECT              6
172#define SC_ASN1_TAG_OBJECT_DESCRIPTOR   7
173#define SC_ASN1_TAG_EXTERNAL            8
174#define SC_ASN1_TAG_REAL                9
175#define SC_ASN1_TAG_ENUMERATED          10
176#define SC_ASN1_TAG_UTF8STRING          12
177#define SC_ASN1_TAG_SEQUENCE            16
178#define SC_ASN1_TAG_SET                 17
179#define SC_ASN1_TAG_NUMERICSTRING       18
180#define SC_ASN1_TAG_PRINTABLESTRING     19
181#define SC_ASN1_TAG_T61STRING           20
182#define SC_ASN1_TAG_TELETEXSTRING       20
183#define SC_ASN1_TAG_VIDEOTEXSTRING      21
184#define SC_ASN1_TAG_IA5STRING           22
185#define SC_ASN1_TAG_UTCTIME             23
186#define SC_ASN1_TAG_GENERALIZEDTIME     24
187#define SC_ASN1_TAG_GRAPHICSTRING       25
188#define SC_ASN1_TAG_ISO64STRING         26
189#define SC_ASN1_TAG_VISIBLESTRING       26
190#define SC_ASN1_TAG_GENERALSTRING       27
191#define SC_ASN1_TAG_UNIVERSALSTRING     28
192#define SC_ASN1_TAG_BMPSTRING           30
193
194#ifdef __cplusplus
195}
196#endif
197
198#endif
Note: See TracBrowser for help on using the browser.