UNPKG

aws-crt

Version:

NodeJS bindings to the aws-c-* libraries

127 lines 4.29 kB
"use strict"; /* * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const binding_1 = __importDefault(require("./binding")); const native_resource_1 = require("./native_resource"); /** * Object that allows for continuous hashing of data. */ class Hash extends native_resource_1.NativeResource { /** * Apply data to the hash. */ update(data) { binding_1.default.hash_update(this.native_handle(), data); } /** * Completes the hash computation and returns the final digest. * * @param truncate_to The maximum number of bytes to receive. Leave as undefined or 0 to receive the entire digest. */ finalize(truncate_to) { return binding_1.default.hash_digest(this.native_handle(), truncate_to); } constructor(hash_handle) { super(hash_handle); } } /** * Object that allows for continuous MD5 hashing of data. */ class Md5Hash extends Hash { constructor() { super(binding_1.default.hash_md5_new()); } } exports.Md5Hash = Md5Hash; /** * Computes an MD5 hash. Use this if you don't need to stream the data you're hashing and can load the entire input * into memory. * * @param data The data to hash * @param truncate_to The maximum number of bytes to receive. Leave as undefined or 0 to receive the entire digest. */ function hash_md5(data, truncate_to) { return binding_1.default.hash_md5_compute(data, truncate_to); } exports.hash_md5 = hash_md5; /** * Object that allows for continuous SHA256 hashing of data. */ class Sha256Hash extends Hash { constructor() { super(binding_1.default.hash_sha256_new()); } } exports.Sha256Hash = Sha256Hash; /** * Computes an SHA256 hash. Use this if you don't need to stream the data you're hashing and can load the entire input * into memory. * * @param data The data to hash * @param truncate_to The maximum number of bytes to receive. Leave as undefined or 0 to receive the entire digest. */ function hash_sha256(data, truncate_to) { return binding_1.default.hash_sha256_compute(data, truncate_to); } exports.hash_sha256 = hash_sha256; /** * Object that allows for continuous hashing of data with an hmac secret. */ class Hmac extends native_resource_1.NativeResource { /** * Apply data to the hash. */ update(data) { binding_1.default.hmac_update(this.native_handle(), data); } /** * Completes the hash computation and returns the final digest. * * @param truncate_to The maximum number of bytes to receive. Leave as undefined or 0 to receive the entire digest. */ finalize(truncate_to) { return binding_1.default.hmac_digest(this.native_handle(), truncate_to); } constructor(hash_handle) { super(hash_handle); } } /** * Object that allows for continuous SHA256 HMAC hashing of data. */ class Sha256Hmac extends Hmac { constructor(secret) { super(binding_1.default.hmac_sha256_new(secret)); } } exports.Sha256Hmac = Sha256Hmac; /** * Computes an SHA256 HMAC. Use this if you don't need to stream the data you're hashing and can load the entire input * into memory. * * @param secret The key to use for the HMAC process * @param data The data to hash * @param truncate_to The maximum number of bytes to receive. Leave as undefined or 0 to receive the entire digest. */ function hmac_sha256(secret, data, truncate_to) { return binding_1.default.hmac_sha256_compute(secret, data, truncate_to); } exports.hmac_sha256 = hmac_sha256; //# sourceMappingURL=crypto.js.map