UNPKG

@observertc/samples-decoder

Version:

ObserveRTC Library for Decoding Samples

65 lines (64 loc) 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CertificateDecoder = void 0; const utils_1 = require("./utils"); const Logger_1 = require("./Logger"); class CertificateDecoder { constructor(id, _attachmentsDecoder) { this.id = id; this._attachmentsDecoder = _attachmentsDecoder; this._visited = false; this._actualValue = undefined; this._timestampDecoder = new utils_1.NumberToNumberDecoder(); this._fingerprintDecoder = new utils_1.StringToStringDecoder(); this._fingerprintAlgorithmDecoder = new utils_1.StringToStringDecoder(); this._base64CertificateDecoder = new utils_1.StringToStringDecoder(); this._issuerCertificateIdDecoder = new utils_1.StringToStringDecoder(); } get visited() { const result = this._visited; this._visited = false; return result; } reset() { this._timestampDecoder.reset(); this._fingerprintDecoder.reset(); this._fingerprintAlgorithmDecoder.reset(); this._base64CertificateDecoder.reset(); this._issuerCertificateIdDecoder.reset(); this._attachmentsDecoder.reset(); } decode(sample) { this._visited = true; const timestamp = this._timestampDecoder.decode(sample.timestamp); if (!timestamp) { Logger_1.logger.warn("Invalid sample: ", sample); return undefined; } this._actualValue = { timestamp, id: this.id, fingerprint: this._fingerprintDecoder.decode(sample.fingerprint), fingerprintAlgorithm: this._fingerprintAlgorithmDecoder.decode(sample.fingerprintAlgorithm), base64Certificate: this._base64CertificateDecoder.decode(sample.base64Certificate), issuerCertificateId: this._issuerCertificateIdDecoder.decode(sample.issuerCertificateId), attachments: this._attachmentsDecoder.decode(sample.attachments), }; } get actualValue() { return this._actualValue; } set actualValue(sample) { if (!sample) return; this._visited = true; this._actualValue = sample; this._timestampDecoder.actualValue = sample.timestamp; this._fingerprintDecoder.actualValue = sample.fingerprint; this._fingerprintAlgorithmDecoder.actualValue = sample.fingerprintAlgorithm; this._base64CertificateDecoder.actualValue = sample.base64Certificate; this._issuerCertificateIdDecoder.actualValue = sample.issuerCertificateId; this._attachmentsDecoder.actualValue = sample.attachments; } } exports.CertificateDecoder = CertificateDecoder;