| "use strict"; |
| var __importDefault = (this && this.__importDefault) || function (mod) { |
| return (mod && mod.__esModule) ? mod : { "default": mod }; |
| }; |
| Object.defineProperty(exports, "__esModule", { value: true }); |
| const native_1 = __importDefault(require("./native")); |
| const hash_fn_1 = require("../base/hash-fn"); |
| |
| |
| |
| exports.normalizeInput = (input, encoding) => { |
| if (input instanceof Buffer) { |
| return input; |
| } |
| if (typeof input === 'string') { |
| return Buffer.from(input, encoding); |
| } |
| return Buffer.from(input); |
| }; |
| |
| |
| |
| function hash(input, { length = hash_fn_1.defaultHashLength } = {}) { |
| return native_1.default.hash(exports.normalizeInput(input), length); |
| } |
| exports.hash = hash; |
| |
| |
| |
| |
| |
| function deriveKey(context, material, { length = hash_fn_1.defaultHashLength } = {}) { |
| const hasher = new native_1.default.Hasher(undefined, context); |
| hasher.update(exports.normalizeInput(material)); |
| const result = Buffer.alloc(length); |
| hasher.digest(result); |
| return result; |
| } |
| exports.deriveKey = deriveKey; |
| |
| |
| |
| function keyedHash(key, input, { length = hash_fn_1.defaultHashLength } = {}) { |
| const hasher = new native_1.default.Hasher(key); |
| hasher.update(exports.normalizeInput(input)); |
| const result = Buffer.alloc(length); |
| hasher.digest(result); |
| return result; |
| } |
| exports.keyedHash = keyedHash; |
| |