proxygen
folly::ssl::OpenSSLHash::Digest Class Reference

#include <OpenSSLHash.h>

Public Member Functions

 Digest ()
 
 Digest (const Digest &other)
 
Digestoperator= (const Digest &other)
 
void hash_init (const EVP_MD *md)
 
void hash_update (ByteRange data)
 
void hash_update (const IOBuf &data)
 
void hash_final (MutableByteRange out)
 

Private Attributes

const EVP_MD * md_ = nullptr
 
EvpMdCtxUniquePtr ctx_ {nullptr}
 

Detailed Description

Definition at line 31 of file OpenSSLHash.h.

Constructor & Destructor Documentation

folly::ssl::OpenSSLHash::Digest::Digest ( )
inline

Definition at line 33 of file OpenSSLHash.h.

Referenced by operator=().

33 : ctx_(EVP_MD_CTX_new()) {}
EVP_MD_CTX * EVP_MD_CTX_new()
Definition: OpenSSL.cpp:321
folly::ssl::OpenSSLHash::Digest::Digest ( const Digest other)
inline

Definition at line 35 of file OpenSSLHash.h.

References folly::ssl::OpenSSLHash::check_libssl_result(), ctx_, folly::portability::ssl::EVP_MD_CTX_new(), hash_init(), and md_.

35  {
37  if (other.md_ != nullptr) {
38  hash_init(other.md_);
40  1, EVP_MD_CTX_copy_ex(ctx_.get(), other.ctx_.get()));
41  }
42  }
void hash_init(const EVP_MD *md)
Definition: OpenSSLHash.h:49
static void check_libssl_result(int expected, int result)
Definition: OpenSSLHash.h:176
EVP_MD_CTX * EVP_MD_CTX_new()
Definition: OpenSSL.cpp:321
std::unique_ptr< EVP_MD_CTX, EvpMdCtxDeleter > EvpMdCtxUniquePtr

Member Function Documentation

void folly::ssl::OpenSSLHash::Digest::hash_final ( MutableByteRange  out)
inline

Definition at line 62 of file OpenSSLHash.h.

References folly::ssl::OpenSSLHash::check_libssl_result(), folly::ssl::OpenSSLHash::check_out_size(), ctx_, folly::Range< Iter >::data(), md_, and folly::size().

Referenced by proxygen::HTTP1xCodec::generateWebsocketAccept(), fizz::HandshakeContextImpl< Hash >::getHandshakeContext(), folly::ssl::OpenSSLHash::hash(), and TEST_F().

62  {
63  const auto size = EVP_MD_size(md_);
64  check_out_size(size_t(size), out);
65  unsigned int len = 0;
66  check_libssl_result(1, EVP_DigestFinal_ex(ctx_.get(), out.data(), &len));
67  check_libssl_result(size, int(len));
68  md_ = nullptr;
69  }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
static void check_libssl_result(int expected, int result)
Definition: OpenSSLHash.h:176
static void check_out_size(size_t size, MutableByteRange out)
Definition: OpenSSLHash.h:166
void folly::ssl::OpenSSLHash::Digest::hash_init ( const EVP_MD *  md)
inline

Definition at line 49 of file OpenSSLHash.h.

References folly::ssl::OpenSSLHash::check_libssl_result(), ctx_, and md_.

Referenced by Digest(), proxygen::HTTP1xCodec::generateWebsocketAccept(), fizz::HandshakeContextImpl< Hash >::HandshakeContextImpl(), folly::ssl::OpenSSLHash::hash(), and TEST_F().

49  {
50  md_ = md;
51  check_libssl_result(1, EVP_DigestInit_ex(ctx_.get(), md, nullptr));
52  }
static void check_libssl_result(int expected, int result)
Definition: OpenSSLHash.h:176
void folly::ssl::OpenSSLHash::Digest::hash_update ( ByteRange  data)
inline
void folly::ssl::OpenSSLHash::Digest::hash_update ( const IOBuf data)
inline

Definition at line 57 of file OpenSSLHash.h.

References hash_update().

57  {
58  for (auto r : data) {
59  hash_update(r);
60  }
61  }
void hash_update(ByteRange data)
Definition: OpenSSLHash.h:53
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
Digest& folly::ssl::OpenSSLHash::Digest::operator= ( const Digest other)
inline

Definition at line 44 of file OpenSSLHash.h.

References Digest().

44  {
45  this->~Digest();
46  return *new (this) Digest(other);
47  }

Member Data Documentation

const EVP_MD* folly::ssl::OpenSSLHash::Digest::md_ = nullptr
private

The documentation for this class was generated from the following file: