3 * _| || |_/ ___| ___ _ __ _ __ ___ | |
4 * |_ .. _\___ \ / _ \ '_ \| '_ \ / _ \| |
5 * |_ _|___) | __/ |_) | |_) | (_) |_|
6 * |_||_| |____/ \___| .__/| .__/ \___/(_)
13 * Copyright (C) The #Seppo contributors. All rights reserved.
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 let hk,hv
= [("k0","v0");("k1","v1")] |> Cohttp.Cookie.Cookie_hdr.serialize
in
33 hk |> Assrt.equals_string __LOC__
"cookie";
34 hv
|> Assrt.equals_string __LOC__
"k0=v0; k1=v1";
35 let _c = Cohttp.Cookie.Set_cookie_hdr.make
43 let (hk,hv
) = _c |> Cohttp.Cookie.Set_cookie_hdr.serialize
in
44 hk |> Assrt.equals_string __LOC__
"Set-Cookie";
45 hv
|> Assrt.equals_string __LOC__
{|k
=v
=v
; :; domain
=example
.com
; path
=/foo
/bar
/; secure
; httponly
|};
47 |> Cohttp.Header.init_with
"Cookie"
48 |> Cohttp.Cookie.Cookie_hdr.extract
with
49 | [("k","v=v"); (":",""); ("domain","example.com"); ("path","/foo/bar/"); ("secure",""); ("httponly","")] ->
51 | l
-> l
|> List.length
|> Assrt.equals_int __LOC__
(-1)
57 let sec = "My secret Secret 89 123456789 12" |> Cstruct.of_string
58 and nonce
= "123456789012" |> Cstruct.of_string
in
59 let ci = "Merhaba, world!"
61 |> Cookie.encrypt
sec nonce
63 ci |> Assrt.equals_string __LOC__
"MTIzNDU2Nzg5MDEyAGoh40PQjxKT7k6hzTRa5pJ1Z6TauBDAsYaEMm2A4w";
64 ci |> Cookie.decrypt
sec
66 |> Assrt.equals_string __LOC__
"Merhaba, world!";
69 let test_chacha20 () =
70 let sec = "My secret Secret 89 123456789 12" |> Cstruct.of_string
71 and nonce
= "123456789012" |> Cstruct.of_string
in
72 assert (32 = (sec |> Cstruct.length
));
73 assert (12 = (nonce
|> Cstruct.length
));
74 let key = sec |> Mirage_crypto.Chacha20.of_secret
in
77 |> Mirage_crypto.Chacha20.authenticate_encrypt ~
key ~nonce
78 |> Mirage_crypto.Chacha20.authenticate_decrypt ~
key ~nonce
81 |> Assrt.equals_string __LOC__
"Merhaba, world!";
84 let test_chacha20_b64 () =
85 let sec = "My secret Secret 89 123456789 12" |> Cstruct.of_string
86 and nonce
= "123456789012" |> Cstruct.of_string
in
87 assert (32 = (sec |> Cstruct.length
));
88 assert (12 = (nonce
|> Cstruct.length
));
89 let key = sec |> Mirage_crypto.Chacha20.of_secret
in
92 |> Mirage_crypto.Chacha20.authenticate_encrypt ~
key ~nonce
94 |> Base64.encode_string
97 |> Mirage_crypto.Chacha20.authenticate_decrypt ~
key ~nonce
100 |> Assrt.equals_string __LOC__
"Merhaba, world!";
104 Mirage_crypto_rng_lwt.initialize
(module Mirage_crypto_rng.Fortuna
);
105 Unix.chdir
"../../../test/";
109 test_chacha20_b64 ();