Fix use of "can_load()" in run_tests.pl.
[openssl.git] / crypto / ct / ct_b64.c
index 9cf7c51be3ec41d8ba18ab3b110adf7fc2128c1b..f0bf3aff29d2686d2e0945149b85c35baa072e96 100644 (file)
@@ -45,6 +45,11 @@ static int ct_base64_decode(const char *in, unsigned char **out)
         goto err;
     }
 
+    /* Subtract padding bytes from |outlen| */
+    while (in[--inlen] == '=') {
+        --outlen;
+    }
+
     *out = outbuf;
     return outlen;
 err:
@@ -59,6 +64,7 @@ SCT *SCT_new_from_base64(unsigned char version, const char *logid_base64,
 {
     SCT *sct = SCT_new();
     unsigned char *dec = NULL;
+    const unsigned char* p = NULL;
     int declen;
 
     if (sct == NULL) {
@@ -97,7 +103,9 @@ SCT *SCT_new_from_base64(unsigned char version, const char *logid_base64,
         CTerr(CT_F_SCT_NEW_FROM_BASE64, X509_R_BASE64_DECODE_ERROR);
         goto err;
     }
-    if (o2i_SCT_signature(sct, (const unsigned char **)&dec, declen) <= 0)
+
+    p = dec;
+    if (o2i_SCT_signature(sct, &p, declen) <= 0)
         goto err;
     OPENSSL_free(dec);
     dec = NULL;
@@ -116,9 +124,10 @@ SCT *SCT_new_from_base64(unsigned char version, const char *logid_base64,
 }
 
 /*
- * This methods returns: 1 on Success,
- * 0 on decoding failure,
- * -1 on internal (malloc) failure, or invalid parameter if any.
+ * Allocate, build and returns a new |ct_log| from input |pkey_base64|
+ * It returns 1 on success,
+ * 0 on decoding failure, or invalid parameter if any
+ * -1 on internal (malloc) failure
  */
 int CTLOG_new_from_base64(CTLOG **ct_log, const char *pkey_base64, const char *name)
 {
@@ -148,7 +157,7 @@ int CTLOG_new_from_base64(CTLOG **ct_log, const char *pkey_base64, const char *n
     *ct_log = CTLOG_new(pkey, name);
     if (*ct_log == NULL) {
         EVP_PKEY_free(pkey);
-        return -1;
+        return 0;
     }
 
     return 1;