PALISADE Lattice Crypto Library  1.11.9
A lattice crypto library for software engineers by software engineers.
stringencoding.h
1 // @file stringencoding.h Represents and defines string-encoded plaintext
2 // objects in Palisade.
3 // @author TPOC: contact@palisade-crypto.org
4 //
5 // @copyright Copyright (c) 2019, New Jersey Institute of Technology (NJIT)
6 // All rights reserved.
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // 1. Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution. THIS SOFTWARE IS
14 // PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 // EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 #ifndef SRC_CORE_LIB_ENCODING_STRINGENCODING_H_
26 #define SRC_CORE_LIB_ENCODING_STRINGENCODING_H_
27 
28 #include <memory>
29 #include <string>
30 
31 #include "encoding/plaintext.h"
32 using std::string;
33 
34 namespace lbcrypto {
35 
36 class StringEncoding : public PlaintextImpl {
37  string ptx;
38  // enum EncodingType { CHAR7bit } encoding = CHAR7bit;
39 
40  public:
41  // these three constructors are used inside of Decrypt
42  StringEncoding(shared_ptr<Poly::Params> vp, EncodingParams ep)
43  : PlaintextImpl(vp, ep) {}
44 
45  StringEncoding(shared_ptr<NativePoly::Params> vp, EncodingParams ep)
46  : PlaintextImpl(vp, ep) {}
47 
48  StringEncoding(shared_ptr<DCRTPoly::Params> vp, EncodingParams ep)
49  : PlaintextImpl(vp, ep) {}
50 
51  StringEncoding(shared_ptr<Poly::Params> vp, EncodingParams ep, string str)
52  : PlaintextImpl(vp, ep), ptx(str) {}
53 
54  StringEncoding(shared_ptr<NativePoly::Params> vp, EncodingParams ep,
55  string str)
56  : PlaintextImpl(vp, ep), ptx(str) {}
57 
58  StringEncoding(shared_ptr<DCRTPoly::Params> vp, EncodingParams ep, string str)
59  : PlaintextImpl(vp, ep), ptx(str) {}
60 
61  // TODO provide wide-character version (for unicode); right now this class
62  // only supports strings of 7-bit ASCII characters
63 
64  virtual ~StringEncoding() {}
65 
70  const string& GetStringValue() const { return ptx; }
71 
76  void SetStringValue(const std::string& value) { ptx = value; }
77 
82  bool Encode();
83 
88  bool Decode();
89 
94  PlaintextEncodings GetEncodingType() const { return String; }
95 
101  size_t GetLength() const { return ptx.size(); }
102 
110  bool CompareTo(const PlaintextImpl& other) const {
111  const auto& oth = static_cast<const StringEncoding&>(other);
112  return oth.ptx == this->ptx;
113  }
114 
119  void PrintValue(std::ostream& out) const { out << ptx; }
120 };
121 
122 } /* namespace lbcrypto */
123 
124 #endif /* SRC_CORE_LIB_ENCODING_STRINGENCODING_H_ */
const string & GetStringValue() const
Definition: stringencoding.h:70
PlaintextEncodings GetEncodingType() const
Definition: stringencoding.h:94
void PrintValue(std::ostream &out) const
Definition: stringencoding.h:119
bool Encode()
Definition: stringencoding.cpp:32
void SetStringValue(const std::string &value)
Definition: stringencoding.h:76
This class represents plaintext in the Palisade library.
Definition: plaintext.h:87
size_t GetLength() const
Definition: stringencoding.h:101
Definition: stringencoding.h:36
bool CompareTo(const PlaintextImpl &other) const
Definition: stringencoding.h:110
Definition: binfhecontext.h:36
bool Decode()
Definition: stringencoding.cpp:81