Browse Source

add/fix tests

add explicit strict&loose base64-decode tests
Steffen Jaeckel 9 years ago
parent
commit
1c0edfdead
2 changed files with 17 additions and 1 deletions
  1. 16 0
      testprof/base64_test.c
  2. 1 1
      testprof/der_tests.c

+ 16 - 0
testprof/base64_test.c

@@ -56,6 +56,22 @@ int base64_test(void)
            return 1;
            return 1;
        }
        }
    }
    }
+
+   x--;
+   memmove(&out[11], &out[10], l1 - 10);
+   out[10] = '\0';
+   l1++;
+   l2 = sizeof(tmp);
+   DO(base64_decode_ex(out, l1, tmp, &l2, 0));
+   if (l2 != x || memcmp(tmp, in, x)) {
+       fprintf(stderr, "loose base64 decoding failed %lu %lu %lu", x, l1, l2);
+       print_hex("is    ", tmp, l2);
+       print_hex("should", in, x);
+       print_hex("input ", out, l1);
+       return 1;
+   }
+   l2 = sizeof(tmp);
+   DO(base64_decode_ex(out, l1, tmp, &l2, 1) == CRYPT_INVALID_PACKET ? CRYPT_OK : CRYPT_INVALID_PACKET);
    return 0;
    return 0;
 }
 }
 #endif
 #endif

+ 1 - 1
testprof/der_tests.c

@@ -392,7 +392,7 @@ static void der_cacert_test(void)
 
 
   ltc_asn1_list *decoded_list, *l, *l1, *l2;
   ltc_asn1_list *decoded_list, *l, *l1, *l2;
 
 
-  DO(base64_decode(_der_tests_cacert_root_cert, sizeof(_der_tests_cacert_root_cert), buf, &len1));
+  DO(base64_decode_ex(_der_tests_cacert_root_cert, sizeof(_der_tests_cacert_root_cert), buf, &len1, 0));
   len2 = len1;
   len2 = len1;
   DO(der_decode_sequence_flexi(buf, &len2, &decoded_list));
   DO(der_decode_sequence_flexi(buf, &len2, &decoded_list));