From f896ebd7de1a0f6cc63b4ab5b7c1043e071a2041 Mon Sep 17 00:00:00 2001 From: Blake Ramsdell Date: Wed, 12 Sep 2007 03:11:03 -0700 Subject: [PATCH] Moved loading functions to util.c. --- printcert/bldmac | 2 +- printcert/printcert.c | 78 +------------------------------------------------ printcert/util.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ printcert/util.h | 6 ++++ 4 files changed, 89 insertions(+), 78 deletions(-) create mode 100644 printcert/util.c create mode 100644 printcert/util.h diff --git a/printcert/bldmac b/printcert/bldmac index 1802bae..0a15386 100755 --- a/printcert/bldmac +++ b/printcert/bldmac @@ -2,4 +2,4 @@ IARG=-I$PATH_TO_A2C/runtime/C A2C_LIB=$PATH_TO_A2C/runtime/C/A2C_Runtime.lib -gcc -o printcert $IARG printcert.c rfc3280.c $A2C_LIB +gcc -o printcert $IARG printcert.c rfc3280.c util.c $A2C_LIB diff --git a/printcert/printcert.c b/printcert/printcert.c index 7adaff6..3bdbaa7 100644 --- a/printcert/printcert.c +++ b/printcert/printcert.c @@ -1,82 +1,6 @@ #include "rfc3280.h" -#define BUFFER_LENGTH 4096 - -static A2C_ERROR _A2C_DecodeBerFile(PVOID * ppv, PC_A2C_DESCRIPTOR pdesc, int flags, FILE* file) -{ - unsigned char buffer[BUFFER_LENGTH]; - int return_code = 0; - A2C_CONTEXT* pcxt = NULL; - A2C_ERROR err = A2C_ERROR_Success; - - while (1) - { - return_code = fread(buffer, 1, sizeof(buffer), file); - - if (return_code < 0) - { - err = A2C_ERROR_malformedEncoding; - break; - } - - if (return_code == 0) - { - break; - } - - err = A2C_DecodeBer( - ppv, - pdesc, - flags, - &pcxt, - buffer, - return_code - ); - if ((err < A2C_ERROR_Success) && (err != A2C_ERROR_needMoreData)) - { - break; - } - - flags |= A2C_FLAGS_MORE_DATA; - } - - if ((err < A2C_ERROR_Success) && (pcxt != NULL)) - { - /* A2C_FreeContext(pcxt); */ - } - - return err; -} - -static Cert_Certificate* read_certificate_from_file(const char* filename) -{ - A2C_ERROR err = A2C_ERROR_Success; - Cert_Certificate* certificate = NULL; - FILE* file = NULL; - - file = fopen(filename, "rb"); - if (file == NULL) - { - perror(filename); - return NULL; - } - - err = _A2C_DecodeBerFile( - (PVOID*) &certificate, - &Cert_Certificate_descriptor, - 0, - file - ); - - (void) fclose(file); - - if (err < A2C_ERROR_Success) - { - return NULL; - } - - return certificate; -} +#include "util.h" static void print_relative_distinguished_name_email_addresses(Cert_RelativeDistinguishedName* rdn) { diff --git a/printcert/util.c b/printcert/util.c new file mode 100644 index 0000000..e4f5d06 --- /dev/null +++ b/printcert/util.c @@ -0,0 +1,81 @@ +#include "rfc3280.h" + +#include "util.h" + +#define BUFFER_LENGTH 4096 + +static A2C_ERROR _A2C_DecodeBerFile(PVOID * ppv, PC_A2C_DESCRIPTOR pdesc, int flags, FILE* file) +{ + unsigned char buffer[BUFFER_LENGTH]; + int return_code = 0; + A2C_CONTEXT* pcxt = NULL; + A2C_ERROR err = A2C_ERROR_Success; + + while (1) + { + return_code = fread(buffer, 1, sizeof(buffer), file); + + if (return_code < 0) + { + err = A2C_ERROR_malformedEncoding; + break; + } + + if (return_code == 0) + { + break; + } + + err = A2C_DecodeBer( + ppv, + pdesc, + flags, + &pcxt, + buffer, + return_code + ); + if ((err < A2C_ERROR_Success) && (err != A2C_ERROR_needMoreData)) + { + break; + } + + flags |= A2C_FLAGS_MORE_DATA; + } + + if ((err < A2C_ERROR_Success) && (pcxt != NULL)) + { + /* A2C_FreeContext(pcxt); */ + } + + return err; +} + +Cert_Certificate* read_certificate_from_file(const char* filename) +{ + A2C_ERROR err = A2C_ERROR_Success; + Cert_Certificate* certificate = NULL; + FILE* file = NULL; + + file = fopen(filename, "rb"); + if (file == NULL) + { + perror(filename); + return NULL; + } + + err = _A2C_DecodeBerFile( + (PVOID*) &certificate, + &Cert_Certificate_descriptor, + 0, + file + ); + + (void) fclose(file); + + if (err < A2C_ERROR_Success) + { + return NULL; + } + + return certificate; +} diff --git a/printcert/util.h b/printcert/util.h new file mode 100644 index 0000000..2f85d38 --- /dev/null +++ b/printcert/util.h @@ -0,0 +1,6 @@ +#ifndef UTIL_H +#define UTIL_H + +Cert_Certificate* read_certificate_from_file(const char* filename); + +#endif /* UTIL_H */ \ No newline at end of file -- 2.11.4.GIT