@@ -48,21 +48,20 @@ bool AES::encryptFilePart(QIODevice *file, qint64 pos, qint64 end, const QByteAr
4848
4949 file->seek (pos);
5050
51- qint64 bufferSize = 4096 ;
51+ const qint64 bufferSize = 4096 ;
5252 qint64 size = end - pos;
5353 qint64 parts = size / bufferSize;
5454 qint64 additional = size % bufferSize;
5555 emit setMaximumValue (parts);
5656
57- unsigned char *buffer = new unsigned char [bufferSize];
58- unsigned char *outBuffer = new unsigned char [bufferSize];
59-
60- int len = 0 ;
61-
6257 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new ();
6358 if (!ctx) return false ;
6459 if (1 != EVP_EncryptInit_ex (ctx, EVP_aes_256_xts (), NULL , key, NULL )) return false ;
6560
61+ unsigned char buffer[bufferSize];
62+ unsigned char outBuffer[bufferSize];
63+ int len = 0 ;
64+
6665 for (int i = 0 ; i < parts; ++i)
6766 {
6867 file->read ((char *)buffer, bufferSize);
@@ -79,8 +78,6 @@ bool AES::encryptFilePart(QIODevice *file, qint64 pos, qint64 end, const QByteAr
7978 file->write ((char *)outBuffer, additional);
8079
8180 EVP_CIPHER_CTX_free (ctx);
82- delete[] buffer;
83- delete[] outBuffer;
8481 emit finished ();
8582 return true ;
8683}
@@ -94,19 +91,18 @@ bool AES::decryptFilePart(QIODevice *file, qint64 pos, qint64 end, const QByteAr
9491
9592 file->seek (pos);
9693
94+ const qint64 bufferSize = 4096 ;
9795 qint64 size = end - pos;
98- qint64 bufferSize = 4096 ;
9996 qint64 parts = size / bufferSize;
10097 qint64 additional = size % bufferSize;
10198 emit setMaximumValue (parts);
10299
103- unsigned char *buffer = new unsigned char [bufferSize];
104- unsigned char *outBuffer = new unsigned char [bufferSize];
105-
106100 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new ();
107101 if (!ctx) return false ;
108102 if (!EVP_DecryptInit_ex (ctx, EVP_aes_256_xts (), NULL , key, NULL )) return false ;
109103
104+ unsigned char buffer[bufferSize];
105+ unsigned char outBuffer[bufferSize];
110106 int len = 0 ;
111107
112108 for (int i = 0 ; i < parts; ++i)
@@ -126,8 +122,6 @@ bool AES::decryptFilePart(QIODevice *file, qint64 pos, qint64 end, const QByteAr
126122 file->write ((char *)outBuffer, len);
127123
128124 EVP_CIPHER_CTX_free (ctx);
129- delete[] buffer;
130- delete[] outBuffer;
131125 emit finished ();
132126 return true ;
133127}
0 commit comments