20
20
#include " X509Cert.h"
21
21
22
22
#include " crypto/OpenSSLHelpers.h"
23
- #include " crypto/X509Crypto.h"
24
23
#include " util/log.h"
25
24
26
25
#include < openssl/asn1t.h>
27
26
#include < openssl/pem.h>
28
27
#include < openssl/x509v3.h>
29
28
30
- #include < functional>
31
-
32
29
using namespace digidoc ;
33
30
using namespace std ;
34
31
@@ -229,7 +226,7 @@ X509Cert::X509Cert(const unsigned char *bytes, size_t size, Format format)
229
226
}
230
227
else
231
228
{
232
- SCOPE (BIO, bio, BIO_new_mem_buf ((void *)bytes, int (size)));
229
+ auto bio = make_unique_ptr<BIO_free>( BIO_new_mem_buf ((void *)bytes, int (size)));
233
230
cert.reset (PEM_read_bio_X509 (bio.get (), nullptr , nullptr , nullptr ), X509_free);
234
231
}
235
232
if (!cert)
@@ -247,7 +244,7 @@ X509Cert::X509Cert(const string &path, Format format)
247
244
{
248
245
if (path.empty ())
249
246
THROW (" No path given to parse X509." );
250
- SCOPE (BIO, bio, BIO_new_file (path.c_str (), " rb" ));
247
+ auto bio = make_unique_ptr<BIO_free>( BIO_new_file (path.c_str (), " rb" ));
251
248
if (!bio)
252
249
THROW_OPENSSLEXCEPTION (" Failed to open X.509 certificate file '%s'" , path.c_str ());
253
250
if (format == Der)
@@ -298,7 +295,7 @@ string X509Cert::serial() const
298
295
{
299
296
if (!cert)
300
297
return {};
301
- if (auto bn = make_unique_ptr (ASN1_INTEGER_to_BN (X509_get_serialNumber (cert.get ()), nullptr ), BN_free ))
298
+ if (auto bn = make_unique_ptr<BN_free> (ASN1_INTEGER_to_BN (X509_get_serialNumber (cert.get ()), nullptr )))
302
299
{
303
300
auto openssl_free = [](char *data) { OPENSSL_free (data); };
304
301
if (auto str = unique_ptr<char ,decltype (openssl_free)>(BN_bn2dec (bn.get ()), openssl_free))
@@ -327,7 +324,7 @@ vector<X509Cert::KeyUsage> X509Cert::keyUsage() const
327
324
vector<KeyUsage> usage;
328
325
if (!cert)
329
326
return usage;
330
- SCOPE (ASN1_BIT_STRING, keyusage, X509_get_ext_d2i (cert.get (), NID_key_usage, nullptr , nullptr ));
327
+ auto keyusage = make_unique_cast<ASN1_BIT_STRING_free>( X509_get_ext_d2i (cert.get (), NID_key_usage, nullptr , nullptr ));
331
328
if (!keyusage)
332
329
return usage;
333
330
@@ -347,7 +344,7 @@ vector<string> X509Cert::certificatePolicies() const
347
344
vector<string> pol;
348
345
if (!cert)
349
346
return pol;
350
- SCOPE (CERTIFICATEPOLICIES, cp, X509_get_ext_d2i (cert.get (), NID_certificate_policies, nullptr , nullptr ));
347
+ auto cp = make_unique_cast<CERTIFICATEPOLICIES_free>( X509_get_ext_d2i (cert.get (), NID_certificate_policies, nullptr , nullptr ));
351
348
if (!cp)
352
349
return pol;
353
350
for (int i = 0 ; i < sk_POLICYINFO_num (cp.get ()); ++i)
@@ -367,7 +364,7 @@ vector<string> X509Cert::qcStatements() const
367
364
if (pos == -1 )
368
365
return result;
369
366
X509_EXTENSION *ext = X509_get_ext (cert.get (), pos);
370
- SCOPE (QCStatements, qc, ASN1_item_unpack (X509_EXTENSION_get_data (ext), ASN1_ITEM_rptr (QCStatements)));
367
+ auto qc = make_unique_cast<QCStatements_free>( ASN1_item_unpack (X509_EXTENSION_get_data (ext), ASN1_ITEM_rptr (QCStatements)));
371
368
if (!qc)
372
369
return result;
373
370
@@ -380,33 +377,31 @@ vector<string> X509Cert::qcStatements() const
380
377
#ifndef TEMPLATE
381
378
if (!s->statementInfo )
382
379
continue ;
383
- SCOPE (SemanticsInformation, si, ASN1_item_unpack (s->statementInfo ->value .sequence , ASN1_ITEM_rptr (SemanticsInformation)));
380
+ auto si = make_unique_cast<SemanticsInformation_free>( ASN1_item_unpack (s->statementInfo ->value .sequence , ASN1_ITEM_rptr (SemanticsInformation)));
384
381
if (!si)
385
382
continue ;
386
- oid = toOID (si->semanticsIdentifier );
383
+ result. push_back ( toOID (si->semanticsIdentifier ) );
387
384
#else
388
- oid = toOID (s->statementInfo .semanticsInformation ->semanticsIdentifier );
385
+ result. push_back ( toOID (s->statementInfo .semanticsInformation ->semanticsIdentifier ) );
389
386
#endif
390
- result.push_back (oid);
391
387
}
392
388
else if (oid == QC_QCT)
393
389
{
394
390
#ifndef TEMPLATE
395
391
if (!s->statementInfo )
396
392
continue ;
397
- SCOPE (QcType, qct, ASN1_item_unpack (s->statementInfo ->value .sequence , ASN1_ITEM_rptr (QcType)));
393
+ auto qct = make_unique_cast<QcType_free>( ASN1_item_unpack (s->statementInfo ->value .sequence , ASN1_ITEM_rptr (QcType)));
398
394
if (!qct)
399
395
continue ;
400
396
for (int j = 0 ; j < sk_ASN1_OBJECT_num (qct.get ()); ++j)
401
397
{
402
- oid = toOID (sk_ASN1_OBJECT_value (qct.get (), j));
398
+ result. push_back ( toOID (sk_ASN1_OBJECT_value (qct.get (), j) ));
403
399
#else
404
400
#endif
405
- result.push_back (oid);
406
401
}
407
402
}
408
403
else
409
- result.push_back (oid);
404
+ result.push_back (std::move ( oid) );
410
405
}
411
406
return result;
412
407
}
@@ -463,7 +458,7 @@ string X509Cert::toString(const string &obj) const
463
458
}
464
459
else
465
460
{
466
- SCOPE (BIO, mem, BIO_new (BIO_s_mem ()));
461
+ auto mem = make_unique_ptr<BIO_free>( BIO_new (BIO_s_mem ()));
467
462
if (!mem)
468
463
THROW_OPENSSLEXCEPTION (" Failed to allocate memory for X509_NAME conversion" );
469
464
@@ -494,7 +489,7 @@ bool X509Cert::isCA() const
494
489
{
495
490
if (!cert)
496
491
return false ;
497
- SCOPE (BASIC_CONSTRAINTS, cons, X509_get_ext_d2i (cert.get (), NID_basic_constraints, nullptr , nullptr ));
492
+ auto cons = make_unique_cast<BASIC_CONSTRAINTS_free>( X509_get_ext_d2i (cert.get (), NID_basic_constraints, nullptr , nullptr ));
498
493
return cons && cons->ca > 0 ;
499
494
}
500
495
0 commit comments