larabr d49d92e5cb Update to Mocha v10 in tests, declare lib as module and add exports to package.json
Mocha v10 requires the lib to be esm compliant.
ESM mandates the use of file extensions in imports, so to minimize the
changes (for now), we rely on the flag `experimental-specifier-resolution=node`
and on `ts-node` (needed only for Node 20).

Breaking changes:
downstream bundlers might be affected by the package.json changes depending on
how they load the library.
NB: legacy package.json entrypoints are still available.
2023-10-25 12:53:10 +02:00

39 lines
1.4 KiB
JavaScript

import { expect } from 'chai';
import OID from '../../src/type/oid.js';
import util from '../../src/util.js';
export default () => describe('Oid tests', function() {
const p256_oid = new Uint8Array([0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07]);
const p384_oid = new Uint8Array([0x2B, 0x81, 0x04, 0x00, 0x22]);
const p521_oid = new Uint8Array([0x2B, 0x81, 0x04, 0x00, 0x23]);
it('Constructing', function() {
const oids = [p256_oid, p384_oid, p521_oid];
oids.forEach(function (data) {
const oid = new OID(data);
expect(oid).to.exist;
expect(oid.oid).to.exist;
expect(oid.oid).to.have.length(data.length);
expect(oid.toHex()).to.equal(util.uint8ArrayToHex(data));
});
});
it('Reading and writing', function() {
const oids = [p256_oid, p384_oid, p521_oid];
oids.forEach(function (data) {
data = util.concatUint8Array([new Uint8Array([data.length]), data]);
const oid = new OID();
expect(oid.read(data)).to.equal(data.length);
expect(oid.oid).to.exist;
expect(oid.oid).to.have.length(data.length - 1);
expect(oid.toHex()).to.equal(util.uint8ArrayToHex(data.subarray(1)));
const result = oid.write();
expect(result).to.exist;
expect(result).to.have.length(data.length);
expect(result[0]).to.equal(data.length - 1);
expect(
util.uint8ArrayToHex(result.subarray(1))
).to.equal(util.uint8ArrayToHex(data.subarray(1)));
});
});
});