<commit_before>"use strict";
var expect = require("chai").expect;
var jwa = require("../lib/jwa/jwa");
var alg;

describe("jwa", function() {
	describe("dir", function() {
		before(function() {
			alg = jwa("dir");
		});

		it("should not throw an error when getting the algorithm", function() {
			expect(jwa("dir")).to.not.throw;
		});

		it("should be able to wrap a key", function() {
			var contentKey = new Buffer(0);
			var mgmtKey = new Buffer(16);
			var enc = alg.wrapKey(contentKey, mgmtKey);
			expect(Buffer.isBuffer(enc)).to.be.true;
			expect(enc).to.have.length(0);
		});

		it("should be able to unwrap a key", function() {
			var contentKey = new Buffer(0);
			var mgmtKey = new Buffer(16);
			var enc = alg.wrapKey(contentKey, mgmtKey);
			var plain = alg.unwrapKey(enc, mgmtKey);
			expect(Buffer.isBuffer(plain)).to.be.true;
			expect(mgmtKey.equals(plain)).to.be.true;
		});

		it("should throw if the unencrypted contentKey is of non-zero length on wrapping", function() {
			var contentKey = new Buffer(1);
			var mgmtKey = new Buffer(16);
			expect(function(){alg.wrapKey(contentKey, mgmtKey);}).to.throw(/contentKey must have a length of zero/);
		});

		it("should throw if the encrypted contentKey is of non-zero length on unwrapping", function() {
			var encKey = new Buffer(1);
			var mgmtKey = new Buffer(16);
			expect(function(){alg.unwrapKey(encKey, mgmtKey);}).to.throw(/encKey must have a length of zero/);
		});

		it.skip("shouldn't be able to unwrap a key with the wrong key", function() {
			var contentKey = new Buffer(0);
			var mgmtKey = new Buffer(16);
			var mgmtKey2 = new Buffer(16);
			var enc = alg.wrapKey(contentKey, mgmtKey);
			expect(function() {alg.unwrapKey(enc, mgmtKey2);}).to.throw(Error);
		});
	});
});<commit_msg>Direct Encryption can't have a wrong key<commit_after>"use strict";
var expect = require("chai").expect;
var jwa = require("../lib/jwa/jwa");
var alg;

describe("jwa", function() {
	describe("dir", function() {
		before(function() {
			alg = jwa("dir");
		});

		it("should not throw an error when getting the algorithm", function() {
			expect(jwa("dir")).to.not.throw;
		});

		it("should be able to wrap a key", function() {
			var contentKey = new Buffer(0);
			var mgmtKey = new Buffer(16);
			var enc = alg.wrapKey(contentKey, mgmtKey);
			expect(Buffer.isBuffer(enc)).to.be.true;
			expect(enc).to.have.length(0);
		});

		it("should be able to unwrap a key", function() {
			var contentKey = new Buffer(0);
			var mgmtKey = new Buffer(16);
			var enc = alg.wrapKey(contentKey, mgmtKey);
			var plain = alg.unwrapKey(enc, mgmtKey);
			expect(Buffer.isBuffer(plain)).to.be.true;
			expect(mgmtKey.equals(plain)).to.be.true;
		});

		it("should throw if the unencrypted contentKey is of non-zero length on wrapping", function() {
			var contentKey = new Buffer(1);
			var mgmtKey = new Buffer(16);
			expect(function(){alg.wrapKey(contentKey, mgmtKey);}).to.throw(/contentKey must have a length of zero/);
		});

		it("should throw if the encrypted contentKey is of non-zero length on unwrapping", function() {
			var encKey = new Buffer(1);
			var mgmtKey = new Buffer(16);
			expect(function(){alg.unwrapKey(encKey, mgmtKey);}).to.throw(/encKey must have a length of zero/);
		});
	});
});
{'fraction_non_alphanumeric': 0.1617242433506573, 'fraction_numerical': 0.010088657902782024, 'mean_word_length': 4.0261136712749614, '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': '2682049', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1095, 'n_words': 305}