const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
const require_forge$1 = require('./forge.cjs');
const require_util$1 = require('./util.cjs');
const require_md$1 = require('./md.cjs');

//#region ../../node_modules/node-forge/lib/hmac.js
var require_hmac = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/node-forge/lib/hmac.js": ((exports, module) => {
	/**
	* Hash-based Message Authentication Code implementation. Requires a message
	* digest object that can be obtained, for example, from forge.md.sha1 or
	* forge.md.md5.
	*
	* @author Dave Longley
	*
	* Copyright (c) 2010-2012 Digital Bazaar, Inc. All rights reserved.
	*/
	var forge = require_forge$1.default;
	require_md$1.default;
	require_util$1.default;
	var hmac = module.exports = forge.hmac = forge.hmac || {};
	/**
	* Creates an HMAC object that uses the given message digest object.
	*
	* @return an HMAC object.
	*/
	hmac.create = function() {
		var _key = null;
		var _md = null;
		var _ipadding = null;
		var _opadding = null;
		var ctx = {};
		/**
		* Starts or restarts the HMAC with the given key and message digest.
		*
		* @param md the message digest to use, null to reuse the previous one,
		*           a string to use builtin 'sha1', 'md5', 'sha256'.
		* @param key the key to use as a string, array of bytes, byte buffer,
		*           or null to reuse the previous key.
		*/
		ctx.start = function(md, key) {
			if (md !== null) if (typeof md === "string") {
				md = md.toLowerCase();
				if (md in forge.md.algorithms) _md = forge.md.algorithms[md].create();
				else throw new Error("Unknown hash algorithm \"" + md + "\"");
			} else _md = md;
			if (key === null) key = _key;
			else {
				if (typeof key === "string") key = forge.util.createBuffer(key);
				else if (forge.util.isArray(key)) {
					var tmp = key;
					key = forge.util.createBuffer();
					for (var i = 0; i < tmp.length; ++i) key.putByte(tmp[i]);
				}
				var keylen = key.length();
				if (keylen > _md.blockLength) {
					_md.start();
					_md.update(key.bytes());
					key = _md.digest();
				}
				_ipadding = forge.util.createBuffer();
				_opadding = forge.util.createBuffer();
				keylen = key.length();
				for (var i = 0; i < keylen; ++i) {
					var tmp = key.at(i);
					_ipadding.putByte(54 ^ tmp);
					_opadding.putByte(92 ^ tmp);
				}
				if (keylen < _md.blockLength) {
					var tmp = _md.blockLength - keylen;
					for (var i = 0; i < tmp; ++i) {
						_ipadding.putByte(54);
						_opadding.putByte(92);
					}
				}
				_key = key;
				_ipadding = _ipadding.bytes();
				_opadding = _opadding.bytes();
			}
			_md.start();
			_md.update(_ipadding);
		};
		/**
		* Updates the HMAC with the given message bytes.
		*
		* @param bytes the bytes to update with.
		*/
		ctx.update = function(bytes) {
			_md.update(bytes);
		};
		/**
		* Produces the Message Authentication Code (MAC).
		*
		* @return a byte buffer containing the digest value.
		*/
		ctx.getMac = function() {
			var inner = _md.digest().bytes();
			_md.start();
			_md.update(_opadding);
			_md.update(inner);
			return _md.digest();
		};
		ctx.digest = ctx.getMac;
		return ctx;
	};
}) });

//#endregion
Object.defineProperty(exports, 'default', {
  enumerable: true,
  get: function () {
    return require_hmac();
  }
});
//# sourceMappingURL=hmac.cjs.map