big_integer.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include <util/generic/ptr.h>
  3. #include <util/generic/strbuf.h>
  4. #include <util/generic/utility.h>
  5. #include <util/generic/string.h>
  6. struct bignum_st;
  7. namespace NOpenSsl {
  8. class TBigInteger {
  9. inline TBigInteger(bignum_st* impl) noexcept
  10. : Impl_(impl)
  11. {
  12. }
  13. static int Compare(const TBigInteger& a, const TBigInteger& b) noexcept;
  14. public:
  15. inline TBigInteger(TBigInteger&& other) noexcept {
  16. Swap(other);
  17. }
  18. ~TBigInteger() noexcept;
  19. static TBigInteger FromULong(ui64 value);
  20. static TBigInteger FromRegion(const void* ptr, size_t len);
  21. inline const bignum_st* Impl() const noexcept {
  22. return Impl_;
  23. }
  24. inline bignum_st* Impl() noexcept {
  25. return Impl_;
  26. }
  27. inline void Swap(TBigInteger& other) noexcept {
  28. DoSwap(Impl_, other.Impl_);
  29. }
  30. inline friend bool operator==(const TBigInteger& a, const TBigInteger& b) noexcept {
  31. return Compare(a, b) == 0;
  32. }
  33. inline friend bool operator!=(const TBigInteger& a, const TBigInteger& b) noexcept {
  34. return !(a == b);
  35. }
  36. size_t NumBytes() const noexcept;
  37. size_t ToRegion(void* to) const noexcept;
  38. TString ToDecimalString() const;
  39. private:
  40. bignum_st* Impl_ = nullptr;
  41. };
  42. }