return maker;
}
+std::unique_ptr<DNSCryptoKeyEngine> DNSCryptoKeyEngine::makeFromPEMString(DNSKEYRecordContent& drc, uint8_t algorithm, const std::string& contents)
+{
+ auto maker = DNSCryptoKeyEngine::make(algorithm);
+ maker->createFromPEMString(drc, contents);
+ return maker;
+}
+
std::string DNSCryptoKeyEngine::convertToISC() const
{
storvector_t storvector = this->convertToISCVector();
throw std::runtime_error("Can't create key from PEM contents");
}
+ /**
+ * \brief Creates a key engine from a PEM string.
+ *
+ * Receives PEM contents and creates a key engine.
+ *
+ * \param[in] drc Key record contents to be populated.
+ *
+ * \param[in] contents The PEM string contents.
+ *
+ * \return A key engine populated with the contents of the PEM string.
+ */
+ void createFromPEMString(DNSKEYRecordContent& drc, const std::string& contents)
+ {
+ // NOLINTNEXTLINE(*-cast): POSIX APIs.
+ unique_ptr<std::FILE, decltype(&std::fclose)> inputFile{fmemopen(const_cast<char*>(contents.data()), contents.length(), "r"), &std::fclose};
+ createFromPEMFile(drc, *inputFile);
+ }
+
[[nodiscard]] virtual storvector_t convertToISCVector() const =0;
[[nodiscard]] std::string convertToISC() const ;
*/
static std::unique_ptr<DNSCryptoKeyEngine> makeFromPEMFile(DNSKEYRecordContent& drc, uint8_t algorithm, std::FILE& inputFile, const std::string& filename);
+ /**
+ * \brief Creates a key engine from a PEM string.
+ *
+ * Receives PEM contents and creates a key engine corresponding to the algorithm
+ * requested.
+ *
+ * \param[in] drc Key record contents to be populated.
+ *
+ * \param[in] algorithm Which algorithm to use. See
+ * https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml
+ *
+ * \param[in] contents The PEM contents.
+ *
+ * \return A key engine corresponding to the requested algorithm and populated with
+ * the contents of the PEM string.
+ */
+ static std::unique_ptr<DNSCryptoKeyEngine> makeFromPEMString(DNSKEYRecordContent& drc, uint8_t algorithm, const std::string& contents);
+
static std::unique_ptr<DNSCryptoKeyEngine> makeFromISCString(DNSKEYRecordContent& drc, const std::string& content);
static std::unique_ptr<DNSCryptoKeyEngine> makeFromPublicKeyString(unsigned int algorithm, const std::string& raw);
static std::unique_ptr<DNSCryptoKeyEngine> make(unsigned int algorithm);
auto dcke = std::shared_ptr<DNSCryptoKeyEngine>(DNSCryptoKeyEngine::makeFromISCString(drc, signer.iscMap));
test_generic_signer(dcke, drc, signer, message);
- unique_ptr<std::FILE, decltype(&std::fclose)> inputFile{fmemopen((void*)signer.pem.c_str(), signer.pem.length(), "r"), &std::fclose};
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg): Boost stuff.
- BOOST_REQUIRE(inputFile.get() != nullptr);
-
DNSKEYRecordContent pemDRC;
- shared_ptr<DNSCryptoKeyEngine> pemKey{DNSCryptoKeyEngine::makeFromPEMFile(pemDRC, signer.algorithm, *inputFile, "<buffer>")};
+ shared_ptr<DNSCryptoKeyEngine> pemKey{DNSCryptoKeyEngine::makeFromPEMString(pemDRC, signer.algorithm, signer.pem)};
BOOST_CHECK_EQUAL(pemKey->convertToISC(), dcke->convertToISC());