TrinityCore
Loading...
Searching...
No Matches
SecretMgr.h
Go to the documentation of this file.
1
/*
2
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#ifndef __TRINITY_SECRETMGR_H__
19
#define __TRINITY_SECRETMGR_H__
20
21
#include "
BigNumber.h
"
22
#include "
Common.h
"
23
#include "
LogCommon.h
"
24
#include "
Optional.h
"
25
#include <array>
26
#include <mutex>
27
#include <string>
28
29
enum
Secrets
:
uint32
30
{
31
SECRET_TOTP_MASTER_KEY
= 0,
32
33
// only add new indices right above this line
34
NUM_SECRETS
35
};
36
37
class
TC_SHARED_API
SecretMgr
38
{
39
private
:
40
SecretMgr
() {}
41
~SecretMgr
() {}
42
43
public
:
44
SecretMgr
(
SecretMgr
const
&) =
delete
;
45
static
SecretMgr
* instance();
46
47
struct
Secret
48
{
49
public
:
50
explicit
operator
bool()
const
{
return
(state == PRESENT); }
51
BigNumber
const
&
operator*
()
const
{
return
value; }
52
BigNumber
const
*
operator->
()
const
{
return
&value; }
53
bool
IsAvailable
()
const
{
return
(state != NOT_LOADED_YET) && (state != LOAD_FAILED); }
54
55
private
:
56
std::mutex
lock
;
57
enum
{ NOT_LOADED_YET,
LOAD_FAILED
, NOT_PRESENT, PRESENT } state = NOT_LOADED_YET;
58
BigNumber
value
;
59
60
friend
class
SecretMgr
;
61
};
62
63
void
Initialize();
64
Secret
const
& GetSecret(
Secrets
i);
65
66
private
:
67
void
AttemptLoad(
Secrets
i,
LogLevel
errorLevel, std::unique_lock<std::mutex>
const
&);
68
Optional<std::string>
AttemptTransition(
Secrets
i,
Optional<BigNumber>
const
& newSecret,
Optional<BigNumber>
const
& oldSecret,
bool
hadOldSecret)
const
;
69
70
std::array<Secret, NUM_SECRETS>
_secrets
;
71
};
72
73
#define sSecretMgr SecretMgr::instance()
74
75
#endif
BigNumber.h
Common.h
TC_SHARED_API
#define TC_SHARED_API
Definition
Define.h:108
uint32
uint32_t uint32
Definition
Define.h:133
LogCommon.h
LogLevel
LogLevel
Definition
LogCommon.h:25
Optional.h
Optional
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition
Optional.h:25
Secrets
Secrets
Definition
SecretMgr.h:30
NUM_SECRETS
@ NUM_SECRETS
Definition
SecretMgr.h:34
SECRET_TOTP_MASTER_KEY
@ SECRET_TOTP_MASTER_KEY
Definition
SecretMgr.h:31
BigNumber
Definition
BigNumber.h:30
SecretMgr
Definition
SecretMgr.h:38
SecretMgr::_secrets
std::array< Secret, NUM_SECRETS > _secrets
Definition
SecretMgr.h:70
SecretMgr::~SecretMgr
~SecretMgr()
Definition
SecretMgr.h:41
SecretMgr::SecretMgr
SecretMgr()
Definition
SecretMgr.h:40
SecretMgr::SecretMgr
SecretMgr(SecretMgr const &)=delete
SecretMgr::Secret
Definition
SecretMgr.h:48
SecretMgr::Secret::value
BigNumber value
Definition
SecretMgr.h:58
SecretMgr::Secret::operator*
BigNumber const & operator*() const
Definition
SecretMgr.h:51
SecretMgr::Secret::LOAD_FAILED
@ LOAD_FAILED
Definition
SecretMgr.h:57
SecretMgr::Secret::operator->
BigNumber const * operator->() const
Definition
SecretMgr.h:52
SecretMgr::Secret::IsAvailable
bool IsAvailable() const
Definition
SecretMgr.h:53
SecretMgr::Secret::lock
std::mutex lock
Definition
SecretMgr.h:56
server
shared
Secrets
SecretMgr.h
Generated on Sun May 10 2026 02:30:26 for TrinityCore by
1.9.8