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