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
30{
32
33 // only add new indices right above this line
35};
36
38{
39 private:
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;
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
#define TC_SHARED_API
Definition Define.h:108
uint32_t uint32
Definition Define.h:133
LogLevel
Definition LogCommon.h:25
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
Secrets
Definition SecretMgr.h:30
@ NUM_SECRETS
Definition SecretMgr.h:34
@ SECRET_TOTP_MASTER_KEY
Definition SecretMgr.h:31
std::array< Secret, NUM_SECRETS > _secrets
Definition SecretMgr.h:70
SecretMgr(SecretMgr const &)=delete
BigNumber value
Definition SecretMgr.h:58
BigNumber const & operator*() const
Definition SecretMgr.h:51
BigNumber const * operator->() const
Definition SecretMgr.h:52
bool IsAvailable() const
Definition SecretMgr.h:53
std::mutex lock
Definition SecretMgr.h:56