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

110 lines (91 loc) 3.69 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 _TreeHeadDataV = require("./TreeHeadDataV2.js"); var _TreeHeadDataV2 = _interopRequireDefault(_TreeHeadDataV); 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 SignedTreeHeadDataV2 extends _BaseClass.BaseClassSigned { //********************************************************************************** /** * Constructor for SignedTreeHeadDataV2 class * @param {Object} [parameters={}] * @property {Object} [schema] asn1js parsed value */ constructor(parameters = {}) { super(parameters); //region Internal properties of the object /** * @type {String} * @description logID */ this.logID = (0, _pvutils.getParametersValue)(parameters, "logID", SignedTreeHeadDataV2.constants("logID")); /** * @type {TreeHeadDataV2} * @description treeHead */ this.treeHead = (0, _pvutils.getParametersValue)(parameters, "treeHead", SignedTreeHeadDataV2.constants("treeHead")); /** * @type {Object} * @description signature */ this.signature = (0, _pvutils.getParametersValue)(parameters, "signature", SignedTreeHeadDataV2.constants("signature")); //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 "treeHead": return new _TreeHeadDataV2.default(); case "signature": return {}; default: throw new Error(`Invalid constant name for SignedTreeHeadDataV2 class: ${name}`); } } //********************************************************************************** /** * Convert SeqStream data into current class * @param {!SeqStream} stream */ fromStream(stream) { this.logID = _utils.utils.getOID(stream, "SignedTreeHeadDataV2"); this.treeHead = new _TreeHeadDataV2.default({ stream }); //region Signature const signatureLength = stream.getUint16(); const signatureData = new Uint8Array(stream.getBlock(signatureLength)).buffer.slice(0); const asn1 = asn1js.fromBER(signatureData); if (asn1.offset === -1) throw new Error("Object's stream was not correct for SignedCertificateTimestampDataV2"); this.signature = asn1.result; //endregion } //********************************************************************************** /** * Convert current object to SeqStream data * @param {!SeqStream} stream * @returns {boolean} Result of the function */ toStream(stream) { _utils.utils.appendOID(this.logID, stream); this.treeHead.toStream(stream); stream.appendUint16(this.signature.byteLength); stream.appendView(new Uint8Array(this.signature)); return true; } //********************************************************************************** } exports.default = SignedTreeHeadDataV2; //************************************************************************************** //# sourceMappingURL=SignedTreeHeadDataV2.js.map