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