Virgil Security Crypto library  2.0.7
VirgilAsn1Writer.h
1 
37 #ifndef VIRGIL_CRYPTO_VIRGIL_ASN1_WRITER_H
38 #define VIRGIL_CRYPTO_VIRGIL_ASN1_WRITER_H
39 
40 #include <cstdlib>
41 #include <string>
42 #include <vector>
43 
44 #include <virgil/crypto/VirgilByteArray.h>
45 
46 namespace virgil { namespace crypto { namespace foundation { namespace asn1 {
47 
55 public:
61 
67  VirgilAsn1Writer(size_t capacity);
68 
72  ~VirgilAsn1Writer() noexcept;
76 
80  void reset();
81 
86  void reset(size_t capacity);
87 
95 
98 
104  size_t writeInteger(int value);
105 
111  size_t writeBool(bool value);
112 
117  size_t writeNull();
118 
125 
132 
139  size_t writeContextTag(unsigned char tag, size_t len);
140 
146  size_t writeData(const virgil::crypto::VirgilByteArray& data);
147 
153  size_t writeOID(const std::string& oid);
155 
158 
164  size_t writeSequence(size_t len);
165 
171  size_t writeSet(const std::vector<virgil::crypto::VirgilByteArray>& set);
173 private:
181  makeComparePadding(const virgil::crypto::VirgilByteArray& asn1, size_t finalSize);
182 
186  static bool compare(const virgil::crypto::VirgilByteArray& first, const virgil::crypto::VirgilByteArray& second);
187 
191  static void makeOrderedSet(std::vector<virgil::crypto::VirgilByteArray>& set);
192 
193 public:
197  VirgilAsn1Writer(VirgilAsn1Writer&& other) = default;
198 
202  VirgilAsn1Writer& operator=(VirgilAsn1Writer&& rhs) = default;
203 
204 
205 private:
210  void checkState();
211 
215  void dispose() noexcept;
216 
222  void relocateBuffer(size_t newBufLen);
223 
230  void ensureBufferEnough(size_t len);
231 
232 private:
233  unsigned char* p_;
234  unsigned char* start_;
235  unsigned char* buf_;
236  size_t bufLen_;
237 };
238 
239 }}}}
240 
241 #endif /* VIRGIL_CRYPTO_VIRGIL_ASN1_WRITER_H */
VirgilAsn1Writer()
Initialize internal state for the first use.
VirgilAsn1Writer & operator=(VirgilAsn1Writer &&rhs)=default
Use default move operator.
size_t writeSequence(size_t len)
Write ASN.1 type: SEQUENCE.
This class provides methods for writing ASN.1 data structure.
Definition: VirgilAsn1Writer.h:54
size_t writeBool(bool value)
Write ASN.1 type: BOOLEAN.
size_t writeSet(const std::vector< virgil::crypto::VirgilByteArray > &set)
Write ASN.1 type: SET OF ANY.
virgil::crypto::VirgilByteArray finish()
Returns the result ASN.1 structure.
~VirgilAsn1Writer() noexcept
Dispose internal resources.
size_t writeContextTag(unsigned char tag, size_t len)
Write ASN.1 type: TAG.
Root namespace for all Virgil Security libraries.
Definition: VirgilAsn1Compatible.h:46
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:53
size_t writeNull()
Write ASN.1 type: NULL.
void reset()
Reset all internal states and prepare to new ASN.1 writing operations.
size_t writeInteger(int value)
Write ASN.1 type: INTEGER.
size_t writeData(const virgil::crypto::VirgilByteArray &data)
Write preformatted ASN.1 structure.
size_t writeUTF8String(const virgil::crypto::VirgilByteArray &data)
Write ASN.1 type: UTF8String.
size_t writeOctetString(const virgil::crypto::VirgilByteArray &data)
Write ASN.1 type: OCTET STRING.
size_t writeOID(const std::string &oid)
Write ASN.1 type: OID.