"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tap_stream_1 = require("../frame/tap-stream");
var models_extensions_1 = require("../model/models.extensions");
var error_1 = require("../../api/converter/error");
;
/**
 *
 */
var CryptedFrameConverter = /** @class */ (function () {
    function CryptedFrameConverter(frameIdGenerator) {
        this.frameIdGenerator = frameIdGenerator;
    }
    CryptedFrameConverter.prototype.encode = function (data) {
        var encryptedModel = models_extensions_1.createTapEncryptedFrame(this.frameIdGenerator.next(), data
        // this.paddingGenerator
        );
        return new tap_stream_1.TapStreamWriter().writeTapEncryptedFrame(encryptedModel).toBytes;
    };
    CryptedFrameConverter.prototype.decode = function (frame) {
        if (!frame) {
            throw error_1.ConverterError.nullBufferError("Illegal data: frame is null");
        }
        var encryptedFrame = tap_stream_1.TapStreamReader.fromArray(frame).readTapEncryptedFrame();
        var subData = encryptedFrame.payload;
        // TODO add back crc
        // let crc = encryptedFrame.crc;
        // let computedCrc = this._computeCRC(byteBuffer.data);
        // if (crc != computedCrc){
        //     if (this.options.skipCRCCheck){
        //     }
        //     else{
        //         throw new Error(`Invalid crc read ${crc}. Should be ${computedCrc}`);
        //     }
        // }
        return subData;
    };
    return CryptedFrameConverter;
}());
exports.CryptedFrameConverter = CryptedFrameConverter;
