Crypto++  5.6.5
Free C++ class library of cryptographic schemes
asn.h
Go to the documentation of this file.
1 // asn.h - written and placed in the public domain by Wei Dai
2 
3 //! \file asn.h
4 //! \brief Classes and functions for working with ANS.1 objects
5 
6 #ifndef CRYPTOPP_ASN_H
7 #define CRYPTOPP_ASN_H
8 
9 #include "cryptlib.h"
10 #include "filters.h"
11 #include "smartptr.h"
12 #include "stdcpp.h"
13 #include "queue.h"
14 #include "misc.h"
15 
16 // Issue 340
17 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
18 # pragma GCC diagnostic push
19 # pragma GCC diagnostic ignored "-Wconversion"
20 # pragma GCC diagnostic ignored "-Wsign-conversion"
21 #endif
22 
23 NAMESPACE_BEGIN(CryptoPP)
24 
25 //! \brief ASN.1 types
26 //! \note These tags and flags are not complete
27 enum ASNTag
28 {
29  BOOLEAN = 0x01,
30  INTEGER = 0x02,
31  BIT_STRING = 0x03,
32  OCTET_STRING = 0x04,
33  TAG_NULL = 0x05,
34  OBJECT_IDENTIFIER = 0x06,
35  OBJECT_DESCRIPTOR = 0x07,
36  EXTERNAL = 0x08,
37  REAL = 0x09,
38  ENUMERATED = 0x0a,
39  UTF8_STRING = 0x0c,
40  SEQUENCE = 0x10,
41  SET = 0x11,
42  NUMERIC_STRING = 0x12,
43  PRINTABLE_STRING = 0x13,
44  T61_STRING = 0x14,
45  VIDEOTEXT_STRING = 0x15,
46  IA5_STRING = 0x16,
47  UTC_TIME = 0x17,
48  GENERALIZED_TIME = 0x18,
49  GRAPHIC_STRING = 0x19,
50  VISIBLE_STRING = 0x1a,
51  GENERAL_STRING = 0x1b
52 };
53 
54 //! \brief ASN.1 flags
55 //! \note These tags and flags are not complete
57 {
58  UNIVERSAL = 0x00,
59 // DATA = 0x01,
60 // HEADER = 0x02,
61  CONSTRUCTED = 0x20,
62  APPLICATION = 0x40,
63  CONTEXT_SPECIFIC = 0x80,
64  PRIVATE = 0xc0
65 };
66 
67 //! \brief Raises a BERDecodeErr
68 inline void BERDecodeError() {throw BERDecodeErr();}
69 
70 //! \brief Exception thrown when an unknown object identifier is encountered
71 class CRYPTOPP_DLL UnknownOID : public BERDecodeErr
72 {
73 public:
74  //! \brief Construct an UnknownOID
75  UnknownOID() : BERDecodeErr("BER decode error: unknown object identifier") {}
76  //! \brief Construct an UnknownOID
77  //! \param err error message to use for the execption
78  UnknownOID(const char *err) : BERDecodeErr(err) {}
79 };
80 
81 // unsigned int DERLengthEncode(unsigned int length, byte *output=0);
82 
83 //! \brief DER encode a length
84 //! \param bt BufferedTransformation object for writing
85 //! \param length the size to encode
86 //! \returns the number of octets used for the encoding
87 CRYPTOPP_DLL size_t CRYPTOPP_API DERLengthEncode(BufferedTransformation &bt, lword length);
88 
89 //! \brief BER decode a length
90 //! \param bt BufferedTransformation object for reading
91 //! \param length the decoded size
92 //! \returns true if the value was decoded
93 //! \throws BERDecodeError if the value fails to decode or is too large for size_t
94 //! \details BERLengthDecode() returns false if the encoding is indefinite length.
95 CRYPTOPP_DLL bool CRYPTOPP_API BERLengthDecode(BufferedTransformation &bt, size_t &length);
96 
97 //! \brief DER encode NULL
98 //! \param bt BufferedTransformation object for writing
99 CRYPTOPP_DLL void CRYPTOPP_API DEREncodeNull(BufferedTransformation &bt);
100 
101 //! \brief BER decode NULL
102 //! \param bt BufferedTransformation object for reading
103 CRYPTOPP_DLL void CRYPTOPP_API BERDecodeNull(BufferedTransformation &bt);
104 
105 //! \brief DER encode octet string
106 //! \param bt BufferedTransformation object for writing
107 //! \param str the string to encode
108 //! \param strLen the length of the string
109 //! \returns the number of octets used for the encoding
110 CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen);
111 
112 //! \brief DER encode octet string
113 //! \param bt BufferedTransformation object for reading
114 //! \param str the string to encode
115 //! \returns the number of octets used for the encoding
116 CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &bt, const SecByteBlock &str);
117 
118 //! \brief BER decode octet string
119 //! \param bt BufferedTransformation object for reading
120 //! \param str the decoded string
121 //! \returns the number of octets used for the encoding
122 CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str);
123 
124 //! \brief BER decode octet string
125 //! \param bt BufferedTransformation object for reading
126 //! \param str the decoded string
127 //! \returns the number of octets used for the encoding
128 CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &bt, BufferedTransformation &str);
129 
130 //! \brief DER encode text string
131 //! \param bt BufferedTransformation object for writing
132 //! \param str the string to encode
133 //! \param asnTag the ASN.1 type
134 //! \returns the number of octets used for the encoding
135 //! \details DEREncodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
136 CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const std::string &str, byte asnTag);
137 
138 //! \brief BER decode text string
139 //! \param bt BufferedTransformation object for reading
140 //! \param str the string to encode
141 //! \param asnTag the ASN.1 type
142 //! \details DEREncodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
143 CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte asnTag);
144 
145 //! \brief DER encode bit string
146 //! \param bt BufferedTransformation object for writing
147 //! \param str the string to encode
148 //! \param strLen the length of the string
149 //! \param unusedBits the number of unused bits
150 //! \returns the number of octets used for the encoding
151 CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0);
152 
153 //! \brief DER decode bit string
154 //! \param bt BufferedTransformation object for reading
155 //! \param str the decoded string
156 //! \param unusedBits the number of unused bits
157 CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits);
158 
159 //! \brief BER decode and DER re-encode
160 //! \param bt BufferedTransformation object for writing
161 //! \param dest BufferedTransformation object
162 CRYPTOPP_DLL void CRYPTOPP_API DERReencode(BufferedTransformation &bt, BufferedTransformation &dest);
163 
164 //! \brief Object Identifier
165 class CRYPTOPP_DLL OID
166 {
167 public:
168  virtual ~OID() {}
169 
170  //! \brief Construct an OID
171  OID() {}
172  //! \brief Construct an OID
173  //! \param v value to initialize the OID
174  OID(word32 v) : m_values(1, v) {}
175  //! \brief Construct an OID
176  //! \param bt BufferedTransformation object
177  OID(BufferedTransformation &bt) {BERDecode(bt);}
178 
179  //! \brief Append a value to an OID
180  //! \param rhs the value to append
181  inline OID & operator+=(word32 rhs) {m_values.push_back(rhs); return *this;}
182 
183  //! \brief DER encode this OID
184  //! \param bt BufferedTransformation object
185  void DEREncode(BufferedTransformation &bt) const;
186 
187  //! \brief BER decode an OID
188  //! \param bt BufferedTransformation object
189  void BERDecode(BufferedTransformation &bt);
190 
191  //! \brief BER decode an OID
192  //! \param bt BufferedTransformation object
193  //! \throws BERDecodeErr() if decoded value doesn't match an expected OID
194  //! \details BERDecodeAndCheck() can be used to parse an OID and verify it matches an expected.
195  //! <pre>
196  //! BERSequenceDecoder key(bt);
197  //! ...
198  //! BERSequenceDecoder algorithm(key);
199  //! GetAlgorithmID().BERDecodeAndCheck(algorithm);
200  //! </pre>
201  void BERDecodeAndCheck(BufferedTransformation &bt) const;
202 
203  std::vector<word32> m_values;
204 
205 private:
206  static void EncodeValue(BufferedTransformation &bt, word32 v);
207  static size_t DecodeValue(BufferedTransformation &bt, word32 &v);
208 };
209 
210 //! \brief ASN.1 encoded object filter
212 {
213 public:
214  enum Flag {PUT_OBJECTS=1, PUT_MESSANGE_END_AFTER_EACH_OBJECT=2, PUT_MESSANGE_END_AFTER_ALL_OBJECTS=4, PUT_MESSANGE_SERIES_END_AFTER_ALL_OBJECTS=8};
215 
216  virtual ~EncodedObjectFilter() {}
217 
218  //! \brief Construct an EncodedObjectFilter
219  //! \param attachment a BufferedTrasformation to attach to this object
220  //! \param nObjects
221  //! \param flags bitwise OR of EncodedObjectFilter::Flag
222  EncodedObjectFilter(BufferedTransformation *attachment = NULL, unsigned int nObjects = 1, word32 flags = 0);
223 
224  //! \brief Input a byte buffer for processing
225  //! \param inString the byte buffer to process
226  //! \param length the size of the string, in bytes
227  void Put(const byte *inString, size_t length);
228 
229  unsigned int GetNumberOfCompletedObjects() const {return m_nCurrentObject;}
230  unsigned long GetPositionOfObject(unsigned int i) const {return m_positions[i];}
231 
232 private:
233  BufferedTransformation & CurrentTarget();
234 
235  word32 m_flags;
236  unsigned int m_nObjects, m_nCurrentObject, m_level;
237  std::vector<unsigned int> m_positions;
238  ByteQueue m_queue;
239  enum State {IDENTIFIER, LENGTH, BODY, TAIL, ALL_DONE} m_state;
240  byte m_id;
241  lword m_lengthRemaining;
242 };
243 
244 //! \brief BER General Decoder
245 class CRYPTOPP_DLL BERGeneralDecoder : public Store
246 {
247 public:
248  virtual ~BERGeneralDecoder();
249 
250  explicit BERGeneralDecoder(BufferedTransformation &inQueue, byte asnTag);
251  explicit BERGeneralDecoder(BERGeneralDecoder &inQueue, byte asnTag);
252 
253  bool IsDefiniteLength() const {return m_definiteLength;}
254  lword RemainingLength() const {CRYPTOPP_ASSERT(m_definiteLength); return m_length;}
255  bool EndReached() const;
256  byte PeekByte() const;
257  void CheckByte(byte b);
258 
259  size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
260  size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
261 
262  // call this to denote end of sequence
263  void MessageEnd();
264 
265 protected:
266  BufferedTransformation &m_inQueue;
267  bool m_finished, m_definiteLength;
268  lword m_length;
269 
270 private:
271  void Init(byte asnTag);
272  void StoreInitialize(const NameValuePairs &parameters)
273  {CRYPTOPP_UNUSED(parameters); CRYPTOPP_ASSERT(false);}
274  lword ReduceLength(lword delta);
275 };
276 
277 // GCC (and likely other compilers) identify the explicit DERGeneralEncoder as a copy constructor;
278 // and not a constructor. We had to remove the default asnTag value to point the compiler in the
279 // proper direction. We did not break the library or versioning based on the output of
280 // `nm --demangle libcryptopp.a | grep DERGeneralEncoder::DERGeneralEncoder | grep -v " U "`.
281 
282 //! \brief DER General Encoder
283 class CRYPTOPP_DLL DERGeneralEncoder : public ByteQueue
284 {
285 public:
286  virtual ~DERGeneralEncoder();
287 
288  explicit DERGeneralEncoder(BufferedTransformation &outQueue, byte asnTag = SEQUENCE | CONSTRUCTED);
289  explicit DERGeneralEncoder(DERGeneralEncoder &outQueue, byte asnTag = SEQUENCE | CONSTRUCTED);
290 
291  // call this to denote end of sequence
292  void MessageEnd();
293 
294 private:
295  BufferedTransformation &m_outQueue;
296  bool m_finished;
297 
298  byte m_asnTag;
299 };
300 
301 //! \brief BER Sequence Decoder
302 class CRYPTOPP_DLL BERSequenceDecoder : public BERGeneralDecoder
303 {
304 public:
305  explicit BERSequenceDecoder(BufferedTransformation &inQueue, byte asnTag = SEQUENCE | CONSTRUCTED)
306  : BERGeneralDecoder(inQueue, asnTag) {}
307  explicit BERSequenceDecoder(BERSequenceDecoder &inQueue, byte asnTag = SEQUENCE | CONSTRUCTED)
308  : BERGeneralDecoder(inQueue, asnTag) {}
309 };
310 
311 //! \brief DER Sequence Encoder
312 class CRYPTOPP_DLL DERSequenceEncoder : public DERGeneralEncoder
313 {
314 public:
315  explicit DERSequenceEncoder(BufferedTransformation &outQueue, byte asnTag = SEQUENCE | CONSTRUCTED)
316  : DERGeneralEncoder(outQueue, asnTag) {}
317  explicit DERSequenceEncoder(DERSequenceEncoder &outQueue, byte asnTag = SEQUENCE | CONSTRUCTED)
318  : DERGeneralEncoder(outQueue, asnTag) {}
319 };
320 
321 //! \brief BER Set Decoder
322 class CRYPTOPP_DLL BERSetDecoder : public BERGeneralDecoder
323 {
324 public:
325  explicit BERSetDecoder(BufferedTransformation &inQueue, byte asnTag = SET | CONSTRUCTED)
326  : BERGeneralDecoder(inQueue, asnTag) {}
327  explicit BERSetDecoder(BERSetDecoder &inQueue, byte asnTag = SET | CONSTRUCTED)
328  : BERGeneralDecoder(inQueue, asnTag) {}
329 };
330 
331 //! \brief DER Set Encoder
332 class CRYPTOPP_DLL DERSetEncoder : public DERGeneralEncoder
333 {
334 public:
335  explicit DERSetEncoder(BufferedTransformation &outQueue, byte asnTag = SET | CONSTRUCTED)
336  : DERGeneralEncoder(outQueue, asnTag) {}
337  explicit DERSetEncoder(DERSetEncoder &outQueue, byte asnTag = SET | CONSTRUCTED)
338  : DERGeneralEncoder(outQueue, asnTag) {}
339 };
340 
341 //! \brief Optional data encoder and decoder
342 //! \tparam T class or type
343 template <class T>
344 class ASNOptional : public member_ptr<T>
345 {
346 public:
347  //! \brief BER decode optional data
348  //! \param seqDecoder sequence with the optional ASN.1 data
349  //! \param tag ASN.1 tag to match as optional data
350  //! \param mask the mask to apply when matching the tag
351  //! \sa ASNTag and ASNIdFlag
352  void BERDecode(BERSequenceDecoder &seqDecoder, byte tag, byte mask = ~CONSTRUCTED)
353  {
354  byte b;
355  if (seqDecoder.Peek(b) && (b & mask) == tag)
356  reset(new T(seqDecoder));
357  }
358 
359  //! \brief DER encode optional data
360  //! \param out BufferedTransformation object
362  {
363  if (this->get() != NULL)
364  this->get()->DEREncode(out);
365  }
366 };
367 
368 //! \brief Encode and decode ASN.1 objects with additional information
369 //! \tparam BASE base class or type
370 //! \details Encodes and decodes public keys, private keys and group
371 //! parameters with OID identifying the algorithm or scheme.
372 template <class BASE>
373 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ASN1CryptoMaterial : public ASN1Object, public BASE
374 {
375 public:
376  //! \brief DER encode ASN.1 object
377  //! \param bt BufferedTransformation object
378  //! \details Save() will write the OID associated with algorithm or scheme.
379  //! In the case of public and private keys, this function writes the
380  //! subjectPubicKeyInfo and privateKeyInfo parts.
381  void Save(BufferedTransformation &bt) const
382  {BEREncode(bt);}
383 
384  //! \brief BER decode ASN.1 object
385  //! \param bt BufferedTransformation object
387  {BERDecode(bt);}
388 };
389 
390 //! \brief Encodes and decodes subjectPublicKeyInfo
391 class CRYPTOPP_DLL X509PublicKey : public ASN1CryptoMaterial<PublicKey>
392 {
393 public:
394  virtual ~X509PublicKey() {}
395 
397  void DEREncode(BufferedTransformation &bt) const;
398 
399  //! \brief Retrieves the OID of the algorithm
400  //! \returns OID of the algorithm
401  virtual OID GetAlgorithmID() const =0;
402  virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
403  {BERDecodeNull(bt); return false;}
404  virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
405  {DEREncodeNull(bt); return false;} // see RFC 2459, section 7.3.1
406 
407  //! decode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header
408  virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0;
409  //! encode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header
410  virtual void DEREncodePublicKey(BufferedTransformation &bt) const =0;
411 };
412 
413 //! \brief Encodes and decodesprivateKeyInfo
414 class CRYPTOPP_DLL PKCS8PrivateKey : public ASN1CryptoMaterial<PrivateKey>
415 {
416 public:
417  virtual ~PKCS8PrivateKey() {}
418 
420  void DEREncode(BufferedTransformation &bt) const;
421 
422  //! \brief Retrieves the OID of the algorithm
423  //! \returns OID of the algorithm
424  virtual OID GetAlgorithmID() const =0;
425  virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
426  {BERDecodeNull(bt); return false;}
427  virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
428  {DEREncodeNull(bt); return false;} // see RFC 2459, section 7.3.1
429 
430  //! decode privateKey part of privateKeyInfo, without the OCTET STRING header
431  virtual void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0;
432  //! encode privateKey part of privateKeyInfo, without the OCTET STRING header
433  virtual void DEREncodePrivateKey(BufferedTransformation &bt) const =0;
434 
435  //! decode optional attributes including context-specific tag
436  /*! /note default implementation stores attributes to be output in DEREncodeOptionalAttributes */
437  virtual void BERDecodeOptionalAttributes(BufferedTransformation &bt);
438  //! encode optional attributes including context-specific tag
439  virtual void DEREncodeOptionalAttributes(BufferedTransformation &bt) const;
440 
441 protected:
442  ByteQueue m_optionalAttributes;
443 };
444 
445 // ********************************************************
446 
447 //! \brief DER Encode unsigned value
448 //! \tparam T class or type
449 //! \param out BufferedTransformation object
450 //! \param w unsigned value to encode
451 //! \param asnTag the ASN.1 type
452 //! \details DEREncodeUnsigned() can be used with INTEGER, BOOLEAN, and ENUM
453 template <class T>
454 size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag = INTEGER)
455 {
456  byte buf[sizeof(w)+1];
457  unsigned int bc;
458  if (asnTag == BOOLEAN)
459  {
460  buf[sizeof(w)] = w ? 0xff : 0;
461  bc = 1;
462  }
463  else
464  {
465  buf[0] = 0;
466  for (unsigned int i=0; i<sizeof(w); i++)
467  buf[i+1] = byte(w >> (sizeof(w)-1-i)*8);
468  bc = sizeof(w);
469  while (bc > 1 && buf[sizeof(w)+1-bc] == 0)
470  --bc;
471  if (buf[sizeof(w)+1-bc] & 0x80)
472  ++bc;
473  }
474  out.Put(asnTag);
475  size_t lengthBytes = DERLengthEncode(out, bc);
476  out.Put(buf+sizeof(w)+1-bc, bc);
477  return 1+lengthBytes+bc;
478 }
479 
480 //! \brief BER Decode unsigned value
481 //! \tparam T class or type
482 //! \param in BufferedTransformation object
483 //! \param w unsigned value to encode
484 //! \param asnTag the ASN.1 type
485 //! \param minValue the minimum expected value
486 //! \param maxValue the maximum expected value
487 //! \throws BERDecodeErr() if the value cannot be parsed or the decoded value is not within range.
488 //! \details DEREncodeUnsigned() can be used with INTEGER, BOOLEAN, and ENUM
489 template <class T>
490 void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag = INTEGER,
491  T minValue = 0, T maxValue = ((std::numeric_limits<T>::max)()))
492 {
493  byte b;
494  if (!in.Get(b) || b != asnTag)
495  BERDecodeError();
496 
497  size_t bc;
498  bool definite = BERLengthDecode(in, bc);
499  if (!definite)
500  BERDecodeError();
501 
502  SecByteBlock buf(bc);
503 
504  if (bc != in.Get(buf, bc))
505  BERDecodeError();
506 
507  const byte *ptr = buf;
508  while (bc > sizeof(w) && *ptr == 0)
509  {
510  bc--;
511  ptr++;
512  }
513  if (bc > sizeof(w))
514  BERDecodeError();
515 
516  w = 0;
517  for (unsigned int i=0; i<bc; i++)
518  w = (w << 8) | ptr[i];
519 
520  if (w < minValue || w > maxValue)
521  BERDecodeError();
522 }
523 
524 #ifdef CRYPTOPP_DOXYGEN_PROCESSING
525 //! \brief Compare two OIDs for equality
526 //! \param lhs the first OID
527 //! \param rhs the second OID
528 //! \returns true if the OIDs are equal, false otherwise
529 inline bool operator==(const OID &lhs, const OID &rhs);
530 //! \brief Compare two OIDs for inequality
531 //! \param lhs the first OID
532 //! \param rhs the second OID
533 //! \returns true if the OIDs are not equal, false otherwise
534 inline bool operator!=(const OID &lhs, const OID &rhs);
535 //! \brief Compare two OIDs for ordering
536 //! \param lhs the first OID
537 //! \param rhs the second OID
538 //! \returns true if the first OID is less than the second OID, false otherwise
539 //! \details operator<() calls std::lexicographical_compare() on each element in the array of values.
540 inline bool operator<(const OID &lhs, const OID &rhs);
541 //! \brief Append a value to an OID
542 //! \param lhs the OID
543 //! \param rhs the value to append
544 inline OID operator+(const OID &lhs, unsigned long rhs);
545 #else
546 inline bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
547  {return lhs.m_values == rhs.m_values;}
548 inline bool operator!=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
549  {return lhs.m_values != rhs.m_values;}
550 inline bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
551  {return std::lexicographical_compare(lhs.m_values.begin(), lhs.m_values.end(), rhs.m_values.begin(), rhs.m_values.end());}
552 inline ::CryptoPP::OID operator+(const ::CryptoPP::OID &lhs, unsigned long rhs)
553  {return ::CryptoPP::OID(lhs)+=rhs;}
554 #endif
555 
556 NAMESPACE_END
557 
558 // Issue 340
559 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
560 # pragma GCC diagnostic pop
561 #endif
562 
563 #endif
UnknownOID(const char *err)
Construct an UnknownOID.
Definition: asn.h:78
Utility functions for the Crypto++ library.
virtual size_t Peek(byte &outByte) const
Peek a 8-bit byte.
Definition: cryptlib.cpp:534
size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag=INTEGER)
DER Encode unsigned value.
Definition: asn.h:454
Encodes and decodesprivateKeyInfo.
Definition: asn.h:414
void DEREncodeNull(BufferedTransformation &bt)
DER encode NULL.
Definition: asn.cpp:87
Abstract base classes that provide a uniform interface to this library.
OID()
Construct an OID.
Definition: asn.h:171
Classes for automatic resource management.
void DEREncode(BufferedTransformation &out)
DER encode optional data.
Definition: asn.h:361
virtual size_t TransferTo2(BufferedTransformation &target, lword &byteCount, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)=0
Transfer bytes from this object to another BufferedTransformation.
EncodedObjectFilter(BufferedTransformation *attachment=NULL, unsigned int nObjects=1, word32 flags=0)
Construct an EncodedObjectFilter.
Acts as a Source for pre-existing, static data.
Definition: simple.h:299
BER Set Decoder.
Definition: asn.h:322
SecBlock typedef.
Definition: secblock.h:731
BER Sequence Decoder.
Definition: asn.h:302
Interface for buffered transformations.
Definition: cryptlib.h:1352
OID(BufferedTransformation &bt)
Construct an OID.
Definition: asn.h:177
bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
Pointer that overloads operator ->
Definition: smartptr.h:39
Optional data encoder and decoder.
Definition: asn.h:344
ASNIdFlag
ASN.1 flags.
Definition: asn.h:56
void BERDecode(BERSequenceDecoder &seqDecoder, byte tag, byte mask=~CONSTRUCTED)
BER decode optional data.
Definition: asn.h:352
bool operator!=(const OID &lhs, const OID &rhs)
Compare two OIDs for inequality.
bool MessageEnd(int propagation=-1, bool blocking=true)
Signals the end of messages to the object.
Definition: cryptlib.h:1434
Classes for an unlimited queue to store bytes.
void BERDecodeNull(BufferedTransformation &bt)
BER decode NULL.
Definition: asn.cpp:93
bool operator<(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
size_t Put(byte inByte, bool blocking=true)
Input a byte for processing.
Definition: cryptlib.h:1376
size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
BER decode octet string.
Definition: asn.cpp:117
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Definition: cryptlib.cpp:59
UnknownOID()
Construct an UnknownOID.
Definition: asn.h:75
OID & operator+=(word32 rhs)
Append a value to an OID.
Definition: asn.h:181
virtual void BERDecode(BufferedTransformation &bt)=0
Decode this object from a BufferedTransformation.
ASN.1 encoded object filter.
Definition: asn.h:211
Interface for encoding and decoding ASN1 objects.
Definition: cryptlib.h:2941
DER Set Encoder.
Definition: asn.h:332
OID operator+(const OID &lhs, unsigned long rhs)
Append a value to an OID.
size_t DEREncodeTextString(BufferedTransformation &bt, const std::string &str, byte asnTag)
DER encode text string.
Definition: asn.cpp:147
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:62
void BERDecodeError()
Raises a BERDecodeErr.
Definition: asn.h:68
void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag=INTEGER, T minValue=0, T maxValue=((std::numeric_limits< T >::max)()))
BER Decode unsigned value.
Definition: asn.h:490
Data structure used to store byte strings.
Definition: queue.h:20
size_t DERLengthEncode(BufferedTransformation &bt, lword length)
DER encode a length.
Definition: asn.cpp:17
void Put(const byte *inString, size_t length)
Input a byte buffer for processing.
Definition: asn.cpp:301
Implementation of BufferedTransformation's attachment interface.
void DERReencode(BufferedTransformation &bt, BufferedTransformation &dest)
BER decode and DER re-encode.
Definition: asn.cpp:202
virtual void BEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
Definition: cryptlib.h:2960
DER Sequence Encoder.
Definition: asn.h:312
OID(word32 v)
Construct an OID.
Definition: asn.h:174
DER General Encoder.
Definition: asn.h:283
void Load(BufferedTransformation &bt)
BER decode ASN.1 object.
Definition: asn.h:386
Exception thrown when an unknown object identifier is encountered.
Definition: asn.h:71
Implementation of BufferedTransformation's attachment interface.
Definition: filters.h:36
size_t DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen)
DER encode octet string.
Definition: asn.cpp:104
size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits)
DER decode bit string.
Definition: asn.cpp:182
virtual size_t Get(byte &outByte)
Retrieve a 8-bit byte.
Definition: cryptlib.cpp:515
Crypto++ library namespace.
ASNTag
ASN.1 types.
Definition: asn.h:27
virtual size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const =0
Copy bytes from this object to another BufferedTransformation.
Encodes and decodes subjectPublicKeyInfo.
Definition: asn.h:391
BER General Decoder.
Definition: asn.h:245
virtual void DEREncode(BufferedTransformation &bt) const =0
Encode this object into a BufferedTransformation.
void Save(BufferedTransformation &bt) const
DER encode ASN.1 object.
Definition: asn.h:381
size_t BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte asnTag)
BER decode text string.
Definition: asn.cpp:155
Encode and decode ASN.1 objects with additional information.
Definition: asn.h:373
Object Identifier.
Definition: asn.h:165
bool BERLengthDecode(BufferedTransformation &bt, size_t &length)
BER decode a length.
Definition: asn.cpp:76
size_t DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0)
DER encode bit string.
Definition: asn.cpp:173
Interface for retrieving values given their names.
Definition: cryptlib.h:279
Exception thrown when an ASN.1 BER decoing error is encountered.
Definition: cryptlib.h:2930