From 08ac3cedc3c12b74db91fc88f7e7dcd7be706fcf Mon Sep 17 00:00:00 2001 From: Ville Saukkonen Date: Tue, 3 Dec 2019 16:15:52 +0200 Subject: [PATCH] fix hmac bindings --- src/NodeCrypto.re | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/NodeCrypto.re b/src/NodeCrypto.re index 35ba9ff..4950eb1 100644 --- a/src/NodeCrypto.re +++ b/src/NodeCrypto.re @@ -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 @@ -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); }; @@ -44,7 +46,7 @@ module Hash: { } = { type t; [@bs.module "crypto"] - external create : + external create: ( [@bs.string] [ @@ -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); -}; \ No newline at end of file +};