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

152 lines (128 loc) 4.99 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 SignedCertificateTimestampDataV2 extends _BaseClass.BaseClassSigned { //********************************************************************************** /** * Constructor for SignedCertificateTimestampDataV2 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", SignedCertificateTimestampDataV2.constants("logID")); /** * @type {Date} * @description timestamp */ this.timestamp = (0, _pvutils.getParametersValue)(parameters, "timestamp", SignedCertificateTimestampDataV2.constants("timestamp")); /** * @type {Array.<Extension>} * @description extensions */ this.extensions = (0, _pvutils.getParametersValue)(parameters, "extensions", SignedCertificateTimestampDataV2.constants("extensions")); /** * @type {Object} * @description signature */ this.signature = (0, _pvutils.getParametersValue)(parameters, "signature", SignedCertificateTimestampDataV2.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 "timestamp": return new Date(); case "extensions": return []; case "signature": return {}; default: throw new Error(`Invalid constant name for SignedCertificateTimestampDataV2 class: ${name}`); } } //********************************************************************************** /** * Convert SeqStream data into current class * @param {!SeqStream} stream */ fromStream(stream) { this.logID = _utils.utils.getOID(stream, "SignedCertificateTimestampDataV2"); this.timestamp = new Date(_utils.utils.getUint64(stream)); let extensionsCount = stream.getUint16(); while (extensionsCount) { this.extensions.push(new _Extension2.default({ stream })); extensionsCount--; } //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); _utils.utils.appendUint64(this.timestamp.valueOf(), stream); stream.appendUint16(this.extensions.length); if (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; } } } } stream.appendUint16(this.signature.byteLength); stream.appendView(new Uint8Array(this.signature)); return true; } //********************************************************************************** } exports.default = SignedCertificateTimestampDataV2; //************************************************************************************** //# sourceMappingURL=SignedCertificateTimestampDataV2.js.map