Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Fix hmac bindings #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/NodeCrypto.re
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module Hmac: {
type t;
let create: ([ | `SHA256 | `SHA512 | `SHA384 | `SHA1 | `MD5], string) => t;
let appendString: (t, string) => unit;
let appendBuffer: (t, NodeBuffer.t) => unit;
let appendString: (t, string) => t;
let appendBuffer: (t, NodeBuffer.t) => t;
let toBase64: t => string;
let toHex: t => string;
let toBuffer: t => NodeBuffer.t;
} = {
type t;
[@bs.module "crypto"]
external create :
external create:
(
[@bs.string] [
| [@bs.as "sha256"] `SHA256
Expand All @@ -22,14 +23,15 @@ module Hmac: {
t =
"createHmac";
[@bs.send]
external update :
(t, [@bs.unwrap] [ | `String(string) | `Buffer(NodeBuffer.t)]) => unit =
external update:
(t, [@bs.unwrap] [ | `String(string) | `Buffer(NodeBuffer.t)]) => t =
"";
let appendString = (hmac, str) => update(hmac, `String(str));
let appendBuffer = (hmac, buffer) => update(hmac, `Buffer(buffer));
[@bs.send] external digest : (t, Js.Nullable.t(string)) => 'a = "";
[@bs.send] external digest: (t, Js.Nullable.t(string)) => 'a = "";
let toBase64: t => string =
hmac => digest(hmac, Js.Nullable.return("base64"));
let toHex: t => string = hmac => digest(hmac, Js.Nullable.return("hex"));
let toBuffer: t => NodeBuffer.t =
hmac => digest(hmac, Js.Nullable.undefined);
};
Expand All @@ -44,7 +46,7 @@ module Hash: {
} = {
type t;
[@bs.module "crypto"]
external create :
external create:
(
[@bs.string]
[
Expand All @@ -58,14 +60,14 @@ module Hash: {
t =
"createHash";
[@bs.send]
external update :
external update:
(t, [@bs.unwrap] [ | `String(string) | `Buffer(NodeBuffer.t)]) => unit =
"";
let appendString = (hmac, str) => update(hmac, `String(str));
let appendBuffer = (hmac, buffer) => update(hmac, `Buffer(buffer));
[@bs.send] external digest : (t, Js.Nullable.t(string)) => 'a = "";
[@bs.send] external digest: (t, Js.Nullable.t(string)) => 'a = "";
let toBase64: t => string =
hmac => digest(hmac, Js.Nullable.return("base64"));
let toBuffer: t => NodeBuffer.t =
hmac => digest(hmac, Js.Nullable.undefined);
};
};