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