From: Remi Gacogne Date: Tue, 21 May 2024 09:02:48 +0000 (+0200) Subject: dnsdist: Delint dnsdist-lua-bindings-dnscrypt.cc X-Git-Tag: rec-5.1.0-beta1~30^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F14205%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Delint dnsdist-lua-bindings-dnscrypt.cc --- diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc index 9c7775f19f..65eba9e32b 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc @@ -35,34 +35,34 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client) luaCtx.registerFunction("markInactive", &DNSCryptContext::markInactive); luaCtx.registerFunction("reloadCertificates", &DNSCryptContext::reloadCertificates); luaCtx.registerFunction("removeInactiveCertificate", &DNSCryptContext::removeInactiveCertificate); - luaCtx.registerFunction::*)(const std::string& certFile, const std::string& keyFile, boost::optional active)>("loadNewCertificate", [](std::shared_ptr ctx, const std::string& certFile, const std::string& keyFile, boost::optional active) { + luaCtx.registerFunction::*)(const std::string& certFile, const std::string& keyFile, boost::optional active)>("loadNewCertificate", [](std::shared_ptr& ctx, const std::string& certFile, const std::string& keyFile, boost::optional active) { if (ctx == nullptr) { throw std::runtime_error("DNSCryptContext::loadNewCertificate() called on a nil value"); } ctx->loadNewCertificate(certFile, keyFile, active ? *active : true); }); - luaCtx.registerFunction::*)(const DNSCryptCert& newCert, const DNSCryptPrivateKey& newKey, boost::optional active)>("addNewCertificate", [](std::shared_ptr ctx, const DNSCryptCert& newCert, const DNSCryptPrivateKey& newKey, boost::optional active) { + luaCtx.registerFunction::*)(const DNSCryptCert& newCert, const DNSCryptPrivateKey& newKey, boost::optional active)>("addNewCertificate", [](std::shared_ptr& ctx, const DNSCryptCert& newCert, const DNSCryptPrivateKey& newKey, boost::optional active) { if (ctx == nullptr) { throw std::runtime_error("DNSCryptContext::addNewCertificate() called on a nil value"); } ctx->addNewCertificate(newCert, newKey, active ? *active : true); }); - luaCtx.registerFunction> (std::shared_ptr::*)()>("getCertificatePairs", [](std::shared_ptr ctx) { + luaCtx.registerFunction> (std::shared_ptr::*)()>("getCertificatePairs", [](std::shared_ptr& ctx) { LuaArray> result; if (ctx != nullptr) { size_t idx = 1; for (const auto& pair : ctx->getCertificates()) { - result.push_back({idx++, pair}); + result.emplace_back(idx++, pair); } } return result; }); - luaCtx.registerFunction (std::shared_ptr::*)(size_t idx)>("getCertificatePair", [](std::shared_ptr ctx, size_t idx) { + luaCtx.registerFunction (std::shared_ptr::*)(size_t idx)>("getCertificatePair", [](std::shared_ptr& ctx, size_t idx) { if (ctx == nullptr) { throw std::runtime_error("DNSCryptContext::getCertificatePair() called on a nil value"); } @@ -76,7 +76,7 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client) return result; }); - luaCtx.registerFunction::*)(size_t idx)>("getCertificate", [](std::shared_ptr ctx, size_t idx) { + luaCtx.registerFunction::*)(size_t idx)>("getCertificate", [](std::shared_ptr& ctx, size_t idx) { if (ctx == nullptr) { throw std::runtime_error("DNSCryptContext::getCertificate() called on a nil value"); } @@ -89,7 +89,7 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client) throw std::runtime_error("This DNSCrypt context has no certificate at index " + std::to_string(idx)); }); - luaCtx.registerFunction::*)() const>("printCertificates", [](const std::shared_ptr ctx) { + luaCtx.registerFunction::*)() const>("printCertificates", [](const std::shared_ptr& ctx) { ostringstream ret; if (ctx != nullptr) { @@ -124,13 +124,13 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client) }); /* DNSCryptCertificatePair */ - luaCtx.registerFunction::*)() const>("getCertificate", [](const std::shared_ptr pair) { + luaCtx.registerFunction::*)() const>("getCertificate", [](const std::shared_ptr& pair) { if (pair == nullptr) { throw std::runtime_error("DNSCryptCertificatePair::getCertificate() called on a nil value"); } return pair->cert; }); - luaCtx.registerFunction::*)() const>("isActive", [](const std::shared_ptr pair) { + luaCtx.registerFunction::*)() const>("isActive", [](const std::shared_ptr& pair) { if (pair == nullptr) { throw std::runtime_error("DNSCryptCertificatePair::isActive() called on a nil value"); } @@ -138,12 +138,30 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client) }); /* DNSCryptCert */ - luaCtx.registerFunction("getMagic", [](const DNSCryptCert& cert) { return std::string(reinterpret_cast(cert.magic.data()), cert.magic.size()); }); - luaCtx.registerFunction("getEsVersion", [](const DNSCryptCert& cert) { return std::string(reinterpret_cast(cert.esVersion.data()), cert.esVersion.size()); }); - luaCtx.registerFunction("getProtocolMinorVersion", [](const DNSCryptCert& cert) { return std::string(reinterpret_cast(cert.protocolMinorVersion.data()), cert.protocolMinorVersion.size()); }); - luaCtx.registerFunction("getSignature", [](const DNSCryptCert& cert) { return std::string(reinterpret_cast(cert.signature.data()), cert.signature.size()); }); - luaCtx.registerFunction("getResolverPublicKey", [](const DNSCryptCert& cert) { return std::string(reinterpret_cast(cert.signedData.resolverPK.data()), cert.signedData.resolverPK.size()); }); - luaCtx.registerFunction("getClientMagic", [](const DNSCryptCert& cert) { return std::string(reinterpret_cast(cert.signedData.clientMagic.data()), cert.signedData.clientMagic.size()); }); + luaCtx.registerFunction("getMagic", [](const DNSCryptCert& cert) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): std::string's API + return std::string(reinterpret_cast(cert.magic.data()), cert.magic.size()); + }); + luaCtx.registerFunction("getEsVersion", [](const DNSCryptCert& cert) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): std::string's API + return std::string(reinterpret_cast(cert.esVersion.data()), cert.esVersion.size()); + }); + luaCtx.registerFunction("getProtocolMinorVersion", [](const DNSCryptCert& cert) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): std::string's API + return std::string(reinterpret_cast(cert.protocolMinorVersion.data()), cert.protocolMinorVersion.size()); + }); + luaCtx.registerFunction("getSignature", [](const DNSCryptCert& cert) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): std::string's API + return std::string(reinterpret_cast(cert.signature.data()), cert.signature.size()); + }); + luaCtx.registerFunction("getResolverPublicKey", [](const DNSCryptCert& cert) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): std::string's API + return std::string(reinterpret_cast(cert.signedData.resolverPK.data()), cert.signedData.resolverPK.size()); + }); + luaCtx.registerFunction("getClientMagic", [](const DNSCryptCert& cert) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): std::string's API + return std::string(reinterpret_cast(cert.signedData.clientMagic.data()), cert.signedData.clientMagic.size()); + }); luaCtx.registerFunction("getSerial", [](const DNSCryptCert& cert) { return cert.getSerial(); }); luaCtx.registerFunction("getTSStart", [](const DNSCryptCert& cert) { return ntohl(cert.getTSStart()); }); luaCtx.registerFunction("getTSEnd", [](const DNSCryptCert& cert) { return ntohl(cert.getTSEnd()); }); @@ -181,10 +199,12 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client) DNSCryptContext::generateProviderKeys(publicKey, privateKey); ofstream pubKStream(publicKeyFile); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): ofstream's API pubKStream.write(reinterpret_cast(publicKey.data()), publicKey.size()); pubKStream.close(); ofstream privKStream(privateKeyFile); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): ofstream's API privKStream.write(reinterpret_cast(privateKey.data()), privateKey.size()); privKStream.close(); @@ -205,6 +225,7 @@ void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client) try { ifstream file(publicKeyFile); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): ifstream's API file.read(reinterpret_cast(publicKey.data()), publicKey.size()); if (file.fail()) {