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, std::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, std::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 std::size_t DIGEST_LENGTH = DigestLength
 

Private Attributes

EVP_MD_CTX * _ctx {}
 
Digest _digest {}
 

Detailed Description

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

Member Typedef Documentation

◆ Digest

template<GenericHashImpl::HashCreator HashCreator, std::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, std::size_t DigestLength>
Acore::Impl::GenericHash< HashCreator, DigestLength >::GenericHash ( )
inline
66 {
67 int result = EVP_DigestInit_ex(_ctx, HashCreator(), nullptr);
68 ASSERT(result == 1);
69 }
#define ASSERT
Definition: Errors.h:68
static EVP_MD_CTX * MakeCTX() noexcept
Definition: CryptoHash.h:37
EVP_MD_CTX * _ctx
Definition: CryptoHash.h:134

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

◆ GenericHash() [2/3]

template<GenericHashImpl::HashCreator HashCreator, std::size_t DigestLength>
Acore::Impl::GenericHash< HashCreator, DigestLength >::GenericHash ( GenericHash< HashCreator, DigestLength > const &  right)
inline
72 {
73 *this = right;
74 }

◆ GenericHash() [3/3]

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

◆ ~GenericHash()

template<GenericHashImpl::HashCreator HashCreator, std::size_t DigestLength>
Acore::Impl::GenericHash< HashCreator, DigestLength >::~GenericHash ( )
inline
82 {
83 if (!_ctx)
84 return;
86 _ctx = nullptr;
87 }
static void DestroyCTX(EVP_MD_CTX *ctx)
Definition: CryptoHash.h:38

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

Member Function Documentation

◆ Finalize()

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

◆ GetDigest()

◆ GetDigestOf() [1/2]

template<GenericHashImpl::HashCreator HashCreator, std::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
58 {
59 GenericHash hash;
60 (hash.UpdateData(std::forward<Ts>(pack)), ...);
61 hash.Finalize();
62 return hash.GetDigest();
63 }
GenericHash()
Definition: CryptoHash.h:65

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, std::size_t DigestLength>
GenericHash & Acore::Impl::GenericHash< HashCreator, DigestLength >::operator= ( GenericHash< HashCreator, DigestLength > &&  right)
inlinenoexcept
101 {
102 if (this == &right)
103 return *this;
104
105 _ctx = std::exchange(right._ctx, GenericHashImpl::MakeCTX());
106 _digest = std::exchange(right._digest, Digest{});
107 return *this;
108 }
std::array< uint8, DIGEST_LENGTH > Digest
Definition: CryptoHash.h:46

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, std::size_t DigestLength>
GenericHash & Acore::Impl::GenericHash< HashCreator, DigestLength >::operator= ( GenericHash< HashCreator, DigestLength > const &  right)
inline
90 {
91 if (this == &right)
92 return *this;
93
94 int result = EVP_MD_CTX_copy_ex(_ctx, right._ctx);
95 ASSERT(result == 1);
96 _digest = right._digest;
97 return *this;
98 }

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

◆ UpdateData() [1/5]

template<GenericHashImpl::HashCreator HashCreator, std::size_t DigestLength>
void Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData ( char const *  str)
inline
118{ 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, std::size_t DigestLength>
template<typename Container >
void Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData ( Container const &  c)
inline

◆ UpdateData() [3/5]

template<GenericHashImpl::HashCreator HashCreator, std::size_t DigestLength>
void Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData ( std::string const &  str)
inline
117{ 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, std::size_t DigestLength>
void Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData ( std::string_view  str)
inline
116{ UpdateData(reinterpret_cast<uint8 const*>(str.data()), str.size()); }
std::uint8_t uint8
Definition: Define.h:109

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

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

◆ UpdateData() [5/5]

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

Member Data Documentation

◆ _ctx

◆ _digest

◆ DIGEST_LENGTH

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