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