• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
3  * 2006.
4  */
5 /* ====================================================================
6  * Copyright (c) 2006 The OpenSSL Project.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. All advertising materials mentioning features or use of this
21  *    software must display the following acknowledgment:
22  *    "This product includes software developed by the OpenSSL Project
23  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24  *
25  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26  *    endorse or promote products derived from this software without
27  *    prior written permission. For written permission, please contact
28  *    licensing@OpenSSL.org.
29  *
30  * 5. Products derived from this software may not be called "OpenSSL"
31  *    nor may "OpenSSL" appear in their names without prior written
32  *    permission of the OpenSSL Project.
33  *
34  * 6. Redistributions of any form whatsoever must retain the following
35  *    acknowledgment:
36  *    "This product includes software developed by the OpenSSL Project
37  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50  * OF THE POSSIBILITY OF SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This product includes cryptographic software written by Eric Young
54  * (eay@cryptsoft.com).  This product includes software written by Tim
55  * Hudson (tjh@cryptsoft.com).
56  *
57  */
58 
59 #ifndef OPENSSL_HEADER_ASN1_ASN1_LOCL_H
60 #define OPENSSL_HEADER_ASN1_ASN1_LOCL_H
61 
62 #include <time.h>
63 
64 #include <openssl/asn1.h>
65 
66 #if defined(__cplusplus)
67 extern "C" {
68 #endif
69 
70 
71 /* Wrapper functions for time functions. */
72 
73 /* OPENSSL_gmtime wraps |gmtime_r|. See the manual page for that function. */
74 struct tm *OPENSSL_gmtime(const time_t *time, struct tm *result);
75 
76 /* OPENSSL_gmtime_adj updates |tm| by adding |offset_day| days and |offset_sec|
77  * seconds. */
78 int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec);
79 
80 /* OPENSSL_gmtime_diff calculates the difference between |from| and |to| and
81  * outputs the difference as a number of days and seconds in |*out_days| and
82  * |*out_secs|. */
83 int OPENSSL_gmtime_diff(int *out_days, int *out_secs, const struct tm *from,
84                         const struct tm *to);
85 
86 
87 /* Internal ASN1 structures and functions: not for application use */
88 
89 /* These are used internally in the ASN1_OBJECT to keep track of
90  * whether the names and data need to be free()ed */
91 #define ASN1_OBJECT_FLAG_DYNAMIC 0x01         /* internal use */
92 #define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
93 #define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08    /* internal use */
94 
95 /* An asn1_object_st (aka |ASN1_OBJECT|) represents an ASN.1 OBJECT IDENTIFIER.
96  * Note: Mutating an |ASN1_OBJECT| is only permitted when initializing it. The
97  * library maintains a table of static |ASN1_OBJECT|s, which may be referenced
98  * by non-const |ASN1_OBJECT| pointers. Code which receives an |ASN1_OBJECT|
99  * pointer externally must assume it is immutable, even if the pointer is not
100  * const. */
101 struct asn1_object_st {
102   const char *sn, *ln;
103   int nid;
104   int length;
105   const unsigned char *data; /* data remains const after init */
106   int flags;                 /* Should we free this one */
107 };
108 
109 int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d);
110 int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d);
111 
112 void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
113                             int combine);
114 
115 int UTF8_getc(const unsigned char *str, int len, uint32_t *val);
116 int UTF8_putc(unsigned char *str, int len, uint32_t value);
117 
118 int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
119 void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
120 
121 void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
122 int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
123                      const ASN1_ITEM *it, int tag, int aclass, char opt,
124                      ASN1_TLC *ctx);
125 
126 int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
127                      const ASN1_ITEM *it, int tag, int aclass);
128 void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
129 
130 int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
131 int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
132 
133 ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
134 
135 const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
136                                  int nullerr);
137 
138 void asn1_refcount_set_one(ASN1_VALUE **pval, const ASN1_ITEM *it);
139 int asn1_refcount_dec_and_test_zero(ASN1_VALUE **pval, const ASN1_ITEM *it);
140 
141 void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
142 void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
143 int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
144                      const ASN1_ITEM *it);
145 int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
146                   const ASN1_ITEM *it);
147 
148 /* asn1_type_value_as_pointer returns |a|'s value in pointer form. This is
149  * usually the value object but, for BOOLEAN values, is 0 or 0xff cast to
150  * a pointer. */
151 const void *asn1_type_value_as_pointer(const ASN1_TYPE *a);
152 
153 /* asn1_is_printable returns one if |value| is a valid Unicode codepoint for an
154  * ASN.1 PrintableString, and zero otherwise. */
155 int asn1_is_printable(uint32_t value);
156 
157 
158 #if defined(__cplusplus)
159 }  /* extern C */
160 #endif
161 
162 #endif  /* OPENSSL_HEADER_ASN1_ASN1_LOCL_H */
163