Skip to content

Commit

Permalink
[Plugin API] Add functions for commonly used hash sums (MD5, SHA1, SH…
Browse files Browse the repository at this point in the history
…A256/512, Blake2)
  • Loading branch information
dmbaturin committed Mar 6, 2024
1 parent efd2b39 commit dc2f4d4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/helpers/hash.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,27 @@ let blake2s s =
let ctx = Digestif.BLAKE2S.feed_string ctx s in
Digestif.BLAKE2S.get ctx |> Digestif.BLAKE2S.to_hex

let blake2b s =
let ctx = Digestif.BLAKE2B.empty in
let ctx = Digestif.BLAKE2B.feed_string ctx s in
Digestif.BLAKE2B.get ctx |> Digestif.BLAKE2B.to_hex

let md5 s =
let ctx = Digestif.MD5.empty in
let ctx = Digestif.MD5.feed_string ctx s in
Digestif.MD5.get ctx |> Digestif.MD5.to_hex

let sha1 s =
let ctx = Digestif.SHA1.empty in
let ctx = Digestif.SHA1.feed_string ctx s in
Digestif.SHA1.get ctx |> Digestif.SHA1.to_hex

let sha256 s =
let ctx = Digestif.SHA256.empty in
let ctx = Digestif.SHA256.feed_string ctx s in
Digestif.SHA256.get ctx |> Digestif.SHA256.to_hex

let sha512 s =
let ctx = Digestif.SHA512.empty in
let ctx = Digestif.SHA512.feed_string ctx s in
Digestif.SHA512.get ctx |> Digestif.SHA512.to_hex
9 changes: 9 additions & 0 deletions src/plugin_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,15 @@ struct
"to_list_of_tables", V.efunc (V.list (V.list V.string) **->> V.list V.value) csv_to_table_list;
] g;

C.register_module "Digest" [
"md5", V.efunc (V.string **->> V.string) Hash.md5;
"sha1", V.efunc (V.string **->> V.string) Hash.sha1;
"sha256", V.efunc (V.string **->> V.string) Hash.sha256;
"sha512", V.efunc (V.string **->> V.string) Hash.sha512;
"blake2s", V.efunc (V.string **->> V.string) Hash.blake2s;
"blake2b", V.efunc (V.string **->> V.string) Hash.blake2b;
] g;

C.register_module "Date" [
"reformat", V.efunc (V.string **-> V.list V.string **-> V.string **->> V.option V.string) reformat_date;
"to_timestamp", V.efunc (V.string **-> V.list V.string **->> V.option V.int) to_timestamp;
Expand Down

0 comments on commit dc2f4d4

Please sign in to comment.