/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
*/
#include "squid.h"
+#include "base/HardFun.h"
#include "security/cert_generators/file/certificate_db.h"
#include <cerrno>
return true;
}
-/// DeAllocator functor for unique_ptr that need free(3) from the std C library
-struct xfree_char {
- void operator()(char *a) { xfree(a); }
-};
-
bool Ssl::CertificateDb::addCertAndPrivateKey(Security::CertPointer & cert, Ssl::EVP_PKEY_Pointer & pkey, std::string const & useName) {
const Locker locker(dbLock, Here);
load();
if (!db || !cert || !pkey)
return false;
+
+ // Functor to wrap xfree() for std::unique_ptr
+ typedef HardFun<void, const void*, &xfree> CharDeleter;
+
Row row;
ASN1_INTEGER * ai = X509_get_serialNumber(cert.get());
std::string serial_string;
Ssl::BIGNUM_Pointer serial(ASN1_INTEGER_to_BN(ai, NULL));
{
- std::unique_ptr<char, xfree_char> hex_bn(BN_bn2hex(serial.get()));
+ std::unique_ptr<char, CharDeleter> hex_bn(BN_bn2hex(serial.get()));
serial_string = std::string(hex_bn.get());
}
row.setValue(cnlSerial, serial_string.c_str());
}
{
- std::unique_ptr<char, xfree_char> subject(X509_NAME_oneline(X509_get_subject_name(cert.get()), nullptr, 0));
+ std::unique_ptr<char, CharDeleter> subject(X509_NAME_oneline(X509_get_subject_name(cert.get()), nullptr, 0));
Security::CertPointer findCert;
Ssl::EVP_PKEY_Pointer findPkey;
if (pure_find(useName.empty() ? subject.get() : useName, findCert, findPkey)) {
// Replace with database certificate
- cert.reset(findCert.release());
- pkey.reset(findPkey.release());
+ cert = std::move(findCert);
+ pkey = std::move(findPkey);
return true;
}
// pure_find may fail because the entry is expired, or because the
if (!useName.empty())
row.setValue(cnlName, useName.c_str());
else {
- std::unique_ptr<char, xfree_char> subject(X509_NAME_oneline(X509_get_subject_name(cert.get()), nullptr, 0));
+ std::unique_ptr<char, CharDeleter> subject(X509_NAME_oneline(X509_get_subject_name(cert.get()), nullptr, 0));
row.setValue(cnlName, subject.get());
}