UNPKG

ctjs

Version:

CTjs is a full set of classes necessary to work with any kind of Certificate Transparency log (V1 as from RFC6962, or V2 as from RFC6962-bis). In CTjs you could find all necessary validation/verification functions for all related data shipped with full-fe

157 lines (131 loc) 5.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _asn1js = require("asn1js"); var asn1js = _interopRequireWildcard(_asn1js); var _pvutils = require("pvutils"); var _utils = require("./utils.js"); var _Extension = require("./Extension.js"); var _Extension2 = _interopRequireDefault(_Extension); var _BaseClass = require("./BaseClass.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } //************************************************************************************** class TimestampedCertificateEntryDataV2 extends _BaseClass.BaseClass { //********************************************************************************** /** * Constructor for TimestampedCertificateEntryDataV2 class * @param {Object} [parameters={}] * @property {Object} [schema] asn1js parsed value */ constructor(parameters = {}) { super(parameters); //region Internal properties of the object /** * @type {Date} * @description timestamp */ this.timestamp = (0, _pvutils.getParametersValue)(parameters, "timestamp", TimestampedCertificateEntryDataV2.constants("timestamp")); /** * @type {ArrayBuffer} * @description issuerKeyHash */ this.issuerKeyHash = (0, _pvutils.getParametersValue)(parameters, "issuerKeyHash", TimestampedCertificateEntryDataV2.constants("issuerKeyHash")); /** * @type {ArrayBuffer} * @description rootHash */ this.rootHash = (0, _pvutils.getParametersValue)(parameters, "rootHash", TimestampedCertificateEntryDataV2.constants("rootHash")); /** * @type {Object} * @description tbsCertificate */ this.tbsCertificate = (0, _pvutils.getParametersValue)(parameters, "tbsCertificate", TimestampedCertificateEntryDataV2.constants("tbsCertificate")); /** * @type {Array.<Extension>} * @description extensions */ this.extensions = (0, _pvutils.getParametersValue)(parameters, "extensions", TimestampedCertificateEntryDataV2.constants("extensions")); //endregion } //********************************************************************************** /** * Return value for a constant by name * @param {string} name String name for a constant */ static constants(name) { switch (name) { case "timestamp": return new Date(); case "issuerKeyHash": return new ArrayBuffer(0); case "tbsCertificate": return new asn1js.Any(); case "extensions": return []; default: throw new Error(`Invalid constant name for TimestampedCertificateEntryDataV2 class: ${name}`); } } //********************************************************************************** /** * Convert SeqStream data into current class * @param {!SeqStream} stream */ fromStream(stream) { this.timestamp = new Date(_utils.utils.getUint64(stream)); const hashLength = stream.getBlock(1)[0]; this.issuerKeyHash = new Uint8Array(stream.getBlock(hashLength)).buffer.slice(0); const tbsLength = stream.getUint24(); const asn1 = asn1js.fromBER(new Uint8Array(stream.getBlock(tbsLength)).buffer.slice(0)); if (asn1.offset === -1) throw new Error("Object's stream was not correct for TimestampedCertificateEntryDataV2"); this.tbsCertificate = asn1.result; let extensionsCount = stream.getUint16(); while (extensionsCount) { this.extensions.push(new _Extension2.default({ stream })); extensionsCount--; } } //********************************************************************************** /** * Convert current object to SeqStream data * @param {!SeqStream} stream * @returns {boolean} Result of the function */ toStream(stream) { _utils.utils.appendUint64(this.timestamp.valueOf(), stream); stream.appendChar(this.issuerKeyHash.byteLength); stream.appendView(new Uint8Array(this.issuerKeyHash)); const tbs = this.tbsCertificate.toBER(false); stream.appendUint24(tbs.byteLength); stream.appendView(new Uint8Array(tbs)); stream.appendUint16(this.extensions.length); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = this.extensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { const extension = _step.value; extension.toStream(stream); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return true; } //********************************************************************************** } exports.default = TimestampedCertificateEntryDataV2; //************************************************************************************** //# sourceMappingURL=TimestampedCertificateEntryDataV2.js.map