let doSomeTests () =
printfn "===== Unit tests"
- CryptoFile.UnitTests.runAllUnitTests ()
+ UnitTests.runAllUnitTests ()
printfn "===== Unit tests OK"
printfn "===== API tests"
File.WriteAllText (plainFilename, fileContent)
- let keyCryptPub, keyCryptPriv = API.generatKeysPair
- let keySigPub, keySigPriv = API.generatKeysPair
+ let keyCryptPub, keyCryptPriv = API.generatKeysPair ()
+ let keySigPub, keySigPriv = API.generatKeysPair ()
let encrypt () =
API.encryptFile plainFilename cipherFilename keySigPriv keyCryptPub
API.decryptFile cipherFilename "." keySigPub keyCryptPriv
let incrementByteCipherFileAt position =
- using (new FileStream (cipherFilename, FileMode.Open, FileAccess.ReadWrite))
- (fun fs -> fs.Position <- position
- let byte = fs.ReadByte () |> byte
- fs.Position <- position
- fs.Write ([| byte + 1uy |], 0, 1)) // Automatically modulo 256.
+ use fs = new FileStream (cipherFilename, FileMode.Open, FileAccess.ReadWrite)
+ fs.Position <- position
+ let byte = fs.ReadByte () |> byte
+ fs.Position <- position
+ fs.Write ([| byte + 1uy |], 0, 1) // Modulo 256.
encrypt ()
File.Delete plainFilename
assert (File.ReadAllText plainFilename = fileContent)
printfn "== Altering the MAC..."
- incrementByteCipherFileAt 0L
- try
- decrypt ()
- assert false
- with
- | error -> assert (error :? IntegrityError)
+ for i in 0 .. API.hmacSize - 1 do
+ printf "."
+ encrypt ()
+ incrementByteCipherFileAt (int64 i)
+ try
+ decrypt ()
+ assert false
+ with
+ | error -> assert (error :? IntegrityError)
+ printfn ""
printfn "== Altering the signature..."
- encrypt ()
- incrementByteCipherFileAt 32L
- try
- decrypt ()
- assert false
- with
- | error -> assert (error :? SignatureMismatch)
+ for i in 0 .. API.signatureSize - 1 do
+ printf "."
+ encrypt ()
+ incrementByteCipherFileAt (int64 <| API.hmacSize + i)
+ try
+ decrypt ()
+ assert false
+ with
+ | error -> assert (error :? SignatureMismatch)
+ printfn ""
printfn "== Altering the keys..."
- encrypt ()
- incrementByteCipherFileAt (32L + 256L)
- try
- decrypt ()
- assert false
- with
- | error -> assert (error :? UnableToDecryptAESKeys)
+ for i in 0 .. API.keysSize - 1 do
+ printf "."
+ encrypt ()
+ incrementByteCipherFileAt (int64 <| API.hmacSize + API.signatureSize + i)
+ try
+ decrypt ()
+ assert false
+ with
+ | error -> assert (error :? UnableToDecryptKeys)
+ printfn ""
- printfn "== Altering the cyphering..."
+ printfn "== Altering the cyphertext..."
encrypt ()
- incrementByteCipherFileAt (32L + 256L + 256L)
+ incrementByteCipherFileAt (int64 <| API.hmacSize + API.signatureSize + API.keysSize)
try
decrypt ()
assert false
- with
+ with
| error -> assert (error :? IntegrityError)
File.Delete cipherFilename