1 /*
2  * Copyright (C) 2012 Red Hat Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  *     * Redistributions of source code must retain the above
9  *       copyright notice, this list of conditions and the
10  *       following disclaimer.
11  *     * Redistributions in binary form must reproduce the
12  *       above copyright notice, this list of conditions and
13  *       the following disclaimer in the documentation and/or
14  *       other materials provided with the distribution.
15  *     * The names of contributors to this software may not be
16  *       used to endorse or promote products derived from this
17  *       software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
29  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30  * DAMAGE.
31  *
32  * Author: Stef Walter <stefw@redhat.com>
33  */
34 
35 #include <libtasn1.h>
36 
37 #include "dict.h"
38 
39 #ifndef P11_ASN1_H_
40 #define P11_ASN1_H_
41 
42 typedef struct _p11_asn1_cache p11_asn1_cache;
43 
44 p11_dict *       p11_asn1_defs_load                 (void);
45 
46 node_asn *       p11_asn1_decode                    (p11_dict *asn1_defs,
47                                                      const char *struct_name,
48                                                      const unsigned char *der,
49                                                      size_t der_len,
50                                                      char *message);
51 
52 node_asn *       p11_asn1_create                    (p11_dict *asn1_defs,
53                                                      const char *struct_name);
54 
55 unsigned char *  p11_asn1_encode                    (node_asn *asn,
56                                                      size_t *der_len);
57 
58 void *           p11_asn1_read                      (node_asn *asn,
59                                                      const char *field,
60                                                      size_t *length);
61 
62 void             p11_asn1_free                      (void *asn);
63 
64 ssize_t          p11_asn1_tlv_length                (const unsigned char *data,
65                                                      size_t length);
66 
67 p11_asn1_cache * p11_asn1_cache_new                 (void);
68 
69 p11_dict *       p11_asn1_cache_defs                (p11_asn1_cache *cache);
70 
71 node_asn *       p11_asn1_cache_get                 (p11_asn1_cache *cache,
72                                                      const char *struct_name,
73                                                      const unsigned char *der,
74                                                      size_t der_len);
75 
76 void             p11_asn1_cache_take                (p11_asn1_cache *cache,
77                                                      node_asn *node,
78                                                      const char *struct_name,
79                                                      const unsigned char *der,
80                                                      size_t der_len);
81 
82 void             p11_asn1_cache_flush               (p11_asn1_cache *cache);
83 
84 void             p11_asn1_cache_free                (p11_asn1_cache *cache);
85 
86 #endif /* P11_ASN1_H_ */
87