@@ -45,7 +45,7 @@ static std::vector<unsigned char> from_base64(std::string_view data)
45
45
std::vector<unsigned char > result (EVP_DECODE_LENGTH (data.size ()), 0 );
46
46
size_t dataPos = 0 ;
47
47
int size = 0 ;
48
- auto ctx = make_unique_ptr (EVP_ENCODE_CTX_new (), EVP_ENCODE_CTX_free );
48
+ auto ctx = make_unique_ptr<EVP_ENCODE_CTX_free> (EVP_ENCODE_CTX_new ());
49
49
EVP_DecodeInit (ctx.get ());
50
50
51
51
for (auto pos = data.find_first_of (whitespace);
@@ -71,7 +71,7 @@ static std::vector<unsigned char> from_base64(std::string_view data)
71
71
static std::string to_base64 (const std::vector<unsigned char > &data)
72
72
{
73
73
std::string result (EVP_ENCODE_LENGTH (data.size ()), 0 );
74
- auto ctx = make_unique_ptr (EVP_ENCODE_CTX_new (), EVP_ENCODE_CTX_free );
74
+ auto ctx = make_unique_ptr<EVP_ENCODE_CTX_free> (EVP_ENCODE_CTX_new ());
75
75
EVP_EncodeInit (ctx.get ());
76
76
int size{};
77
77
if (EVP_EncodeUpdate (ctx.get (), (unsigned char *)result.data (), &size, data.data (), int (data.size ())) < 1 )
@@ -232,7 +232,9 @@ struct XMLNode: public XMLElem<xmlNode>
232
232
{
233
233
if (!d)
234
234
return *this ;
235
- xmlNodeAddContentLen (d, pcxmlChar (text.data ()), int (text.length ()));
235
+ xmlNodeSetContentLen (d, nullptr , 0 );
236
+ if (!text.empty ())
237
+ xmlNodeAddContentLen (d, pcxmlChar (text.data ()), int (text.length ()));
236
238
return *this ;
237
239
}
238
240
@@ -305,11 +307,11 @@ struct XMLDocument: public unique_free_t<xmlDoc>, public XMLNode
305
307
306
308
static XMLDocument openStream (std::istream &is, const XMLName &name = {}, bool hugeFile = false )
307
309
{
308
- auto ctxt = make_unique_ptr (xmlCreateIOParserCtxt (nullptr , nullptr , [](void *context, char *buffer, int len) -> int {
310
+ auto ctxt = make_unique_ptr<xmlFreeParserCtxt> (xmlCreateIOParserCtxt (nullptr , nullptr , [](void *context, char *buffer, int len) -> int {
309
311
auto *is = static_cast <std::istream *>(context);
310
312
is->read (buffer, len);
311
313
return is->good () || is->eof () ? int (is->gcount ()) : -1 ;
312
- }, nullptr , &is, XML_CHAR_ENCODING_NONE), xmlFreeParserCtxt );
314
+ }, nullptr , &is, XML_CHAR_ENCODING_NONE));
313
315
ctxt->linenumbers = 1 ;
314
316
ctxt->options |= XML_PARSE_NOENT|XML_PARSE_DTDLOAD|XML_PARSE_DTDATTR|XML_PARSE_NONET;
315
317
ctxt->loadsubset |= XML_DETECT_IDS|XML_COMPLETE_ATTRS;
@@ -358,11 +360,11 @@ struct XMLDocument: public unique_free_t<xmlDoc>, public XMLNode
358
360
}
359
361
else if (!algo.empty ())
360
362
THROW (" Unsupported canonicalization method '%.*s'" , int (algo.size ()), algo.data ());
361
- auto buf = make_unique_ptr (xmlOutputBufferCreateIO ([](void *context, const char *buffer, int len) {
363
+ auto buf = make_unique_ptr<xmlOutputBufferClose> (xmlOutputBufferCreateIO ([](void *context, const char *buffer, int len) {
362
364
auto *digest = static_cast <Digest *>(context);
363
365
digest->update (pcxmlChar (buffer), size_t (len));
364
366
return len;
365
- }, nullptr , const_cast <Digest*>(&digest), nullptr ), xmlOutputBufferClose );
367
+ }, nullptr , const_cast <Digest*>(&digest), nullptr ));
366
368
int size = xmlC14NExecute (get (), [](void *root, xmlNodePtr node, xmlNodePtr parent) constexpr noexcept {
367
369
if (root == node)
368
370
return 1 ;
@@ -396,14 +398,14 @@ struct XMLDocument: public unique_free_t<xmlDoc>, public XMLNode
396
398
397
399
void validateSchema (const std::string &schemaPath) const
398
400
{
399
- auto parser = make_unique_ptr (xmlSchemaNewParserCtxt (schemaPath.c_str ()), xmlSchemaFreeParserCtxt );
401
+ auto parser = make_unique_ptr<xmlSchemaFreeParserCtxt> (xmlSchemaNewParserCtxt (schemaPath.c_str ()));
400
402
if (!parser)
401
403
THROW (" Failed to create schema parser context %s" , schemaPath.c_str ());
402
404
xmlSchemaSetParserErrors (parser.get (), schemaValidationError, schemaValidationWarning, nullptr );
403
- auto schema = make_unique_ptr (xmlSchemaParse (parser.get ()), xmlSchemaFree );
405
+ auto schema = make_unique_ptr<xmlSchemaFree> (xmlSchemaParse (parser.get ()));
404
406
if (!schema)
405
407
THROW (" Failed to parse schema %s" , schemaPath.c_str ());
406
- auto validate = make_unique_ptr (xmlSchemaNewValidCtxt (schema.get ()), xmlSchemaFreeValidCtxt );
408
+ auto validate = make_unique_ptr<xmlSchemaFreeValidCtxt> (xmlSchemaNewValidCtxt (schema.get ()));
407
409
if (!validate)
408
410
THROW (" Failed to create schema validation context %s" , schemaPath.c_str ());
409
411
Exception e (EXCEPTION_PARAMS (" Failed to XML with schema" ));
@@ -414,12 +416,12 @@ struct XMLDocument: public unique_free_t<xmlDoc>, public XMLNode
414
416
415
417
static bool verifySignature (XMLNode signature, [[maybe_unused]] Exception *e = {}) noexcept
416
418
{
417
- auto mngr = make_unique_ptr (xmlSecKeysMngrCreate (), xmlSecKeysMngrDestroy );
419
+ auto mngr = make_unique_ptr<xmlSecKeysMngrDestroy> (xmlSecKeysMngrCreate ());
418
420
if (!mngr)
419
421
return false ;
420
422
if (xmlSecCryptoAppDefaultKeysMngrInit (mngr.get ()) < 0 )
421
423
return false ;
422
- auto ctx = make_unique_ptr (xmlSecDSigCtxCreate (mngr.get ()), xmlSecDSigCtxDestroy );
424
+ auto ctx = make_unique_ptr<xmlSecDSigCtxDestroy> (xmlSecDSigCtxCreate (mngr.get ()));
423
425
if (!ctx)
424
426
return false ;
425
427
ctx->keyInfoReadCtx .flags |= XMLSEC_KEYINFO_FLAGS_X509DATA_DONT_VERIFY_CERTS;
0 commit comments