/* ASN.1 decoder test driver * * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public Licence * as published by the Free Software Foundation; either version * 2 of the Licence, or (at your option) any later version. */ #include #include #include #include #include #include #include #include "x509.h" /* * */ int main(int argc, char **argv) { struct stat st; const char *filename; ssize_t readlen; unsigned char *buffer; int fd, ret; if (argc != 2) { fprintf(stderr, "Format: %s \n", argv[0]); exit(2); } filename = argv[1]; fd = open(filename, O_RDONLY); if (fd < 0) { perror(filename); exit(1); } if (fstat(fd, &st) < 0) { perror(filename); exit(1); } if (!(buffer = malloc(st.st_size + 1))) { perror(NULL); exit(1); } if ((readlen = read(fd, buffer, st.st_size)) < 0) { perror(filename); exit(1); } if (close(fd) < 0) { perror(filename); exit(1); } if (readlen != st.st_size) { fprintf(stderr, "%s: Short read\n", filename); exit(1); } ret = asn1_decoder(&x509_decoder, NULL, buffer, st.st_size); if (ret == 0) { printf("Success!\n"); exit(0); } fprintf(stderr, "Failure!\n"); exit(1); } /* * */ int do_tbs_certificate(void *context, unsigned state_index, unsigned char tag, const void *value, size_t vlen) { printf("do_tbs_certificate!\n"); return 0; } /* * */ int do_name_segment(void *context, unsigned state_index, unsigned char tag, const void *value, size_t vlen) { printf("do_name_segment(%02x,%zu,%*.*s)\n", tag, vlen, (int)vlen, (int)vlen, (const char *)value); return 0; } /* * */ int do_issuer(void *context, unsigned state_index, unsigned char tag, const void *value, size_t vlen) { printf("do_issuer(%02x,%zu)\n", tag, vlen); return 0; } /* * */ int do_subject(void *context, unsigned state_index, unsigned char tag, const void *value, size_t vlen) { printf("do_subject(%02x,%zu)\n", tag, vlen); return 0; }