tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

scoped_ptrs_ssl.h (1168B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef scoped_ptrs_ssl_h__
      8 #define scoped_ptrs_ssl_h__
      9 
     10 #include <memory>
     11 #include "sslexp.h"
     12 
     13 struct ScopedDeleteSSL {
     14  void operator()(SSLAeadContext* ctx) { SSL_DestroyAead(ctx); }
     15  void operator()(SSLMaskingContext* ctx) { SSL_DestroyMaskingContext(ctx); }
     16  void operator()(SSLAntiReplayContext* ctx) {
     17    SSL_ReleaseAntiReplayContext(ctx);
     18  }
     19  void operator()(SSLResumptionTokenInfo* token) {
     20    SSL_DestroyResumptionTokenInfo(token);
     21  }
     22 };
     23 
     24 template <class T>
     25 struct ScopedMaybeDeleteSSL {
     26  void operator()(T* ptr) {
     27    if (ptr) {
     28      ScopedDeleteSSL del;
     29      del(ptr);
     30    }
     31  }
     32 };
     33 
     34 #define SCOPED(x) typedef std::unique_ptr<x, ScopedMaybeDeleteSSL<x> > Scoped##x
     35 
     36 SCOPED(SSLAeadContext);
     37 SCOPED(SSLAntiReplayContext);
     38 SCOPED(SSLMaskingContext);
     39 SCOPED(SSLResumptionTokenInfo);
     40 
     41 #undef SCOPED
     42 
     43 #endif  // scoped_ptrs_ssl_h__