Virgil Security Crypto library  1.8.2
VirgilAsn1Writer.h
1 
37 #ifndef VIRGIL_CRYPTO_VIRGIL_ASN1_WRITER_H
38 #define VIRGIL_CRYPTO_VIRGIL_ASN1_WRITER_H
39 
40 #include <cstddef>
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() throw();
76 
80  void reset();
81 
86  void reset(size_t capacity);
87 
93  virgil::crypto::VirgilByteArray finish();
95 
98 
104  size_t writeInteger(int value);
105 
111  size_t writeBool(bool value);
112 
117  size_t writeNull();
118 
124  size_t writeOctetString(const virgil::crypto::VirgilByteArray& data);
125 
131  size_t writeUTF8String(const virgil::crypto::VirgilByteArray& data);
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:
180  static virgil::crypto::VirgilByteArray
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 private:
198  void checkState();
199 
203  void dispose() throw();
204 
210  void relocateBuffer(size_t newBufLen);
211 
218  void ensureBufferEnough(size_t len);
219 
223  VirgilAsn1Writer(const VirgilAsn1Writer& other);
224 
228  VirgilAsn1Writer& operator=(const VirgilAsn1Writer& rhs);
229 
230 private:
231  unsigned char* p_;
232  unsigned char* start_;
233  unsigned char* buf_;
234  size_t bufLen_;
235 };
236 
237 }}}}
238 
239 #endif /* VIRGIL_CRYPTO_VIRGIL_ASN1_WRITER_H */
VirgilAsn1Writer()
Initialize internal state for the first use.
~VirgilAsn1Writer()
Dispose internal resources.
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.
size_t writeContextTag(unsigned char tag, size_t len)
Write ASN.1 type: TAG.
Definition: VirgilAsn1Compatible.h:46
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.