...
 
Commits (4)
type t =
| AddPublicKey of {
algorithm : string;
key : string;
power : Power.t }
| RemovePublicKey of {
fingerprint : string }
| UpdatePower of {
fingerprint : string;
power : Power.t }
| UserCommand of {
protocol : string;
body : string }
| Halt
type t = { algorithm : HashAlgorithm.t; hash : string }
val hash : HashAlgorithm.t -> string -> t
(** computes a hash for the given string. *)
val format : t -> ( string * string )
(** formats the given hash for block. *)
type t =
| Sha1
| Sha256
open Core
let of_string = function
type t = Sha1 | Sha256
let of_string value =
let value = String.lowercase value in
match value with
| "sha1" -> Some Sha1
| "sha256" -> Some Sha256
| _ -> None
......
type t = Sha1 | Sha256
val of_string : string -> t option
val to_string : t -> string
type t = {
hash_algorithm : HashAlgorithm.t;
hash : string }
hash : string;
expires_at : ExpirationDateTime.t }
type t
val of_int : int -> t option
(** convert int to Power.t *)
(** converts int to Power.t.*)
val to_int : t -> int
(** convert Power.t to power *)
(** converts Power.t to power. *)
type t = {
algorithm : PublicKeyAlgorithm.t;
key : string;
fingerprint_algorithm : HashAlgorithm.t;
power : Power.t }
let fingerprint { fingerprint_algorithm; key; _ } =
let Hash.{ hash; _ } = Hash.hash fingerprint_algorithm key in
Base64.encode_exn hash
type t = {
algorithm : PublicKeyAlgorithm.t;
key : string;
fingerprint_algorithm : HashAlgorithm.t;
power : Power.t }
val fingerprint : t -> string
open Core
type t = RSA
let of_string value =
let value = String.lowercase value in
match value with
| "rsa" -> Some RSA
| _ -> None
let to_string = function
| RSA -> "RSA"
type t = RSA
val of_string : string -> t option
val to_string : t -> string
(tests
(names power_test hash_test hashAlgorithm_test)
(names power_test hash_test hashAlgorithm_test publicKey_test publicKeyAlgorithm_test)
(libraries alcotest yayakaChain))
......@@ -2,17 +2,16 @@ open YayakaChain
open HashAlgorithm
module Test = Alcotest
let pp ppf value =
match value with
| Sha1 -> Fmt.pf ppf "Sha1"
| Sha256 -> Fmt.pf ppf "Sha256"
let pp ppf value = Fmt.pf ppf "%s" (to_string value)
let hash_algorithm = Test.testable pp ( = )
let test_of_string () =
Test.(check (option hash_algorithm)) "sha1" (Some Sha1) (of_string "sha1");
Test.(check (option hash_algorithm)) "SHA1" (Some Sha1) (of_string "SHA1");
Test.(check (option hash_algorithm)) "sha256" (Some Sha256) (of_string "sha256");
Test.(check (option hash_algorithm)) "Sha256" None (of_string "Sha256")
Test.(check (option hash_algorithm)) "sHa256" (Some Sha256) (of_string "sHa256");
Test.(check (option hash_algorithm)) "sha257" None (of_string "Sha257")
let test_to_string () =
Test.(check string) "sha1" "sha1" (to_string Sha1);
......
open Core
open YayakaChain
module Test = Alcotest
open Support
let to_int_option = Option.map ~f:Power.to_int
let to_power value =
match (Power.of_int value) with
| Some power -> power
| _ -> raise (Failure "")
let test_of_int () =
Test.(check (option int)) "0" (Some 0) (to_int_option (Power.of_int 0));
......
open YayakaChain
open PublicKeyAlgorithm
module Test = Alcotest
let pp ppf value = Fmt.pf ppf "%s" (to_string value)
let public_key_algorithm = Test.testable pp ( = )
let test_of_string () =
Test.(check (option public_key_algorithm)) "rsa" (Some RSA) (of_string "rsa");
Test.(check (option public_key_algorithm)) "RSA" (Some RSA) (of_string "RSA");
Test.(check (option public_key_algorithm)) "rSa" (Some RSA) (of_string "rSa");
Test.(check (option public_key_algorithm)) "RSA2" None (of_string "RSA2")
let test_to_string () =
Test.(check string) "RSA" "RSA" (to_string RSA)
let public_key_algorithm_tests = [
"of_string", `Quick, test_of_string;
"to_string", `Quick, test_to_string;
]
let () =
Test.run "PublicKeyAlgorithm" [
"PublicKeyAlgorithm", public_key_algorithm_tests;
]
open YayakaChain
module Test = Alcotest
open Support
let test_fingerprint () =
Test.(check string) "public key 1"
"+gf0YWKHMzO0/mCFlB9AivKRlD0="
(PublicKey.fingerprint {
algorithm = PublicKeyAlgorithm.RSA;
fingerprint_algorithm = HashAlgorithm.Sha1;
power = to_power 1;
key = "-----BEGIN PUBLIC KEY-----\n\
MB4wDQYJKoZIhvcNAQEBBQADDQAwCgIDAOCHAgMBAAE=\n\
-----END PUBLIC KEY-----\n" });
Test.(check string) "public key 2"
"s71Ok1G01SONnQB8hirmj/ZDgb8="
(PublicKey.fingerprint {
algorithm = PublicKeyAlgorithm.RSA;
fingerprint_algorithm = HashAlgorithm.Sha1;
power = to_power 1;
key = "-----BEGIN PUBLIC KEY-----\n\
MB4wDQYJKoZIhvcNAQEBBQADDQAwCgIDALy/AgMBAAE=\n\
-----END PUBLIC KEY-----\n" })
let public_key_tests = [
"fingerprint", `Quick, test_fingerprint
]
let () =
Test.run "PublicKey" [
"PublicKey", public_key_tests
]
open YayakaChain
let to_power value =
match (Power.of_int value) with
| Some power -> power
| _ -> raise (Failure "")