import { ConverterError } from './error';
import { TapStreamReader, TapStreamWriter } from '../frame/tap-stream-extended';
import { createTapEncryptedFrame } from '../model/models.extensions';
/**
 *
 */
var CryptedFrameConverter = /** @class */ (function () {
    function CryptedFrameConverter(frameIdGenerator) {
        this.frameIdGenerator = frameIdGenerator;
    }
    CryptedFrameConverter.prototype.encode = function (data) {
        var encryptedModel = createTapEncryptedFrame(this.frameIdGenerator.next(), data
        // this.paddingGenerator
        );
        return new TapStreamWriter().writeTapEncryptedFrame(encryptedModel)
            .toBytes;
    };
    CryptedFrameConverter.prototype.decode = function (frame) {
        if (!frame) {
            throw ConverterError.nullBufferError('Illegal data: frame is null');
        }
        var encryptedFrame = 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;
}());
export { CryptedFrameConverter };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3J5cHRlZC1mcmFtZS1jb252ZXJ0ZXIuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9AaW90aXplL3RhcC9jbGllbnQvaW1wbC8iLCJzb3VyY2VzIjpbImxpYi9jb252ZXJ0ZXIvY3J5cHRlZC1mcmFtZS1jb252ZXJ0ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLFNBQVMsQ0FBQztBQUN6QyxPQUFPLEVBQUUsZUFBZSxFQUFFLGVBQWUsRUFBRSxNQUFNLDhCQUE4QixDQUFDO0FBQ2hGLE9BQU8sRUFBRSx1QkFBdUIsRUFBRSxNQUFNLDRCQUE0QixDQUFDO0FBS3JFOztHQUVH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