Commit a43d44cb authored by Ryo33's avatar Ryo33

Add HashAlgorithm

parent 830d7385
(library
(name yayakaChain)
(libraries core))
(libraries core digestif))
type t = string
type t =
| SHA1
| SHA2
let from_string = function
| "SHA-1" -> Some SHA1
| "SHA-2" -> Some SHA2
| _ -> None
let to_string = function
| SHA1 -> "SHA-1"
| SHA2 -> "SHA-2"
type t = { algorithm : string; body : string }
type t = {
hash_algorithm : HashAlgorithm.t;
signature_algorithm : string;
fingerprint : string;
body : string }
(tests
(names test power_test)
(names test power_test hash_test hashAlgorithm_test)
(libraries alcotest yayakaChain))
open YayakaChain
open HashAlgorithm
module Test = Alcotest
let pp ppf value =
match value with
| SHA1 -> Fmt.pf ppf "SHA1"
| SHA2 -> Fmt.pf ppf "SHA2"
let hash_algorithm = Test.testable pp ( = )
let test_from_string () =
Test.(check (option hash_algorithm)) "SHA-1" (Some SHA1) (from_string "SHA-1");
Test.(check (option hash_algorithm)) "SHA-2" (Some SHA2) (from_string "SHA-2");
Test.(check (option hash_algorithm)) "SHA2" None (from_string "SHA2")
let test_to_string () =
Test.(check string) "SHA-1" "SHA-1" (to_string SHA1);
Test.(check string) "SHA-2" "SHA-2" (to_string SHA2)
let hash_algorithm_tests = [
"from_string", `Quick, test_from_string;
"to_string", `Quick, test_to_string;
]
let () =
Test.run "HashAlgorithm" [
"HashAlgorithm", hash_algorithm_tests;
]
module Test = Alcotest
let hash_tests = [
]
let () =
Test.run "Hash" [
"Hash", hash_tests;
]
......@@ -8,7 +8,7 @@ let to_power value =
| Some power -> power
| _ -> raise (Failure "")
let from_int () =
let test_from_int () =
Test.(check (option int)) "0" (Some 0) (to_int_option (Power.from_int 0));
Test.(check (option int)) "1,000,000" (Some 1000000) (to_int_option (Power.from_int 1000000));
Test.(check (option int)) "2 ^ 31 - 1" (Some 2147483647) (to_int_option (Power.from_int 2147483647));
......@@ -16,14 +16,14 @@ let from_int () =
Test.(check (option int)) "-1" None (to_int_option (Power.from_int ~- 1));
Test.(check (option int)) "-1,000,000" None (to_int_option (Power.from_int ~- 1000000))
let to_int () =
let test_to_int () =
Test.(check int) "0" 0 (Power.to_int (to_power 0));
Test.(check int) "1,000,000" 1000000 (Power.to_int (to_power 1000000));
Test.(check int) "2 ^ 31 - 1" 2147483647 (Power.to_int (to_power 2147483647))
let power_tests = [
"from_int", `Quick, from_int;
"to_int", `Quick, to_int;
"from_int", `Quick, test_from_int;
"to_int", `Quick, test_to_int;
]
let () =
......
lib: [
"_build/install/default/lib/yayaka-chain/META" {"META"}
"_build/install/default/lib/yayaka-chain/opam" {"opam"}
]
doc: [
"_build/install/default/doc/yayaka-chain/LICENSE"
"_build/install/default/doc/yayaka-chain/README.md"
]
opam-version: "2.0"
version: "0.1.0"
maintainer: "ryo33@yayaka.org"
authors: ["Ryo Hashiguchi <ryo33@yayaka.org>"]
license: "AGPL"
bug-reports: "https://gitlib.com/yayaka/yayaka-chain/issues"
homepage: "https://gitlib.com/yayaka/yayaka-chain"
build-test: [
"dune runtest"
]
depends: [
"dune" {build}
"alcotest" {test}
"core"
"digestif"
]
synopsis: "Manipulates yayaka-chains"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment