diff dcrypt/crypto/macs/HMAC.d @ 28:ad687db713a4

Further reworked the code for hash padding. Replaced all instances of 'char[]' with 'string' and removed a few 'const' modifiers as per Glenn Haecker's patch for D2 compatibility. Updated CONTRIBUTORS file.
author Thomas Dixon <reikon@reikon.us>
date Sun, 10 May 2009 22:38:48 -0400
parents 8b5eaf3c2979
children b9ba770b8f16
line wrap: on
line diff
--- a/dcrypt/crypto/macs/HMAC.d	Sat May 09 23:29:20 2009 -0400
+++ b/dcrypt/crypto/macs/HMAC.d	Sun May 10 22:38:48 2009 -0400
@@ -83,7 +83,7 @@
         hash.update(input_);
     }
     
-    char[] name()
+    string name()
     {
         return "HMAC-"~hash.name;
     }
@@ -116,7 +116,7 @@
         return r;
     }
     
-    char[] hexDigest()
+    string hexDigest()
     {
         return ByteConverter.hexEncode(digest());
     }
@@ -134,7 +134,7 @@
     {
         unittest
         {
-            static char[][] test_keys = [
+            static string[] test_keys = [
                 "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
                 "4a656665", // Jefe?
                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@@ -144,7 +144,7 @@
                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
             ];
             
-            static char[][] test_inputs = [
+            static string[] test_inputs = [
                 "4869205468657265",
                 "7768617420646f2079612077616e7420666f72206e6f7468696e673f",
                 "dd",
@@ -156,7 +156,7 @@
                 1, 1, 50, 1
             ];
             
-            static const char[][] test_results = [
+            static const string[] test_results = [
                 "b617318655057264e28bc0b6fb378c8ef146be00",
                 "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79",
                 "125d7342b9ac11cd91a39af48aa17b4f63f175d3",
@@ -164,12 +164,12 @@
             ];
             
             HMAC h = new HMAC(new SHA1());
-            foreach (uint i, char[] k; test_keys)
+            foreach (uint i, string k; test_keys)
             {
                 h.init(new SymmetricKey(ByteConverter.hexDecode(k)));
                 for (int j = 0; j < test_repeat[i]; j++)
                     h.update(ByteConverter.hexDecode(test_inputs[i]));
-                char[] mac = h.hexDigest();
+                string mac = h.hexDigest();
                 assert(mac == test_results[i], 
                         h.name~": ("~mac~") != ("~test_results[i]~")");
             }