1
module CryptoFileTests.Tests
7 printfn
"===== Unit tests"
8 CryptoFile.UnitTests.runAllUnitTests
()
9 printfn
"===== Unit tests OK"
11 printfn
"===== API tests"
12 let plainFilename = "test.txt"
13 let cipherFilename = "test.cipher"
14 let fileContent = "Screw the NSA"
16 File.WriteAllText (plainFilename, fileContent)
18 let keyCryptPub, keyCryptPriv
= API.generatKeysPair
19 let keySigPub, keySigPriv
= API.generatKeysPair
22 API.encryptFile
plainFilename cipherFilename keySigPriv keyCryptPub
25 API.decryptFile
cipherFilename "." keySigPub keyCryptPriv
27 let writeByteToCipherFileAt byte
position =
28 using
(new FileStream (cipherFilename, FileMode.Open, FileAccess.Write))
29 (fun fs
-> fs
.Position <- position
30 fs
.Write ([| byte |], 0, 1))
33 File.Delete plainFilename
35 assert (File.ReadAllText plainFilename = fileContent)
37 printfn
"== Altering the MAC..."
38 writeByteToCipherFileAt 0uy 0L
43 | error -> assert (error :? IntegrityError)
45 printfn
"== Altering the signature..."
47 writeByteToCipherFileAt 0uy 32L
52 | error -> assert (error :? SignatureMismatch)
54 printfn
"== Altering the keys..."
56 writeByteToCipherFileAt 0uy (32L + 256L)
61 | error -> assert (error :? UnableToDecryptAESKeys)
63 printfn
"== Altering the cyphering..."
65 writeByteToCipherFileAt 0uy (32L + 256L + 256L)
70 | error -> assert (error :? IntegrityError)
72 File.Delete cipherFilename
73 File.Delete plainFilename
75 printfn
"===== API tests OK"