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

129 lines (114 loc) 4.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _pvutils = require("pvutils"); var _utils = require("./utils.js"); var _BaseClass = require("./BaseClass.js"); //************************************************************************************** class ConsistencyProofDataV2 extends _BaseClass.BaseClass { //********************************************************************************** /** * Constructor for ConsistencyProofDataV2 class * @param {Object} [parameters={}] * @property {Object} [schema] asn1js parsed value */ constructor(parameters = {}) { super(parameters); //region Internal properties of the object /** * @type {String} * @description logID OID representing used Certificate Transparency Log */ this.logID = (0, _pvutils.getParametersValue)(parameters, "logID", ConsistencyProofDataV2.constants("logID")); /** * @type {Number} * @description treeSize1 The size of the older tree */ this.treeSize1 = (0, _pvutils.getParametersValue)(parameters, "treeSize1", ConsistencyProofDataV2.constants("treeSize1")); /** * @type {Number} * @description treeSize2 The size of the newer tree */ this.treeSize2 = (0, _pvutils.getParametersValue)(parameters, "treeSize2", ConsistencyProofDataV2.constants("treeSize2")); /** * @type {Array.<ArrayBuffer>} * @description consistencyPath */ this.consistencyPath = (0, _pvutils.getParametersValue)(parameters, "consistencyPath", ConsistencyProofDataV2.constants("consistencyPath")); //endregion } //********************************************************************************** /** * Return value for a constant by name * @param {string} name String name for a constant */ static constants(name) { switch (name) { case "logID": return ""; case "treeSize1": case "treeSize2": return 0; case "consistencyPath": return []; default: throw new Error(`Invalid constant name for ConsistencyProofDataV2 class: ${name}`); } } //********************************************************************************** /** * Convert SeqStream data into current class * @param {!SeqStream} stream */ fromStream(stream) { this.logID = _utils.utils.getOID(stream, "ConsistencyProofDataV2"); this.treeSize1 = _utils.utils.getUint64(stream); this.treeSize2 = _utils.utils.getUint64(stream); let pathLength = stream.getUint16(); while (pathLength) { const hashLength = stream.getBlock(1)[0]; this.consistencyPath.push(new Uint8Array(stream.getBlock(hashLength)).buffer.slice(0)); pathLength--; } } //********************************************************************************** /** * Convert current object to SeqStream data * @param {!SeqStream} stream * @returns {boolean} Result of the function */ toStream(stream) { _utils.utils.appendOID(this.logID, stream); _utils.utils.appendUint64(this.treeSize1, stream); _utils.utils.appendUint64(this.treeSize2, stream); stream.appendUint16(this.consistencyPath.length); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = this.consistencyPath[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { const consistency = _step.value; stream.appendChar(consistency.byteLength); stream.appendView(new Uint8Array(consistency)); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return true; } //********************************************************************************** } exports.default = ConsistencyProofDataV2; //************************************************************************************** //# sourceMappingURL=ConsistencyProofDataV2.js.map