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 "asn1.h" 36 #include "array.h" 37 #include "compat.h" 38 #include "dict.h" 39 40 #ifndef P11_PARSER_H_ 41 #define P11_PARSER_H_ 42 43 enum { 44 P11_PARSE_FLAG_NONE = 0, 45 P11_PARSE_FLAG_ANCHOR = 1 << 0, 46 P11_PARSE_FLAG_BLOCKLIST = 1 << 1, 47 }; 48 49 enum { 50 P11_PARSE_FAILURE = -1, 51 P11_PARSE_UNRECOGNIZED = 0, 52 P11_PARSE_SUCCESS = 1, 53 }; 54 55 typedef struct _p11_parser p11_parser; 56 57 p11_parser * p11_parser_new (p11_asn1_cache *asn1_cache); 58 59 void p11_parser_free (p11_parser *parser); 60 61 int p11_parse_memory (p11_parser *parser, 62 const char *filename, 63 int flags, 64 const unsigned char *data, 65 size_t length); 66 67 int p11_parse_file (p11_parser *parser, 68 const char *filename, 69 struct stat *sb, 70 int flags); 71 72 p11_array * p11_parser_parsed (p11_parser *parser); 73 74 void p11_parser_formats (p11_parser *parser, 75 ...) GNUC_NULL_TERMINATED; 76 77 int p11_parser_format_persist (p11_parser *parser, 78 const unsigned char *data, 79 size_t length); 80 81 int p11_parser_format_pem (p11_parser *parser, 82 const unsigned char *data, 83 size_t length); 84 85 int p11_parser_format_x509 (p11_parser *parser, 86 const unsigned char *data, 87 size_t length); 88 89 #endif /* P11_PARSER_H_ */ 90