aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/openssl/big_integer/big_integer.h
blob: 07763c5e1379182ce8554344769639d9202f1a5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include <util/generic/ptr.h>
#include <util/generic/strbuf.h>
#include <util/generic/utility.h>
#include <util/generic/string.h>

struct bignum_st;

namespace NOpenSsl {
    class TBigInteger {
        inline TBigInteger(bignum_st* impl) noexcept
            : Impl_(impl)
        {
        }

        static int Compare(const TBigInteger& a, const TBigInteger& b) noexcept;

    public:
        inline TBigInteger(TBigInteger&& other) noexcept {
            Swap(other);
        }

        ~TBigInteger() noexcept;

        static TBigInteger FromULong(ui64 value);
        static TBigInteger FromRegion(const void* ptr, size_t len);

        inline const bignum_st* Impl() const noexcept {
            return Impl_;
        }

        inline bignum_st* Impl() noexcept {
            return Impl_;
        }

        inline void Swap(TBigInteger& other) noexcept {
            DoSwap(Impl_, other.Impl_);
        }

        inline friend bool operator==(const TBigInteger& a, const TBigInteger& b) noexcept {
            return Compare(a, b) == 0;
        }

        inline friend bool operator!=(const TBigInteger& a, const TBigInteger& b) noexcept {
            return !(a == b);
        }

        size_t NumBytes() const noexcept;
        size_t ToRegion(void* to) const noexcept;

        TString ToDecimalString() const;

    private:
        bignum_st* Impl_ = nullptr;
    };
}