1 /*
2 # Copyright 2016 Google Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      https://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 ################################################################################
17 */
18 
19 #include <assert.h>
20 #include <stdint.h>
21 
22 #include <gnutls/gnutls.h>
23 #include <gnutls/pkcs7.h>
24 
25 #include "fuzzer.h"
26 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)27 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
28 {
29 	gnutls_datum_t raw;
30 	gnutls_datum_t out;
31 	gnutls_pkcs7_t pkcs7;
32 	int ret;
33 
34 	raw.data = (unsigned char *)data;
35 	raw.size = size;
36 
37 	ret = gnutls_pkcs7_init(&pkcs7);
38 	assert(ret >= 0);
39 
40 	ret = gnutls_pkcs7_import(pkcs7, &raw, GNUTLS_X509_FMT_DER);
41 	if (ret >= 0) {
42 		ret = gnutls_pkcs7_print(pkcs7, GNUTLS_CRT_PRINT_FULL, &out);
43 		assert(ret >= 0);
44 		gnutls_free(out.data);
45 	}
46 
47 	gnutls_pkcs7_deinit(pkcs7);
48 	return 0;
49 }
50