AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::Impl::GenericHash< HashCreator, DigestLength > Class Template Reference

#include "CryptoHash.h"

Public Types

using Digest = std::array< uint8, DIGEST_LENGTH >
 

Public Member Functions

 GenericHash ()
 
 GenericHash (GenericHash const &right)
 
 GenericHash (GenericHash &&right) noexcept
 
 ~GenericHash ()
 
GenericHashoperator= (GenericHash const &right)
 
GenericHashoperator= (GenericHash &&right) noexcept
 
void UpdateData (uint8 const *data, size_t len)
 
void UpdateData (std::string_view str)
 
void UpdateData (std::string const &str)
 
void UpdateData (char const *str)
 
template<typename Container >
void UpdateData (Container const &c)
 
void Finalize ()
 
Digest const & GetDigest () const
 

Static Public Member Functions

static Digest GetDigestOf (uint8 const *data, size_t len)
 
template<typename... Ts>
static auto GetDigestOf (Ts &&... pack) -> std::enable_if_t<!(std::is_integral_v< std::decay_t< Ts > >||...), Digest >
 

Static Public Attributes

static constexpr size_t DIGEST_LENGTH = DigestLength
 

Private Attributes

EVP_MD_CTX * _ctx {}
 
Digest _digest {}
 

Detailed Description

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
class Acore::Impl::GenericHash< HashCreator, DigestLength >

Member Typedef Documentation

◆ Digest

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
using Acore::Impl::GenericHash< HashCreator, DigestLength >::Digest = std::array<uint8, DIGEST_LENGTH>

Constructor & Destructor Documentation

◆ GenericHash() [1/3]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
Acore::Impl::GenericHash< HashCreator, DigestLength >::GenericHash ( )
inline
71 {
72 int result = EVP_DigestInit_ex(_ctx, HashCreator(), nullptr);
73 ASSERT(result == 1);
74 }
#define ASSERT
Definition: Errors.h:68
static EVP_MD_CTX * MakeCTX() noexcept
Definition: CryptoHash.h:41
EVP_MD_CTX * _ctx
Definition: CryptoHash.h:139

References Acore::Impl::GenericHash< HashCreator, DigestLength >::_ctx, and ASSERT.

◆ GenericHash() [2/3]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
Acore::Impl::GenericHash< HashCreator, DigestLength >::GenericHash ( GenericHash< HashCreator, DigestLength > const &  right)
inline
77 {
78 *this = right;
79 }

◆ GenericHash() [3/3]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
Acore::Impl::GenericHash< HashCreator, DigestLength >::GenericHash ( GenericHash< HashCreator, DigestLength > &&  right)
inlinenoexcept
82 {
83 *this = std::move(right);
84 }

◆ ~GenericHash()

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
Acore::Impl::GenericHash< HashCreator, DigestLength >::~GenericHash ( )
inline
87 {
88 if (!_ctx)
89 return;
91 _ctx = nullptr;
92 }
static void DestroyCTX(EVP_MD_CTX *ctx)
Definition: CryptoHash.h:42

References Acore::Impl::GenericHash< HashCreator, DigestLength >::_ctx, and Acore::Impl::GenericHashImpl::DestroyCTX().

Member Function Documentation

◆ Finalize()

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
void Acore::Impl::GenericHash< HashCreator, DigestLength >::Finalize ( )
inline

◆ GetDigest()

◆ GetDigestOf() [1/2]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
template<typename... Ts>
static auto Acore::Impl::GenericHash< HashCreator, DigestLength >::GetDigestOf ( Ts &&...  pack) -> std::enable_if_t<!(std::is_integral_v<std::decay_t<Ts>> || ...), Digest>
inlinestatic
63 {
64 GenericHash hash;
65 (hash.UpdateData(std::forward<Ts>(pack)), ...);
66 hash.Finalize();
67 return hash.GetDigest();
68 }
GenericHash()
Definition: CryptoHash.h:70

References Acore::Impl::GenericHash< HashCreator, DigestLength >::Finalize(), Acore::Impl::GenericHash< HashCreator, DigestLength >::GetDigest(), and Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData().

◆ GetDigestOf() [2/2]

◆ operator=() [1/2]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
GenericHash & Acore::Impl::GenericHash< HashCreator, DigestLength >::operator= ( GenericHash< HashCreator, DigestLength > &&  right)
inlinenoexcept
106 {
107 if (this == &right)
108 return *this;
109
110 _ctx = std::exchange(right._ctx, GenericHashImpl::MakeCTX());
111 _digest = std::exchange(right._digest, Digest{});
112 return *this;
113 }
std::array< uint8, DIGEST_LENGTH > Digest
Definition: CryptoHash.h:51

References Acore::Impl::GenericHash< HashCreator, DigestLength >::_ctx, Acore::Impl::GenericHash< HashCreator, DigestLength >::_digest, and Acore::Impl::GenericHashImpl::MakeCTX().

◆ operator=() [2/2]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
GenericHash & Acore::Impl::GenericHash< HashCreator, DigestLength >::operator= ( GenericHash< HashCreator, DigestLength > const &  right)
inline
95 {
96 if (this == &right)
97 return *this;
98
99 int result = EVP_MD_CTX_copy_ex(_ctx, right._ctx);
100 ASSERT(result == 1);
101 _digest = right._digest;
102 return *this;
103 }

References Acore::Impl::GenericHash< HashCreator, DigestLength >::_ctx, Acore::Impl::GenericHash< HashCreator, DigestLength >::_digest, and ASSERT.

◆ UpdateData() [1/5]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
void Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData ( char const *  str)
inline
123{ UpdateData(std::string_view(str)); } /* explicit overload to avoid using the container template */
Definition: UpdateData.h:52

References Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData().

Referenced by Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData().

◆ UpdateData() [2/5]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
template<typename Container >
void Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData ( Container const &  c)
inline

◆ UpdateData() [3/5]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
void Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData ( std::string const &  str)
inline
122{ UpdateData(std::string_view(str)); } /* explicit overload to avoid using the container template */

References Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData().

Referenced by Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData().

◆ UpdateData() [4/5]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
void Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData ( std::string_view  str)
inline
121{ UpdateData(reinterpret_cast<uint8 const*>(str.data()), str.size()); }
std::uint8_t uint8
Definition: Define.h:110

References Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData().

Referenced by Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData().

◆ UpdateData() [5/5]

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
void Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData ( uint8 const *  data,
size_t  len 
)
inline

Member Data Documentation

◆ _ctx

◆ _digest

◆ DIGEST_LENGTH

template<GenericHashImpl::HashCreator HashCreator, size_t DigestLength>
constexpr size_t Acore::Impl::GenericHash< HashCreator, DigestLength >::DIGEST_LENGTH = DigestLength
staticconstexpr