[PATCH 2 of 3] Disambiguate enumerator values and add portable wrapper

Wald Commits scm-commit at wald.intevation.org
Tue May 27 18:31:34 CEST 2014


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1401208258 0
# Node ID ecfd77751daf0f126ee1392fd1c373381fe00f6d
# Parent  21f8d32f2d2a5e8db25ecdf396c8f8ce4184fdd6
Disambiguate enumerator values and add portable wrapper.

diff -r 21f8d32f2d2a -r ecfd77751daf common/binverify.c
--- a/common/binverify.c	Tue May 27 10:46:02 2014 +0000
+++ b/common/binverify.c	Tue May 27 16:30:58 2014 +0000
@@ -11,6 +11,16 @@
 #include "strhelp.h"
 #include "logging.h"
 
+bin_verify_result
+verify_binary(const char *filename, size_t name_len) {
+#ifdef WIN32
+  return verify_binary_win(filename, name_len);
+#else
+  /* TODO */
+  return VerifyValid;
+#endif
+}
+
 #ifdef WIN32
 
 #include <windows.h>
@@ -20,7 +30,7 @@
 
 bin_verify_result
 verify_binary_win(const char *filename, size_t name_len) {
-  bin_verify_result retval = UnknownError;
+  bin_verify_result retval = VerifyUnknownError;
   WCHAR *filenameW = NULL;
   BOOL result = FALSE;
   DWORD dwEncoding = 0,
@@ -35,7 +45,7 @@
   if (!filename || name_len > MAX_PATH || strlen(filename) != name_len)
     {
       ERRORPRINTF ("Invalid parameters\n");
-      return UnknownError;
+      return VerifyUnknownError;
     }
 
   filenameW = utf8_to_wchar(filename, strnlen(filename, MAX_PATH));
@@ -55,7 +65,7 @@
   if (!result || !hMsg)
     {
       PRINTLASTERROR ("Failed to query crypto object");
-      retval = ReadFailed;
+      retval = VerifyReadFailed;
       goto done;
     }
 
@@ -71,7 +81,7 @@
   else
     {
       ERRORPRINTF ("Failed to get signer cert size.");
-      retval = UnknownError;
+      retval = VerifyUnknownError;
       goto done;
     }
 
@@ -82,7 +92,7 @@
                          &dwSignerInfoSize)))
     {
       ERRORPRINTF ("Failed to get signer cert.");
-      retval = UnknownError;
+      retval = VerifyUnknownError;
       goto done;
     }
 
@@ -94,7 +104,7 @@
   if (!pSignerCertContext)
     {
       ERRORPRINTF ("Failed to find signer cert in store.");
-      retval = UnknownError;
+      retval = VerifyUnknownError;
       goto done;
     }
 
@@ -106,10 +116,10 @@
     {
       DEBUGPRINTF ("Verify signature succeeded. \n");
       /* TODO pinning*/
-      retval = Valid;
+      retval = VerifyValid;
     } else {
       ERRORPRINTF ("The signature was not verified. \n");
-      retval = InvalidSignature;
+      retval = VerifyInvalidSignature;
       goto done;
     }
 
diff -r 21f8d32f2d2a -r ecfd77751daf common/binverify.h
--- a/common/binverify.h	Tue May 27 10:46:02 2014 +0000
+++ b/common/binverify.h	Tue May 27 16:30:58 2014 +0000
@@ -23,13 +23,12 @@
  * @brief Result of a verification
  */
 typedef enum {
-    Valid = 100, /*! Could be read and signature matched */
-    UnknownError = 1, /*! The expected unexpected */
-    InvalidSignature = 4, /*! Signature was invalid */
-    ReadFailed = 6, /*! File exists but could not read the file */
+    VerifyValid = 100, /*! Could be read and signature matched */
+    VerifyUnknownError = 1, /*! The expected unexpected */
+    VerifyInvalidSignature = 4, /*! Signature was invalid */
+    VerifyReadFailed = 6, /*! File exists but could not read the file */
 } bin_verify_result;
 
-#ifdef WIN32
 /**
  * @brief verify a binary
  *
@@ -48,6 +47,12 @@
  *
  * @returns the verification result.
  */
+bin_verify_result verify_binary(const char *filename, size_t name_len);
+
+#ifdef WIN32
+/**
+ * @brief windows implementation of verify_binary
+ */
 bin_verify_result verify_binary_win(const char *filename, size_t name_len);
 #endif /* WIN32 */
 


More information about the Trustbridge-commits mailing list