Commit 4bc6d8e7 authored by Ryo33's avatar Ryo33

Make *Algorithm modules case-insensitive

parent 711dbb65
open Core
type t = Sha1 | Sha256
let of_string value =
let value = String.lowercase value in
match value with
let of_string = function
| "sha1" -> Some Sha1
| "sha256" -> Some Sha256
| _ -> None
......
open Core
type t = RSA
let of_string value =
let value = String.lowercase value in
match value with
let of_string = function
| "rsa" -> Some RSA
| _ -> None
let to_string = function
| RSA -> "RSA"
| RSA -> "rsa"
......@@ -8,10 +8,8 @@ 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" (Some Sha256) (of_string "sHa256");
Test.(check (option hash_algorithm)) "sha257" None (of_string "Sha257")
Test.(check (option hash_algorithm)) "Sha256" None (of_string "Sha256")
let test_to_string () =
Test.(check string) "sha1" "sha1" (to_string Sha1);
......
......@@ -8,12 +8,11 @@ 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")
Test.(check (option public_key_algorithm)) "RSA" None (of_string "RSA");
Test.(check (option public_key_algorithm)) "Rsa" None (of_string "rSa")
let test_to_string () =
Test.(check string) "RSA" "RSA" (to_string RSA)
Test.(check string) "RSA" "rsa" (to_string RSA)
let public_key_algorithm_tests = [
"of_string", `Quick, test_of_string;
......
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