Plaintext.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "Plaintext.h"
  2. #include "openfhe/pke/encoding/plaintext.h"
  3. #include "openfhe/src/lib.rs.h" // ComplexPair
  4. namespace openfhe
  5. {
  6. Plaintext::Plaintext(const std::shared_ptr<PlaintextImpl>& plaintext)
  7. : m_plaintext(plaintext)
  8. { }
  9. Plaintext& Plaintext::operator=(const std::shared_ptr<PlaintextImpl>& plaintext)
  10. {
  11. m_plaintext = plaintext;
  12. return *this;
  13. }
  14. std::shared_ptr<PlaintextImpl> Plaintext::GetInternal() const
  15. {
  16. return m_plaintext;
  17. }
  18. void Plaintext::SetLength(const size_t newSize) const
  19. {
  20. m_plaintext->SetLength(newSize);
  21. }
  22. void Plaintext::SetLevel(const size_t l) const
  23. {
  24. m_plaintext->SetLevel(l);
  25. }
  26. bool Plaintext::IsEncoded() const
  27. {
  28. return m_plaintext->IsEncoded();
  29. }
  30. int64_t Plaintext::HighBound() const
  31. {
  32. return m_plaintext->HighBound();
  33. }
  34. int64_t Plaintext::LowBound() const
  35. {
  36. return m_plaintext->LowBound();
  37. }
  38. double Plaintext::GetLogPrecision() const
  39. {
  40. return m_plaintext->GetLogPrecision();
  41. }
  42. rust::String Plaintext::GetString() const
  43. {
  44. std::stringstream stream;
  45. stream << *m_plaintext;
  46. return rust::String(stream.str());
  47. }
  48. size_t Plaintext::GetLength() const
  49. {
  50. return m_plaintext->GetLength();
  51. }
  52. size_t Plaintext::GetLevel() const
  53. {
  54. return m_plaintext->GetLevel();
  55. }
  56. double Plaintext::GetLogError() const
  57. {
  58. return m_plaintext->GetLogError();
  59. }
  60. size_t Plaintext::GetNoiseScaleDeg() const
  61. {
  62. return m_plaintext->GetNoiseScaleDeg();
  63. }
  64. double Plaintext::GetScalingFactor() const
  65. {
  66. return m_plaintext->GetScalingFactor();
  67. }
  68. SCHEME Plaintext::GetSchemeID() const
  69. {
  70. return m_plaintext->GetSchemeID();
  71. }
  72. uint32_t Plaintext::GetSlots() const
  73. {
  74. return m_plaintext->GetSlots();
  75. }
  76. bool Plaintext::Encode() const
  77. {
  78. return m_plaintext->Encode();
  79. }
  80. bool Plaintext::Decode() const
  81. {
  82. return m_plaintext->Decode();
  83. }
  84. void Plaintext::SetFormat(const Format fmt) const
  85. {
  86. m_plaintext->SetFormat(fmt);
  87. }
  88. void Plaintext::SetIntVectorValue(const std::vector<int64_t>& val) const
  89. {
  90. m_plaintext->SetIntVectorValue(val);
  91. }
  92. void Plaintext::SetNoiseScaleDeg(const size_t nsd) const
  93. {
  94. m_plaintext->SetNoiseScaleDeg(nsd);
  95. }
  96. void Plaintext::SetScalingFactor(const double sf) const
  97. {
  98. m_plaintext->SetScalingFactor(sf);
  99. }
  100. void Plaintext::SetSlots(const uint32_t s) const
  101. {
  102. m_plaintext->SetSlots(s);
  103. }
  104. void Plaintext::SetStringValue(const std::string& value) const
  105. {
  106. m_plaintext->SetStringValue(value);
  107. }
  108. std::unique_ptr<std::vector<ComplexPair>> Plaintext::GetCopyOfCKKSPackedValue() const
  109. {
  110. const std::vector<std::complex<double>>& v = m_plaintext->GetCKKSPackedValue();
  111. std::vector<ComplexPair> result;
  112. result.reserve(v.size());
  113. for (const std::complex<double>& elem : v)
  114. {
  115. result.push_back(ComplexPair{elem.real(), elem.imag()});
  116. }
  117. return std::make_unique<std::vector<ComplexPair>>(std::move(result));
  118. }
  119. const std::vector<int64_t>& Plaintext::GetPackedValue() const
  120. {
  121. return m_plaintext->GetPackedValue();
  122. }
  123. std::unique_ptr<std::vector<double>>Plaintext::GetRealPackedValue() const
  124. {
  125. return std::make_unique<std::vector<double>>(std::move(m_plaintext->GetRealPackedValue()));
  126. }
  127. const std::vector<int64_t>& Plaintext::GetCoefPackedValue() const
  128. {
  129. return m_plaintext->GetCoefPackedValue();
  130. }
  131. const std::string& Plaintext::GetStringValue() const
  132. {
  133. return m_plaintext->GetStringValue();
  134. }
  135. // Generator functions
  136. std::unique_ptr<Plaintext> GenNullPlainText()
  137. {
  138. return std::make_unique<Plaintext>();
  139. }
  140. } // openfhe