"use strict";
/*
 * @adonisjs/encryption
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Hmac = void 0;
const crypto_1 = require("crypto");
const helpers_1 = require("@poppinss/utils/build/helpers");
/**
 * A generic class for generating SHA-256 Hmac for verifying the value
 * integrity.
 */
class Hmac {
    constructor(key) {
        this.key = key;
    }
    /**
     * Generate the hmac
     */
    generate(value) {
        return helpers_1.base64.urlEncode((0, crypto_1.createHmac)('sha256', this.key).update(value).digest());
    }
    /**
     * Compare raw value against an existing hmac
     */
    compare(value, existingHmac) {
        return (0, helpers_1.safeEqual)(this.generate(value), existingHmac);
    }
}
exports.Hmac = Hmac;
