chunks v2

This commit is contained in:
andrei-mihnea-cerbu
2024-11-12 12:47:28 +02:00
parent 8c88d73665
commit a5e4fc030d
3 changed files with 21 additions and 13 deletions
@@ -78,13 +78,7 @@ export class TcpClientCommunicator extends SocketCommunicatorBase {
async sendChunkedMessage(operationCode: string, metaInfo?: { [key: string]: any }, fileContent?: Buffer): Promise<void> {
const message = MessageHandler.formatMessage(operationCode, metaInfo, fileContent);
let outgoingMessage: string;
if (this.aesKey && this.aesIv) {
outgoingMessage = this.encryptWithAes(message);
} else {
outgoingMessage = message;
}
const outgoingMessage = this.encryptWithAes(message);
const totalChunks = Math.ceil(outgoingMessage.length / CHUNK_SIZE);
const messageId = Date.now().toString();
@@ -136,9 +136,16 @@ export class TcpServerCommunicator extends SocketCommunicatorBase {
const message = MessageHandler.formatMessage(operationCode, metaInfo, fileContent);
let outgoingMessage: string;
if (this.aesKey && this.aesIv) outgoingMessage = this.encryptWithAes(message);
else if(this.privateKey) outgoingMessage = this.encryptWithRsa(message);
else outgoingMessage = message;
switch(operationCode) {
case 'SET_PUBLIC_KEY':
outgoingMessage = message;
break;
case 'SET_AES_KEY':
outgoingMessage = this.encryptWithRsa(message);
break;
default:
outgoingMessage = this.encryptWithAes(message);
}
const totalChunks = Math.ceil(outgoingMessage.length / CHUNK_SIZE);
const messageId = Date.now().toString();