From 5faeca1b82b3b4a84a8049fcee7a9b9e77b0a7b7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 18 Feb 2018 01:04:44 +0100 Subject: [PATCH] Move BIO2ByteArray to annonymous namespace This has no use outside of the clientsidenecryption.cpp --- src/libsync/clientsideencryption.cpp | 26 +++++++++++++------------- src/libsync/clientsideencryption.h | 2 -- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/libsync/clientsideencryption.cpp b/src/libsync/clientsideencryption.cpp index 5fcdaf53b..0118c9870 100644 --- a/src/libsync/clientsideencryption.cpp +++ b/src/libsync/clientsideencryption.cpp @@ -58,6 +58,17 @@ namespace { } // ns namespace { + QByteArray BIO2ByteArray(BIO *b) { + int pending = BIO_ctrl_pending(b); + char *tmp = (char *)calloc(pending+1, sizeof(char)); + BIO_read(b, tmp, pending); + + QByteArray res(tmp, pending); + free(tmp); + + return res; + } + void handleErrors(void) { ERR_print_errors_fp(stdout); // This line is not printing anything. @@ -592,17 +603,6 @@ QByteArray EncryptionHelper::encryptStringAsymmetric(EVP_PKEY *publicKey, const return raw.toBase64(); } -QByteArray EncryptionHelper::BIO2ByteArray(BIO *b) { - int pending = BIO_ctrl_pending(b); - char *tmp = (char *)calloc(pending+1, sizeof(char)); - BIO_read(b, tmp, pending); - - QByteArray res(tmp, pending); - free(tmp); - - return res; -} - ClientSideEncryption::ClientSideEncryption() { } @@ -847,7 +847,7 @@ void ClientSideEncryption::generateKeyPair() qCInfo(lcCse()) << "Could not read private key from bio."; return; } - QByteArray key = EncryptionHelper::BIO2ByteArray(privKey); + QByteArray key = BIO2ByteArray(privKey); _privateKey = QSslKey(key, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); qCInfo(lcCse()) << "Keys generated correctly, sending to server."; @@ -907,7 +907,7 @@ void ClientSideEncryption::generateCSR(EVP_PKEY *keyPair) BIO *out = BIO_new(BIO_s_mem()); ret = PEM_write_bio_X509_REQ(out, x509_req); - QByteArray output = EncryptionHelper::BIO2ByteArray(out); + QByteArray output = BIO2ByteArray(out); BIO_free(out); EVP_PKEY_free(keyPair); diff --git a/src/libsync/clientsideencryption.h b/src/libsync/clientsideencryption.h index 7a35a0606..b3dcdb17e 100644 --- a/src/libsync/clientsideencryption.h +++ b/src/libsync/clientsideencryption.h @@ -61,8 +61,6 @@ public: const QByteArray& data ); - static QByteArray BIO2ByteArray(BIO *b); - static bool fileEncryption(const QByteArray &key, const QByteArray &iv, QFile *input, QFile *output, QByteArray& returnTag);