Skip to content

Commit dc2f4d4

Browse files
committed
[Plugin API] Add functions for commonly used hash sums (MD5, SHA1, SHA256/512, Blake2)
1 parent efd2b39 commit dc2f4d4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/helpers/hash.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,27 @@ let blake2s s =
77
let ctx = Digestif.BLAKE2S.feed_string ctx s in
88
Digestif.BLAKE2S.get ctx |> Digestif.BLAKE2S.to_hex
99

10+
let blake2b s =
11+
let ctx = Digestif.BLAKE2B.empty in
12+
let ctx = Digestif.BLAKE2B.feed_string ctx s in
13+
Digestif.BLAKE2B.get ctx |> Digestif.BLAKE2B.to_hex
1014

15+
let md5 s =
16+
let ctx = Digestif.MD5.empty in
17+
let ctx = Digestif.MD5.feed_string ctx s in
18+
Digestif.MD5.get ctx |> Digestif.MD5.to_hex
1119

20+
let sha1 s =
21+
let ctx = Digestif.SHA1.empty in
22+
let ctx = Digestif.SHA1.feed_string ctx s in
23+
Digestif.SHA1.get ctx |> Digestif.SHA1.to_hex
24+
25+
let sha256 s =
26+
let ctx = Digestif.SHA256.empty in
27+
let ctx = Digestif.SHA256.feed_string ctx s in
28+
Digestif.SHA256.get ctx |> Digestif.SHA256.to_hex
29+
30+
let sha512 s =
31+
let ctx = Digestif.SHA512.empty in
32+
let ctx = Digestif.SHA512.feed_string ctx s in
33+
Digestif.SHA512.get ctx |> Digestif.SHA512.to_hex

src/plugin_api.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,15 @@ struct
10041004
"to_list_of_tables", V.efunc (V.list (V.list V.string) **->> V.list V.value) csv_to_table_list;
10051005
] g;
10061006

1007+
C.register_module "Digest" [
1008+
"md5", V.efunc (V.string **->> V.string) Hash.md5;
1009+
"sha1", V.efunc (V.string **->> V.string) Hash.sha1;
1010+
"sha256", V.efunc (V.string **->> V.string) Hash.sha256;
1011+
"sha512", V.efunc (V.string **->> V.string) Hash.sha512;
1012+
"blake2s", V.efunc (V.string **->> V.string) Hash.blake2s;
1013+
"blake2b", V.efunc (V.string **->> V.string) Hash.blake2b;
1014+
] g;
1015+
10071016
C.register_module "Date" [
10081017
"reformat", V.efunc (V.string **-> V.list V.string **-> V.string **->> V.option V.string) reformat_date;
10091018
"to_timestamp", V.efunc (V.string **-> V.list V.string **->> V.option V.int) to_timestamp;

0 commit comments

Comments
 (0)