TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BigNumber.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _AUTH_BIGNUMBER_H
20 #define _AUTH_BIGNUMBER_H
21 
22 #include <memory>
23 #include "Define.h"
24 #include <string>
25 
26 struct bignum_st;
27 
29 {
30  public:
31  BigNumber();
32  BigNumber(BigNumber const& bn);
34  ~BigNumber();
35 
36  void SetDword(uint32);
37  void SetQword(uint64);
38  void SetBinary(uint8 const* bytes, int32 len);
39  void SetHexStr(char const* str);
40 
41  void SetRand(int32 numbits);
42 
43  BigNumber& operator=(BigNumber const& bn);
44 
45  BigNumber operator+=(BigNumber const& bn);
47  {
48  BigNumber t(*this);
49  return t += bn;
50  }
51 
52  BigNumber operator-=(BigNumber const& bn);
54  {
55  BigNumber t(*this);
56  return t -= bn;
57  }
58 
59  BigNumber operator*=(BigNumber const& bn);
61  {
62  BigNumber t(*this);
63  return t *= bn;
64  }
65 
66  BigNumber operator/=(BigNumber const& bn);
68  {
69  BigNumber t(*this);
70  return t /= bn;
71  }
72 
73  BigNumber operator%=(BigNumber const& bn);
75  {
76  BigNumber t(*this);
77  return t %= bn;
78  }
79 
80  bool IsZero() const;
81  bool IsNegative() const;
82 
83  BigNumber ModExp(BigNumber const& bn1, BigNumber const& bn2);
84  BigNumber Exp(BigNumber const&);
85 
86  int32 GetNumBytes(void);
87 
88  struct bignum_st *BN() { return _bn; }
89 
90  uint32 AsDword();
91 
92  std::unique_ptr<uint8[]> AsByteArray(int32 minSize = 0, bool littleEndian = true);
93 
94  std::string AsHexStr() const;
95  std::string AsDecStr() const;
96 
97  private:
98  struct bignum_st *_bn;
99 
100 };
101 #endif
102 
Definition: BigNumber.h:28
unorm16 & operator+=(const unorm16 other)
Definition: unorm16.h:126
BigNumber operator*(BigNumber const &bn)
Definition: BigNumber.h:60
BigNumber operator+(BigNumber const &bn)
Definition: BigNumber.h:46
unorm16 & operator/=(const int i)
Definition: unorm16.h:153
BigNumber operator-(BigNumber const &bn)
Definition: BigNumber.h:53
struct bignum_st * BN()
Definition: BigNumber.h:88
unorm16 & operator-=(const unorm16 other)
Definition: unorm16.h:135
BigNumber operator%(BigNumber const &bn)
Definition: BigNumber.h:74
Vector2int16 & operator=(const Any &a)
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
unorm16 & operator*=(const int i)
Definition: unorm16.h:144
#define TC_COMMON_API
Definition: Define.h:116
struct bignum_st * _bn
Definition: BigNumber.h:98
uint8_t uint8
Definition: Define.h:152
BigNumber operator/(BigNumber const &bn)
Definition: BigNumber.h:67