"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "generateDigestAuthHeader", {
    enumerable: true,
    get: function() {
        return generateDigestAuthHeader;
    }
});
const _nodecrypto = require("node:crypto");
function generateDigestAuthHeader(params) {
    const { username, password, method, uri, realm, nonce, qop, nc, cnonce } = params;
    const ha1 = (0, _nodecrypto.createHash)("md5").update(`${username}:${realm}:${password}`).digest("hex");
    const ha2 = (0, _nodecrypto.createHash)("md5").update(`${method}:${uri}`).digest("hex");
    let response;
    let authHeader;
    if (qop) {
        response = (0, _nodecrypto.createHash)("md5").update(`${ha1}:${nonce}:${nc}:${cnonce}:${qop}:${ha2}`).digest("hex");
        authHeader = `Digest username="${username}", realm="${realm}", nonce="${nonce}", uri="${uri}", qop=${qop}, nc=${nc}, cnonce="${cnonce}", response="${response}"`;
    } else {
        response = (0, _nodecrypto.createHash)("md5").update(`${ha1}:${nonce}:${ha2}`).digest("hex");
        authHeader = `Digest username="${username}", realm="${realm}", nonce="${nonce}", uri="${uri}", response="${response}"`;
    }
    return authHeader;
}

//# sourceMappingURL=digest-auth.util.js.map