Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 3, 2024
1 parent 04987d2 commit 19a711f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 46 deletions.
39 changes: 19 additions & 20 deletions src/smime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ SMime::~SMime()

void SMime::setKeyFile(const QString &filename, const QString &password)
{
SMimePrivate *d = static_cast<SMimePrivate*>(d_ptr.data());
d->_keyfile = filename;
d->_password = password;
SMimePrivate *d = static_cast<SMimePrivate *>(d_ptr.data());
d->_keyfile = filename;
d->_password = password;
loadPKCS12PrivateKey();
}

void SMime::setPublicKey(const QString &filename)
{
SMimePrivate *d = static_cast<SMimePrivate*>(d_ptr.data());
SMimePrivate *d = static_cast<SMimePrivate *>(d_ptr.data());
d->_publicKeyfile = filename;
loadPKCS12PublicKey();
}

bool SMime::sign()
{
SMimePrivate *d = static_cast<SMimePrivate*>(d_ptr.data());
bool ret = false;
PKCS7 *p7 = nullptr;
SMimePrivate *d = static_cast<SMimePrivate *>(d_ptr.data());
bool ret = false;
PKCS7 *p7 = nullptr;

if (!d->_certificate || !d->_privateKey) {
qCDebug(SIMPLEMAIL_SMIME) << "no certificate or private key";
Expand Down Expand Up @@ -100,9 +100,9 @@ bool SMime::sign()

bool SMime::encrypt()
{
SMimePrivate *d = static_cast<SMimePrivate*>(d_ptr.data());
bool ret = false;
PKCS7 *p7 = nullptr;
SMimePrivate *d = static_cast<SMimePrivate *>(d_ptr.data());
bool ret = false;
PKCS7 *p7 = nullptr;

if (!d->_recipsReceiver) {
qCDebug(SIMPLEMAIL_SMIME) << "no public key";
Expand Down Expand Up @@ -138,7 +138,7 @@ bool SMime::encrypt()

bool SMime::signAndEncrypt()
{
SMimePrivate *d = static_cast<SMimePrivate*>(d_ptr.data());
SMimePrivate *d = static_cast<SMimePrivate *>(d_ptr.data());
bool ret = false;
PKCS7 *p7 = nullptr;
BIO *signedContent = nullptr;
Expand Down Expand Up @@ -214,7 +214,7 @@ void SMime::setEncryptionHeader()

void SMime::loadPKCS12PrivateKey()
{
SMimePrivate *d = static_cast<SMimePrivate*>(d_ptr.data());
SMimePrivate *d = static_cast<SMimePrivate *>(d_ptr.data());
QFile file(d->_keyfile);
if (!file.exists())
return;
Expand All @@ -236,8 +236,8 @@ void SMime::loadPKCS12PrivateKey()
qCDebug(SIMPLEMAIL_SMIME) << "Error reading PKCS#12 file";
}

EVP_PKEY *privateKey = nullptr;
X509 *certificate = nullptr;
EVP_PKEY *privateKey = nullptr;
X509 *certificate = nullptr;
STACK_OF(X509) *certificateCA = nullptr;
if (!PKCS12_parse(
p12, d->_password.toStdString().c_str(), &privateKey, &certificate, &certificateCA)) {
Expand All @@ -260,7 +260,7 @@ void SMime::loadPKCS12PrivateKey()

void SMime::loadPKCS12PublicKey()
{
SMimePrivate *d = static_cast<SMimePrivate*>(d_ptr.data());
SMimePrivate *d = static_cast<SMimePrivate *>(d_ptr.data());
QFile file(d->_publicKeyfile);
if (!file.exists())
return;
Expand All @@ -278,7 +278,6 @@ void SMime::loadPKCS12PublicKey()
X509 *publicrcert = PEM_read_bio_X509(keyBuffer, NULL, 0, NULL);
BIO_free(keyBuffer);


STACK_OF(X509) *recipsReceiver = sk_X509_new_null();

if (!recipsReceiver || !sk_X509_push(recipsReceiver, publicrcert)) {
Expand Down Expand Up @@ -307,9 +306,9 @@ void SMime::wrapMimeMultiPart()

bool SMime::writeInputBuffer()
{
SMimePrivate *d = static_cast<SMimePrivate*>(d_ptr.data());
BIO *input = BIO_new(BIO_s_mem());
d->_input = std::unique_ptr<BIO>(input);
SMimePrivate *d = static_cast<SMimePrivate *>(d_ptr.data());
BIO *input = BIO_new(BIO_s_mem());
d->_input = std::unique_ptr<BIO>(input);
if (!d->_input)
return false;
if (!BIO_write(d->_input.get(), (void *) d->_message.data(), d->_message.length()))
Expand All @@ -319,7 +318,7 @@ bool SMime::writeInputBuffer()

bool SMime::writeMimeMessageBuffer()
{
SMimePrivate *d = static_cast<SMimePrivate*>(d_ptr.data());
SMimePrivate *d = static_cast<SMimePrivate *>(d_ptr.data());
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);

Expand Down
8 changes: 4 additions & 4 deletions src/smimepart_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ using namespace SimpleMail;

SMimePrivate::~SMimePrivate()
{
_input = nullptr;
_privateKey = nullptr;
_certificate = nullptr;
_certificateCA = nullptr;
_input = nullptr;
_privateKey = nullptr;
_certificate = nullptr;
_certificateCA = nullptr;
_recipsReceiver = nullptr;
}
37 changes: 15 additions & 22 deletions src/smimepart_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,36 @@
#define SMIMEPART_P_H

#include "mimepart_p.h"
#include <openssl/pkcs12.h>

#include <openssl/bio.h>
#include <openssl/pkcs12.h>

template<> class std::default_delete<BIO>
template <>
class std::default_delete<BIO>
{
public:
void operator()(BIO *ptr) const
{
BIO_free(ptr);
}
void operator()(BIO *ptr) const { BIO_free(ptr); }
};

template<> class std::default_delete<EVP_PKEY>
template <>
class std::default_delete<EVP_PKEY>
{
public:
void operator()(EVP_PKEY *ptr) const
{
EVP_PKEY_free(ptr);
}
void operator()(EVP_PKEY *ptr) const { EVP_PKEY_free(ptr); }
};

template<> class std::default_delete<X509>
template <>
class std::default_delete<X509>
{
public:
void operator()(X509 *ptr) const
{
X509_free(ptr);
}
void operator()(X509 *ptr) const { X509_free(ptr); }
};

template<> class std::default_delete<STACK_OF(X509)>
template <>
class std::default_delete<STACK_OF(X509)>
{
public:
void operator()(STACK_OF(X509) *ptr) const
{
sk_X509_pop_free(ptr, X509_free);
}
void operator()(STACK_OF(X509) * ptr) const { sk_X509_pop_free(ptr, X509_free); }
};

namespace SimpleMail {
Expand All @@ -56,7 +49,7 @@ class SMimePrivate : public MimePartPrivate
std::unique_ptr<EVP_PKEY> _privateKey = nullptr;

// certificate from private Key
std::unique_ptr<X509> _certificate = nullptr;
std::unique_ptr<X509> _certificate = nullptr;
std::unique_ptr<STACK_OF(X509)> _certificateCA = nullptr;
// certificate from public key, used for encrypting
std::unique_ptr<STACK_OF(X509)> _recipsReceiver = nullptr;
Expand Down

0 comments on commit 19a711f

Please sign in to comment.