<commit_before>"use strict";

var crypto = require("crypto"),
    assert = require("assert");

var carn = function (param) {
    return param ? param.split("&").sort().join("&") : "";
};

exports.sign = function (requestOptions, options, payload) {
    // var now = new Date("Fri, 25 May 2012 00:24:53 GMT");
    var now = new Date();
    requestOptions.host = "glacier." + options.Region + ".amazonaws.com";

    requestOptions.headers.Host = "glacier." + options.Region + ".amazonaws.com";
    requestOptions.headers.Date = now.toISOString().replace(/-/g, "").replace(/:/g, "").substring(0, 15) + "Z";
    requestOptions.headers["x-amz-glacier-version"] = "2012-06-01";
    requestOptions.headers["x-amz-date"] = requestOptions.headers.Date;

    var carnonicalRequest = "";
    carnonicalRequest += requestOptions.method + "\n";
    carnonicalRequest += requestOptions.path.split("?")[0] + "\n";
    carnonicalRequest += carn(requestOptions.path.split("?")[1]) + "\n";
    carnonicalRequest += "host:" + requestOptions.host + "\n";
    carnonicalRequest += "x-amz-date:" + requestOptions.headers.Date + "\n";
    carnonicalRequest += "x-amz-glacier-version:" + requestOptions.headers["x-amz-glacier-version"] + "\n";
    carnonicalRequest += "\n";
    carnonicalRequest += "host;x-amz-date;x-amz-glacier-version\n";
    carnonicalRequest += crypto.createHash("sha256").update(payload ? payload : "").digest("hex");
    // console.info("The carnonical request:\n" + carnonicalRequest);

    var stringToSign = "";
    stringToSign += "AWS4-HMAC-SHA256\n";
    stringToSign += requestOptions.headers.Date + "\n";
    stringToSign += requestOptions.headers.Date.substring(0, 8) + "/" + options.Region + "/glacier/aws4_request\n";
    stringToSign += crypto.createHash("sha256").update(carnonicalRequest).digest("hex");
    // console.info("String to sign:\n" + stringToSign);

    var kDate       = crypto.createHmac("sha256", "AWS4" + options.SecretKey).update(requestOptions.headers.Date.substring(0, 8)).digest("binary");
    var kRegion     = crypto.createHmac("sha256", kDate).update(options.Region).digest("binary");
    var kService    = crypto.createHmac("sha256", kRegion).update("glacier").digest("binary");
    var kSigning    = crypto.createHmac("sha256", kService).update("aws4_request").digest("binary");
    var signature   = crypto.createHmac("sha256", kSigning).update(stringToSign).digest("hex");
    // console.info("Signature:\n" + signature);
    requestOptions.headers.Authorization = "AWS4-HMAC-SHA256 " + "Credential=" + options.AccessKeyId + "/" + requestOptions.headers.Date.substring(0, 8) + "/" + options.Region + "/glacier/aws4_request," + "SignedHeaders=host;x-amz-date;x-amz-glacier-version," + "Signature=" + signature;
    return null;
};
<commit_msg>Changed to hash rather than payload<commit_after>"use strict";

var crypto = require("crypto"),
    assert = require("assert");

var carn = function (param) {
    return param ? param.split("&").sort().join("&") : "";
};

exports.sign = function (requestOptions, options, payloadHash) {
    // var now = new Date("Fri, 25 May 2012 00:24:53 GMT");
    var now = new Date();
    requestOptions.host = "glacier." + options.Region + ".amazonaws.com";

    requestOptions.headers.Host = "glacier." + options.Region + ".amazonaws.com";
    requestOptions.headers.Date = now.toISOString().replace(/-/g, "").replace(/:/g, "").substring(0, 15) + "Z";
    requestOptions.headers["x-amz-glacier-version"] = "2012-06-01";
    requestOptions.headers["x-amz-date"] = requestOptions.headers.Date;

    var carnonicalRequest = "";
    carnonicalRequest += requestOptions.method + "\n";
    carnonicalRequest += requestOptions.path.split("?")[0] + "\n";
    carnonicalRequest += carn(requestOptions.path.split("?")[1]) + "\n";
    carnonicalRequest += "host:" + requestOptions.host + "\n";
    carnonicalRequest += "x-amz-date:" + requestOptions.headers.Date + "\n";
    carnonicalRequest += "x-amz-glacier-version:" + requestOptions.headers["x-amz-glacier-version"] + "\n";
    carnonicalRequest += "\n";
    carnonicalRequest += "host;x-amz-date;x-amz-glacier-version\n";
    carnonicalRequest += payloadHash ? payloadHash : crypto.createHash("sha256").update("").digest("hex");
    // console.info("The carnonical request:\n" + carnonicalRequest);

    var stringToSign = "";
    stringToSign += "AWS4-HMAC-SHA256\n";
    stringToSign += requestOptions.headers.Date + "\n";
    stringToSign += requestOptions.headers.Date.substring(0, 8) + "/" + options.Region + "/glacier/aws4_request\n";
    stringToSign += crypto.createHash("sha256").update(carnonicalRequest).digest("hex");
    // console.info("String to sign:\n" + stringToSign);

    var kDate       = crypto.createHmac("sha256", "AWS4" + options.SecretKey).update(requestOptions.headers.Date.substring(0, 8)).digest("binary");
    var kRegion     = crypto.createHmac("sha256", kDate).update(options.Region).digest("binary");
    var kService    = crypto.createHmac("sha256", kRegion).update("glacier").digest("binary");
    var kSigning    = crypto.createHmac("sha256", kService).update("aws4_request").digest("binary");
    var signature   = crypto.createHmac("sha256", kSigning).update(stringToSign).digest("hex");
    // console.info("Signature:\n" + signature);
    requestOptions.headers.Authorization = "AWS4-HMAC-SHA256 " + "Credential=" + options.AccessKeyId + "/" + requestOptions.headers.Date.substring(0, 8) + "/" + options.Region + "/glacier/aws4_request," + "SignedHeaders=host;x-amz-date;x-amz-glacier-version," + "Signature=" + signature;
    return null;
};

{'fraction_non_alphanumeric': 0.18814709032488397, 'fraction_numerical': 0.02284898250624777, 'mean_word_length': 4.326045627376426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6044129', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1793, 'n_words': 285}