X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=labo2-fsharp%2FCryptoFileTests%2FTests.fs;h=eb8a2902805fe33956e32b1309f771c1a70028ec;hb=0508ca9ddb817b14ca747f8736ea1960cb70d2e7;hp=dd1b3e04ba9b5848d324f7784a8887cfce505adf;hpb=61a8b3492e89e883b23c158eb52ba2b070234df8;p=crypto_lab2.git diff --git a/labo2-fsharp/CryptoFileTests/Tests.fs b/labo2-fsharp/CryptoFileTests/Tests.fs index dd1b3e0..eb8a290 100644 --- a/labo2-fsharp/CryptoFileTests/Tests.fs +++ b/labo2-fsharp/CryptoFileTests/Tests.fs @@ -24,10 +24,12 @@ let doSomeTests () = let decrypt () = API.decryptFile cipherFilename "." keySigPub keyCryptPriv - let writeByteToCipherFileAt byte position = - using (new FileStream (cipherFilename, FileMode.Open, FileAccess.Write)) + let incrementByteCipherFileAt position = + using (new FileStream (cipherFilename, FileMode.Open, FileAccess.ReadWrite)) (fun fs -> fs.Position <- position - fs.Write ([| byte |], 0, 1)) + let byte = fs.ReadByte () |> byte + fs.Position <- position + fs.Write ([| byte + 1uy |], 0, 1)) // Automatically modulo 256. encrypt () File.Delete plainFilename @@ -35,7 +37,7 @@ let doSomeTests () = assert (File.ReadAllText plainFilename = fileContent) printfn "== Altering the MAC..." - writeByteToCipherFileAt 0uy 0L + incrementByteCipherFileAt 0L try decrypt () assert false @@ -44,7 +46,7 @@ let doSomeTests () = printfn "== Altering the signature..." encrypt () - writeByteToCipherFileAt 0uy 32L + incrementByteCipherFileAt 32L try decrypt () assert false @@ -53,16 +55,16 @@ let doSomeTests () = printfn "== Altering the keys..." encrypt () - writeByteToCipherFileAt 0uy (32L + 256L) + incrementByteCipherFileAt (32L + 256L) try decrypt () assert false with | error -> assert (error :? UnableToDecryptAESKeys) - printfn "== Altering the cyphering..." + printfn "== Altering the cyphertext..." encrypt () - writeByteToCipherFileAt 0uy (32L + 256L + 256L) + incrementByteCipherFileAt (32L + 256L + 256L) try decrypt () assert false