Typos in report + clean up.
[crypto_lab2.git] / labo2-fsharp / CryptoFileTests / Tests.fs
index 458b1be..aeea186 100644 (file)
@@ -36,7 +36,7 @@ let doSomeTests () =
     decrypt ()
     assert (File.ReadAllText plainFilename = fileContent)
 
-    printfn "== Altering the MAC..."
+    printfn "== Altering the MAC... (%d bytes)" (API.hmacSize - 1)
     for i in 0 .. API.hmacSize - 1 do
         printf "."
         encrypt ()
@@ -48,7 +48,7 @@ let doSomeTests () =
             | error -> assert (error :? IntegrityError)
     printfn ""
 
-    printfn "== Altering the signature..."
+    printfn "== Altering the signature... (%d bytes)" (API.signatureSize - 1)
     for i in 0 .. API.signatureSize - 1 do
         printf "."
         encrypt ()
@@ -60,7 +60,7 @@ let doSomeTests () =
             | error -> assert (error :? SignatureMismatch)
     printfn ""
 
-    printfn "== Altering the keys..."
+    printfn "== Altering the keys... (%d bytes)" (API.keysSize - 1)
     for i in 0 .. API.keysSize - 1 do
         printf "."
         encrypt ()
@@ -72,14 +72,18 @@ let doSomeTests () =
             | error -> assert (error :? UnableToDecryptKeys)
     printfn ""
 
-    printfn "== Altering the cyphertext..."
-    encrypt ()
-    incrementByteCipherFileAt (int64 <| API.hmacSize + API.signatureSize + API.keysSize)
-    try
-        decrypt ()
-        assert false
-    with
-        | error -> assert (error :? IntegrityError)
+    let cyphertextLength = (int (FileInfo (cipherFilename)).Length) + API.hmacSize + API.signatureSize + API.keysSize
+    printfn "== Altering the cyphertext... (%d bytes)" cyphertextLength
+    for i in 0 .. cyphertextLength do 
+        printf "."
+        encrypt ()
+        incrementByteCipherFileAt (int64 <| API.hmacSize + API.signatureSize + API.keysSize + i)
+        try
+            decrypt ()
+            assert false
+        with
+            | error -> assert (error :? IntegrityError)
+    printfn ""
 
     File.Delete cipherFilename
     File.Delete plainFilename