Crypto++ 8.7
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#include <iosfwd>
17
18// Issue 340
19#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
20# pragma GCC diagnostic push
21# pragma GCC diagnostic ignored "-Wconversion"
22# pragma GCC diagnostic ignored "-Wsign-conversion"
23#endif
24
25NAMESPACE_BEGIN(CryptoPP)
26
27/// \brief ASN.1 types
28/// \note These tags are not complete
30{
31 /// \brief ASN.1 Boolean
32 BOOLEAN = 0x01,
33 /// \brief ASN.1 Integer
34 INTEGER = 0x02,
35 /// \brief ASN.1 Bit string
36 BIT_STRING = 0x03,
37 /// \brief ASN.1 Octet string
39 /// \brief ASN.1 Null
40 TAG_NULL = 0x05,
41 /// \brief ASN.1 Object identifier
43 /// \brief ASN.1 Object descriptor
45 /// \brief ASN.1 External reference
46 EXTERNAL = 0x08,
47 /// \brief ASN.1 Real integer
48 REAL = 0x09,
49 /// \brief ASN.1 Enumerated value
50 ENUMERATED = 0x0a,
51 /// \brief ASN.1 UTF-8 string
53 /// \brief ASN.1 Sequence
54 SEQUENCE = 0x10,
55 /// \brief ASN.1 Set
56 SET = 0x11,
57 /// \brief ASN.1 Numeric string
59 /// \brief ASN.1 Printable string
61 /// \brief ASN.1 T61 string
62 T61_STRING = 0x14,
63 /// \brief ASN.1 Videotext string
65 /// \brief ASN.1 IA5 string
66 IA5_STRING = 0x16,
67 /// \brief ASN.1 UTC time
68 UTC_TIME = 0x17,
69 /// \brief ASN.1 Generalized time
71 /// \brief ASN.1 Graphic string
73 /// \brief ASN.1 Visible string
75 /// \brief ASN.1 General string
77 /// \brief ASN.1 Universal string
79 /// \brief ASN.1 BMP string
80 BMP_STRING = 0x1e
81};
82
83/// \brief ASN.1 flags
84/// \note These flags are not complete
86{
87 /// \brief ASN.1 Universal class
88 UNIVERSAL = 0x00,
89 // DATA = 0x01,
90 // HEADER = 0x02,
91 /// \brief ASN.1 Primitive flag
92 PRIMITIVE = 0x00,
93 /// \brief ASN.1 Constructed flag
95 /// \brief ASN.1 Application class
97 /// \brief ASN.1 Context specific class
99 /// \brief ASN.1 Private class
100 PRIVATE = 0xc0
102
103/// \brief Raises a BERDecodeErr
104inline void BERDecodeError() {throw BERDecodeErr();}
105
106/// \brief Exception thrown when an unknown object identifier is encountered
107class CRYPTOPP_DLL UnknownOID : public BERDecodeErr
108{
109public:
110 /// \brief Construct an UnknownOID
111 UnknownOID() : BERDecodeErr("BER decode error: unknown object identifier") {}
112 /// \brief Construct an UnknownOID
113 /// \param err error message to use for the exception
114 UnknownOID(const char *err) : BERDecodeErr(err) {}
115};
116
117/// \brief DER encode a length
118/// \param bt BufferedTransformation object for writing
119/// \param length the size to encode
120/// \return the number of octets used for the encoding
122
123/// \brief BER decode a length
124/// \param bt BufferedTransformation object for reading
125/// \param length the decoded size
126/// \return true if the value was decoded
127/// \throw BERDecodeError if the value fails to decode or is too large for size_t
128/// \details BERLengthDecode() returns false if the encoding is indefinite length.
129CRYPTOPP_DLL bool CRYPTOPP_API BERLengthDecode(BufferedTransformation &bt, size_t &length);
130
131/// \brief DER encode NULL
132/// \param bt BufferedTransformation object for writing
134
135/// \brief BER decode NULL
136/// \param bt BufferedTransformation object for reading
138
139/// \brief DER encode octet string
140/// \param bt BufferedTransformation object for writing
141/// \param str the string to encode
142/// \param strLen the length of the string
143/// \return the number of octets used for the encoding
144CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen);
145
146/// \brief DER encode octet string
147/// \param bt BufferedTransformation object for reading
148/// \param str the string to encode
149/// \return the number of octets used for the encoding
151
152/// \brief BER decode octet string
153/// \param bt BufferedTransformation object for reading
154/// \param str the decoded string
155/// \return the number of octets used for the encoding
157
158/// \brief BER decode octet string
159/// \param bt BufferedTransformation object for reading
160/// \param str the decoded string
161/// \return the number of octets used for the encoding
163
164/// \brief DER encode text string
165/// \param bt BufferedTransformation object for writing
166/// \param str the string to encode
167/// \param strLen the length of the string, in bytes
168/// \param asnTag the ASN.1 identifier
169/// \return the number of octets used for the encoding
170/// \details DEREncodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
171/// \since Crypto++ 8.3
172CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const byte* str, size_t strLen, byte asnTag);
173
174/// \brief DER encode text string
175/// \param bt BufferedTransformation object for writing
176/// \param str the string to encode
177/// \param asnTag the ASN.1 identifier
178/// \return the number of octets used for the encoding
179/// \details DEREncodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
180/// \since Crypto++ 8.3
181CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag);
182
183/// \brief DER encode text string
184/// \param bt BufferedTransformation object for writing
185/// \param str the string to encode
186/// \param asnTag the ASN.1 identifier
187/// \return the number of octets used for the encoding
188/// \details DEREncodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
189/// \since Crypto++ 6.0
190CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const std::string &str, byte asnTag);
191
192/// \brief BER decode text string
193/// \param bt BufferedTransformation object for reading
194/// \param str the string to decode
195/// \param asnTag the ASN.1 identifier
196/// \details BERDecodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
197/// \since Crypto++ 8.3
198CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &bt, SecByteBlock &str, byte asnTag);
199
200/// \brief BER decode text string
201/// \param bt BufferedTransformation object for reading
202/// \param str the string to decode
203/// \param asnTag the ASN.1 identifier
204/// \details BERDecodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
205/// \since Crypto++ 6.0
206CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte asnTag);
207
208/// \brief DER encode date
209/// \param bt BufferedTransformation object for writing
210/// \param str the date to encode
211/// \param asnTag the ASN.1 identifier
212/// \return the number of octets used for the encoding
213/// \details BERDecodeDate() can be used for UTC_TIME and GENERALIZED_TIME
214/// \since Crypto++ 8.3
215CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeDate(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag);
216
217/// \brief BER decode date
218/// \param bt BufferedTransformation object for reading
219/// \param str the date to decode
220/// \param asnTag the ASN.1 identifier
221/// \details BERDecodeDate() can be used for UTC_TIME and GENERALIZED_TIME
222/// \since Crypto++ 8.3
223CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeDate(BufferedTransformation &bt, SecByteBlock &str, byte asnTag);
224
225/// \brief DER encode bit string
226/// \param bt BufferedTransformation object for writing
227/// \param str the string to encode
228/// \param strLen the length of the string
229/// \param unusedBits the number of unused bits
230/// \return the number of octets used for the encoding
231/// \details The caller is responsible for shifting octets if unusedBits is
232/// not 0. For example, to DER encode a web server X.509 key usage, the 101b
233/// bit mask is often used (digitalSignature and keyEncipherment). In this
234/// case <tt>str</tt> is one octet with a value=0xa0 and unusedBits=5. The
235/// value 0xa0 is <tt>101b << 5</tt>.
236CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0);
237
238/// \brief DER decode bit string
239/// \param bt BufferedTransformation object for reading
240/// \param str the decoded string
241/// \param unusedBits the number of unused bits
242/// \details The caller is responsible for shifting octets if unusedBits is
243/// not 0. For example, to DER encode a web server X.509 key usage, the 101b
244/// bit mask is often used (digitalSignature and keyEncipherment). In this
245/// case <tt>str</tt> is one octet with a value=0xa0 and unusedBits=5. The
246/// value 0xa0 is <tt>101b << 5</tt>.
247CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits);
248
249/// \brief BER decode and DER re-encode
250/// \param bt BufferedTransformation object for writing
251/// \param dest BufferedTransformation object
253
254/// \brief BER decode size
255/// \param bt BufferedTransformation object for reading
256/// \return the length of the ASN.1 value, in bytes
257/// \details BERDecodePeekLength() determines the length of a value without
258/// consuming octets in the stream. The stream must use definite length encoding.
259/// If indefinite length encoding is used or an error occurs, then 0 is returned.
260/// \since Crypto++ 8.3
262
263/// \brief Object Identifier
264class CRYPTOPP_DLL OID
265{
266public:
267 virtual ~OID() {}
268
269 /// \brief Construct an OID
270 OID() {}
271
272 /// \brief Construct an OID
273 /// \param v value to initialize the OID
274 OID(word32 v) : m_values(1, v) {}
275
276 /// \brief Construct an OID
277 /// \param bt BufferedTransformation object
279 BERDecode(bt);
280 }
281
282 /// \brief Append a value to an OID
283 /// \param rhs the value to append
284 inline OID & operator+=(word32 rhs) {
285 m_values.push_back(rhs); return *this;
286 }
287
288 /// \brief DER encode this OID
289 /// \param bt BufferedTransformation object
291
292 /// \brief BER decode an OID
293 /// \param bt BufferedTransformation object
295
296 /// \brief BER decode an OID
297 /// \param bt BufferedTransformation object
298 /// \throw BERDecodeErr() if decoded value doesn't match an expected OID
299 /// \details BERDecodeAndCheck() can be used to parse an OID and verify it matches an expected.
300 /// <pre>
301 /// BERSequenceDecoder key(bt);
302 /// ...
303 /// BERSequenceDecoder algorithm(key);
304 /// GetAlgorithmID().BERDecodeAndCheck(algorithm);
305 /// </pre>
307
308 /// \brief Determine if OID is empty
309 /// \return true if OID has 0 elements, false otherwise
310 /// \since Crypto++ 8.0
311 bool Empty() const {
312 return m_values.empty();
313 }
314
315 /// \brief Retrieve OID value array
316 /// \return OID value vector
317 /// \since Crypto++ 8.0
318 const std::vector<word32>& GetValues() const {
319 return m_values;
320 }
321
322 /// \brief Print an OID
323 /// \param out ostream object
324 /// \return ostream reference
325 /// \details Print() writes the OID in a customary format, like
326 /// 1.2.840.113549.1.1.11. The caller is reposnsible to convert the
327 /// OID to a friendly name, like sha256WithRSAEncryption.
328 /// \since Crypto++ 8.3
329 std::ostream& Print(std::ostream& out) const;
330
331protected:
332 friend bool operator==(const OID &lhs, const OID &rhs);
333 friend bool operator!=(const OID &lhs, const OID &rhs);
334 friend bool operator<(const OID &lhs, const OID &rhs);
335 friend bool operator<=(const OID &lhs, const OID &rhs);
336 friend bool operator>=(const OID &lhs, const OID &rhs);
337
338 std::vector<word32> m_values;
339
340private:
341 static void EncodeValue(BufferedTransformation &bt, word32 v);
342 static size_t DecodeValue(BufferedTransformation &bt, word32 &v);
343};
344
345/// \brief ASN.1 encoded object filter
347{
348public:
349 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};
350 enum State {IDENTIFIER, LENGTH, BODY, TAIL, ALL_DONE} m_state;
351
352 virtual ~EncodedObjectFilter() {}
353
354 /// \brief Construct an EncodedObjectFilter
355 /// \param attachment a BufferedTrasformation to attach to this object
356 /// \param nObjects the number of objects
357 /// \param flags bitwise OR of EncodedObjectFilter::Flag
358 EncodedObjectFilter(BufferedTransformation *attachment = NULLPTR, unsigned int nObjects = 1, word32 flags = 0);
359
360 /// \brief Input a byte buffer for processing
361 /// \param inString the byte buffer to process
362 /// \param length the size of the string, in bytes
363 void Put(const byte *inString, size_t length);
364
365 unsigned int GetNumberOfCompletedObjects() const {return m_nCurrentObject;}
366 unsigned long GetPositionOfObject(unsigned int i) const {return m_positions[i];}
367
368private:
369 BufferedTransformation & CurrentTarget();
370
371 ByteQueue m_queue;
372 std::vector<unsigned int> m_positions;
373 lword m_lengthRemaining;
374 word32 m_nObjects, m_nCurrentObject, m_level, m_flags;
375 byte m_id;
376};
377
378/// \brief BER General Decoder
379class CRYPTOPP_DLL BERGeneralDecoder : public Store
380{
381public:
382 /// \brief Default ASN.1 tag
383 enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
384
385 virtual ~BERGeneralDecoder();
386
387 /// \brief Construct an ASN.1 decoder
388 /// \param inQueue input byte queue
389 /// \details BERGeneralDecoder uses DefaultTag
391
392 /// \brief Construct an ASN.1 decoder
393 /// \param inQueue input byte queue
394 /// \param asnTag ASN.1 tag
395 explicit BERGeneralDecoder(BufferedTransformation &inQueue, byte asnTag);
396
397 /// \brief Construct an ASN.1 decoder
398 /// \param inQueue input byte queue
399 /// \param asnTag ASN.1 tag
400 explicit BERGeneralDecoder(BERGeneralDecoder &inQueue, byte asnTag);
401
402 /// \brief Determine length encoding
403 /// \return true if the ASN.1 object is definite length encoded, false otherwise
404 bool IsDefiniteLength() const {
405 return m_definiteLength;
406 }
407
408 /// \brief Determine remaining length
409 /// \return number of octets that remain to be consumed
410 /// \details RemainingLength() is only valid if IsDefiniteLength()
411 /// returns true.
413 CRYPTOPP_ASSERT(m_definiteLength);
414 return IsDefiniteLength() ? m_length : 0;
415 }
416
417 /// \brief Determine end of stream
418 /// \return true if all octets have been consumed, false otherwise
419 bool EndReached() const;
420
421 /// \brief Determine next octet
422 /// \return next octet in the stream
423 /// \details PeekByte does not consume the octet.
424 /// \throw BERDecodeError if there are no octets remaining
425 byte PeekByte() const;
426
427 /// \brief Determine next octet
428 /// \details CheckByte reads the next byte in the stream and verifies
429 /// the octet matches b.
430 /// \throw BERDecodeError if the next octet is not b
431 void CheckByte(byte b);
432
433 /// \brief Transfer bytes to another BufferedTransformation
434 /// \param target the destination BufferedTransformation
435 /// \param transferBytes the number of bytes to transfer
436 /// \param channel the channel on which the transfer should occur
437 /// \param blocking specifies whether the object should block when
438 /// processing input
439 /// \return the number of bytes that remain in the transfer block
440 /// (i.e., bytes not transferred)
441 /// \details TransferTo2() removes bytes and moves
442 /// them to the destination. Transfer begins at the index position
443 /// in the current stream, and not from an absolute position in the
444 /// stream.
445 /// \details transferBytes is an \a IN and \a OUT parameter. When
446 /// the call is made, transferBytes is the requested size of the
447 /// transfer. When the call returns, transferBytes is the number
448 /// of bytes that were transferred.
449 size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
450
451 /// \brief Copy bytes to another BufferedTransformation
452 /// \param target the destination BufferedTransformation
453 /// \param begin the 0-based index of the first byte to copy in
454 /// the stream
455 /// \param end the 0-based index of the last byte to copy in
456 /// the stream
457 /// \param channel the channel on which the transfer should occur
458 /// \param blocking specifies whether the object should block when
459 /// processing input
460 /// \return the number of bytes that remain in the copy block
461 /// (i.e., bytes not copied)
462 /// \details CopyRangeTo2 copies bytes to the
463 /// destination. The bytes are not removed from this object. Copying
464 /// begins at the index position in the current stream, and not from
465 /// an absolute position in the stream.
466 /// \details begin is an \a IN and \a OUT parameter. When the call is
467 /// made, begin is the starting position of the copy. When the call
468 /// returns, begin is the position of the first byte that was \a not
469 /// copied (which may be different than end). begin can be used for
470 /// subsequent calls to CopyRangeTo2().
471 size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
472
473 /// \brief Signals the end of messages to the object
474 /// \details Call this to denote end of sequence
476
477protected:
478 BufferedTransformation &m_inQueue;
479 lword m_length;
480 bool m_finished, m_definiteLength;
481
482private:
483 void Init(byte asnTag);
484 void StoreInitialize(const NameValuePairs &parameters)
485 {CRYPTOPP_UNUSED(parameters); CRYPTOPP_ASSERT(false);}
486 lword ReduceLength(lword delta);
487};
488
489/// \brief DER General Encoder
490class CRYPTOPP_DLL DERGeneralEncoder : public ByteQueue
491{
492public:
493 /// \brief Default ASN.1 tag
494 enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
495
496 virtual ~DERGeneralEncoder();
497
498 /// \brief Construct an ASN.1 encoder
499 /// \param outQueue output byte queue
500 /// \details DERGeneralEncoder uses DefaultTag
502
503 /// \brief Construct an ASN.1 encoder
504 /// \param outQueue output byte queue
505 /// \param asnTag ASN.1 tag
506 explicit DERGeneralEncoder(BufferedTransformation &outQueue, byte asnTag);
507
508 /// \brief Construct an ASN.1 encoder
509 /// \param outQueue output byte queue
510 /// \param asnTag ASN.1 tag
511 explicit DERGeneralEncoder(DERGeneralEncoder &outQueue, byte asnTag);
512
513 /// \brief Signals the end of messages to the object
514 /// \details Call this to denote end of sequence
516
517private:
518 BufferedTransformation &m_outQueue;
519 byte m_asnTag;
520 bool m_finished;
521};
522
523/// \brief BER Sequence Decoder
524class CRYPTOPP_DLL BERSequenceDecoder : public BERGeneralDecoder
525{
526public:
527 /// \brief Default ASN.1 tag
528 enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
529
530 /// \brief Construct an ASN.1 decoder
531 /// \param inQueue input byte queue
532 /// \details BERSequenceDecoder uses DefaultTag
534 : BERGeneralDecoder(inQueue, DefaultTag) {}
535
536 /// \brief Construct an ASN.1 decoder
537 /// \param inQueue input byte queue
538 /// \param asnTag ASN.1 tag
539 explicit BERSequenceDecoder(BufferedTransformation &inQueue, byte asnTag)
540 : BERGeneralDecoder(inQueue, asnTag) {}
541
542 /// \brief Construct an ASN.1 decoder
543 /// \param inQueue input byte queue
544 /// \details BERSequenceDecoder uses DefaultTag
546 : BERGeneralDecoder(inQueue, DefaultTag) {}
547
548 /// \brief Construct an ASN.1 decoder
549 /// \param inQueue input byte queue
550 /// \param asnTag ASN.1 tag
551 explicit BERSequenceDecoder(BERSequenceDecoder &inQueue, byte asnTag)
552 : BERGeneralDecoder(inQueue, asnTag) {}
553};
554
555/// \brief DER Sequence Encoder
556class CRYPTOPP_DLL DERSequenceEncoder : public DERGeneralEncoder
557{
558public:
559 /// \brief Default ASN.1 tag
560 enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
561
562 /// \brief Construct an ASN.1 encoder
563 /// \param outQueue output byte queue
564 /// \details DERSequenceEncoder uses DefaultTag
566 : DERGeneralEncoder(outQueue, DefaultTag) {}
567
568 /// \brief Construct an ASN.1 encoder
569 /// \param outQueue output byte queue
570 /// \param asnTag ASN.1 tag
571 explicit DERSequenceEncoder(BufferedTransformation &outQueue, byte asnTag)
572 : DERGeneralEncoder(outQueue, asnTag) {}
573
574 /// \brief Construct an ASN.1 encoder
575 /// \param outQueue output byte queue
576 /// \details DERSequenceEncoder uses DefaultTag
578 : DERGeneralEncoder(outQueue, DefaultTag) {}
579
580 /// \brief Construct an ASN.1 encoder
581 /// \param outQueue output byte queue
582 /// \param asnTag ASN.1 tag
583 explicit DERSequenceEncoder(DERSequenceEncoder &outQueue, byte asnTag)
584 : DERGeneralEncoder(outQueue, asnTag) {}
585};
586
587/// \brief BER Set Decoder
588class CRYPTOPP_DLL BERSetDecoder : public BERGeneralDecoder
589{
590public:
591 /// \brief Default ASN.1 tag
592 enum {DefaultTag = SET | EnumToInt(CONSTRUCTED)};
593
594 /// \brief Construct an ASN.1 decoder
595 /// \param inQueue input byte queue
596 /// \details BERSetDecoder uses DefaultTag
598 : BERGeneralDecoder(inQueue, DefaultTag) {}
599
600 /// \brief Construct an ASN.1 decoder
601 /// \param inQueue input byte queue
602 /// \param asnTag ASN.1 tag
603 explicit BERSetDecoder(BufferedTransformation &inQueue, byte asnTag)
604 : BERGeneralDecoder(inQueue, asnTag) {}
605
606 /// \brief Construct an ASN.1 decoder
607 /// \param inQueue input byte queue
608 /// \details BERSetDecoder uses DefaultTag
609 explicit BERSetDecoder(BERSetDecoder &inQueue)
610 : BERGeneralDecoder(inQueue, DefaultTag) {}
611
612 /// \brief Construct an ASN.1 decoder
613 /// \param inQueue input byte queue
614 /// \param asnTag ASN.1 tag
615 explicit BERSetDecoder(BERSetDecoder &inQueue, byte asnTag)
616 : BERGeneralDecoder(inQueue, asnTag) {}
617};
618
619/// \brief DER Set Encoder
620class CRYPTOPP_DLL DERSetEncoder : public DERGeneralEncoder
621{
622public:
623 /// \brief Default ASN.1 tag
624 enum {DefaultTag = SET | EnumToInt(CONSTRUCTED)};
625
626 /// \brief Construct an ASN.1 encoder
627 /// \param outQueue output byte queue
628 /// \details DERSetEncoder uses DefaultTag
630 : DERGeneralEncoder(outQueue, DefaultTag) {}
631
632 /// \brief Construct an ASN.1 encoder
633 /// \param outQueue output byte queue
634 /// \param asnTag ASN.1 tag
635 explicit DERSetEncoder(BufferedTransformation &outQueue, byte asnTag)
636 : DERGeneralEncoder(outQueue, asnTag) {}
637
638 /// \brief Construct an ASN.1 encoder
639 /// \param outQueue output byte queue
640 /// \details DERSetEncoder uses DefaultTag
641 explicit DERSetEncoder(DERSetEncoder &outQueue)
642 : DERGeneralEncoder(outQueue, DefaultTag) {}
643
644 /// \brief Construct an ASN.1 encoder
645 /// \param outQueue output byte queue
646 /// \param asnTag ASN.1 tag
647 explicit DERSetEncoder(DERSetEncoder &outQueue, byte asnTag)
648 : DERGeneralEncoder(outQueue, asnTag) {}
649};
650
651/// \brief Optional data encoder and decoder
652/// \tparam T class or type
653template <class T>
654class ASNOptional : public member_ptr<T>
655{
656public:
657 /// \brief BER decode optional data
658 /// \param seqDecoder sequence with the optional ASN.1 data
659 /// \param tag ASN.1 tag to match as optional data
660 /// \param mask the mask to apply when matching the tag
661 /// \sa ASNTag and ASNIdFlag
662 void BERDecode(BERSequenceDecoder &seqDecoder, byte tag, byte mask = ~CONSTRUCTED)
663 {
664 byte b;
665 if (seqDecoder.Peek(b) && (b & mask) == tag)
666 reset(new T(seqDecoder));
667 }
668
669 /// \brief DER encode optional data
670 /// \param out BufferedTransformation object
672 {
673 if (this->get() != NULLPTR)
674 this->get()->DEREncode(out);
675 }
676};
677
678/// \brief Encode and decode ASN.1 objects with additional information
679/// \tparam BASE base class or type
680/// \details Encodes and decodes public keys, private keys and group
681/// parameters with OID identifying the algorithm or scheme.
682template <class BASE>
683class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ASN1CryptoMaterial : public ASN1Object, public BASE
684{
685public:
686 /// \brief DER encode ASN.1 object
687 /// \param bt BufferedTransformation object
688 /// \details Save() will write the OID associated with algorithm or scheme.
689 /// In the case of public and private keys, this function writes the
690 /// subjectPublicKeyInfo and privateKeyInfo parts.
692 {BEREncode(bt);}
693
694 /// \brief BER decode ASN.1 object
695 /// \param bt BufferedTransformation object
697 {BERDecode(bt);}
698};
699
700/// \brief Encodes and decodes subjectPublicKeyInfo
701class CRYPTOPP_DLL X509PublicKey : public ASN1CryptoMaterial<PublicKey>
702{
703public:
704 virtual ~X509PublicKey() {}
705
708
709 /// \brief Retrieves the OID of the algorithm
710 /// \return OID of the algorithm
711 virtual OID GetAlgorithmID() const =0;
712
713 /// \brief Decode algorithm parameters
714 /// \param bt BufferedTransformation object
715 /// \sa BERDecodePublicKey, <A HREF="http://www.ietf.org/rfc/rfc2459.txt">RFC
716 /// 2459, section 7.3.1</A>
718 {BERDecodeNull(bt); return false;}
719
720 /// \brief Encode algorithm parameters
721 /// \param bt BufferedTransformation object
722 /// \sa DEREncodePublicKey, <A HREF="http://www.ietf.org/rfc/rfc2459.txt">RFC
723 /// 2459, section 7.3.1</A>
725 {DEREncodeNull(bt); return false;}
726
727 /// \brief Decode subjectPublicKey part of subjectPublicKeyInfo
728 /// \param bt BufferedTransformation object
729 /// \param parametersPresent flag indicating if algorithm parameters are present
730 /// \param size number of octets to read for the parameters, in bytes
731 /// \details BERDecodePublicKey() the decodes subjectPublicKey part of
732 /// subjectPublicKeyInfo, without the BIT STRING header.
733 /// \details When <tt>parametersPresent = true</tt> then BERDecodePublicKey() calls
734 /// BERDecodeAlgorithmParameters() to parse algorithm parameters.
735 /// \sa BERDecodeAlgorithmParameters
736 virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0;
737
738 /// \brief Encode subjectPublicKey part of subjectPublicKeyInfo
739 /// \param bt BufferedTransformation object
740 /// \details DEREncodePublicKey() encodes the subjectPublicKey part of
741 /// subjectPublicKeyInfo, without the BIT STRING header.
742 /// \sa DEREncodeAlgorithmParameters
743 virtual void DEREncodePublicKey(BufferedTransformation &bt) const =0;
744};
745
746/// \brief Encodes and Decodes privateKeyInfo
747class CRYPTOPP_DLL PKCS8PrivateKey : public ASN1CryptoMaterial<PrivateKey>
748{
749public:
750 virtual ~PKCS8PrivateKey() {}
751
754
755 /// \brief Retrieves the OID of the algorithm
756 /// \return OID of the algorithm
757 virtual OID GetAlgorithmID() const =0;
758
759 /// \brief Decode optional parameters
760 /// \param bt BufferedTransformation object
761 /// \sa BERDecodePrivateKey, <A HREF="http://www.ietf.org/rfc/rfc2459.txt">RFC
762 /// 2459, section 7.3.1</A>
764 {BERDecodeNull(bt); return false;}
765
766 /// \brief Encode optional parameters
767 /// \param bt BufferedTransformation object
768 /// \sa DEREncodePrivateKey, <A HREF="http://www.ietf.org/rfc/rfc2459.txt">RFC
769 /// 2459, section 7.3.1</A>
771 {DEREncodeNull(bt); return false;}
772
773 /// \brief Decode privateKey part of privateKeyInfo
774 /// \param bt BufferedTransformation object
775 /// \param parametersPresent flag indicating if algorithm parameters are present
776 /// \param size number of octets to read for the parameters, in bytes
777 /// \details BERDecodePrivateKey() the decodes privateKey part of privateKeyInfo,
778 /// without the OCTET STRING header.
779 /// \details When <tt>parametersPresent = true</tt> then BERDecodePrivateKey() calls
780 /// BERDecodeAlgorithmParameters() to parse algorithm parameters.
781 /// \sa BERDecodeAlgorithmParameters
782 virtual void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0;
783
784 /// \brief Encode privateKey part of privateKeyInfo
785 /// \param bt BufferedTransformation object
786 /// \details DEREncodePrivateKey() encodes the privateKey part of privateKeyInfo,
787 /// without the OCTET STRING header.
788 /// \sa DEREncodeAlgorithmParameters
789 virtual void DEREncodePrivateKey(BufferedTransformation &bt) const =0;
790
791 /// \brief Decode optional attributes
792 /// \param bt BufferedTransformation object
793 /// \details BERDecodeOptionalAttributes() decodes optional attributes including
794 /// context-specific tag.
795 /// \sa BERDecodeAlgorithmParameters, DEREncodeOptionalAttributes
796 /// \note default implementation stores attributes to be output using
797 /// DEREncodeOptionalAttributes
799
800 /// \brief Encode optional attributes
801 /// \param bt BufferedTransformation object
802 /// \details DEREncodeOptionalAttributes() encodes optional attributes including
803 /// context-specific tag.
804 /// \sa BERDecodeAlgorithmParameters
806
807protected:
808 ByteQueue m_optionalAttributes;
809};
810
811// ********************************************************
812
813/// \brief DER Encode unsigned value
814/// \tparam T class or type
815/// \param out BufferedTransformation object
816/// \param w unsigned value to encode
817/// \param asnTag the ASN.1 identifier
818/// \details DEREncodeUnsigned() can be used with INTEGER, BOOLEAN, and ENUM
819template <class T>
820size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag = INTEGER)
821{
822 byte buf[sizeof(w)+1];
823 unsigned int bc;
824 if (asnTag == BOOLEAN)
825 {
826 buf[sizeof(w)] = w ? 0xff : 0;
827 bc = 1;
828 }
829 else
830 {
831 buf[0] = 0;
832 for (unsigned int i=0; i<sizeof(w); i++)
833 buf[i+1] = byte(w >> (sizeof(w)-1-i)*8);
834 bc = sizeof(w);
835 while (bc > 1 && buf[sizeof(w)+1-bc] == 0)
836 --bc;
837 if (buf[sizeof(w)+1-bc] & 0x80)
838 ++bc;
839 }
840 out.Put(asnTag);
841 size_t lengthBytes = DERLengthEncode(out, bc);
842 out.Put(buf+sizeof(w)+1-bc, bc);
843 return 1+lengthBytes+bc;
844}
845
846/// \brief BER Decode unsigned value
847/// \tparam T fundamental C++ type
848/// \param in BufferedTransformation object
849/// \param w the decoded value
850/// \param asnTag the ASN.1 identifier
851/// \param minValue the minimum expected value
852/// \param maxValue the maximum expected value
853/// \throw BERDecodeErr() if the value cannot be parsed or the decoded value is not within range.
854/// \details DEREncodeUnsigned() can be used with INTEGER, BOOLEAN, and ENUM
855template <class T>
857 T minValue = 0, T maxValue = T(0xffffffff))
858{
859 byte b;
860 if (!in.Get(b) || b != asnTag)
862
863 size_t bc;
864 bool definite = BERLengthDecode(in, bc);
865 if (!definite)
867 if (bc > in.MaxRetrievable()) // Issue 346
869 if (asnTag == BOOLEAN && bc != 1) // X.690, 8.2.1
871 if ((asnTag == INTEGER || asnTag == ENUMERATED) && bc == 0) // X.690, 8.3.1 and 8.4
873
874 SecByteBlock buf(bc);
875
876 if (bc != in.Get(buf, bc))
878
879 // This consumes leading 0 octets. According to X.690, 8.3.2, it could be non-conforming behavior.
880 // X.690, 8.3.2 says "the bits of the first octet and bit 8 of the second octet ... (a) shall
881 // not all be ones and (b) shall not all be zeros ... These rules ensure that an integer value
882 // is always encoded in the smallest possible number of octet".
883 // We invented AER (Alternate Encoding Rules), which is more relaxed than BER, CER, and DER.
884 const byte *ptr = buf;
885 while (bc > sizeof(w) && *ptr == 0)
886 {
887 bc--;
888 ptr++;
889 }
890 if (bc > sizeof(w))
892
893 w = 0;
894 for (unsigned int i=0; i<bc; i++)
895 w = (w << 8) | ptr[i];
896
897 if (w < minValue || w > maxValue)
899}
900
901#ifdef CRYPTOPP_DOXYGEN_PROCESSING
902/// \brief Compare two OIDs for equality
903/// \param lhs the first OID
904/// \param rhs the second OID
905/// \return true if the OIDs are equal, false otherwise
906inline bool operator==(const OID &lhs, const OID &rhs);
907/// \brief Compare two OIDs for inequality
908/// \param lhs the first OID
909/// \param rhs the second OID
910/// \return true if the OIDs are not equal, false otherwise
911inline bool operator!=(const OID &lhs, const OID &rhs);
912/// \brief Compare two OIDs for ordering
913/// \param lhs the first OID
914/// \param rhs the second OID
915/// \return true if the first OID is less than the second OID, false otherwise
916/// \details operator<() calls std::lexicographical_compare() on each element in the array of values.
917inline bool operator<(const OID &lhs, const OID &rhs);
918/// \brief Compare two OIDs for ordering
919/// \param lhs the first OID
920/// \param rhs the second OID
921/// \return true if the first OID is less than or equal to the second OID, false otherwise
922/// \details operator<=() is implemented in terms of operator==() and operator<().
923/// \since Crypto++ 8.3
924inline bool operator<=(const OID &lhs, const OID &rhs);
925/// \brief Compare two OIDs for ordering
926/// \param lhs the first OID
927/// \param rhs the second OID
928/// \return true if the first OID is greater than or equal to the second OID, false otherwise
929/// \details operator>=() is implemented in terms of operator<().
930/// \since Crypto++ 8.3
931inline bool operator>=(const OID &lhs, const OID &rhs);
932/// \brief Append a value to an OID
933/// \param lhs the OID
934/// \param rhs the value to append
935inline OID operator+(const OID &lhs, unsigned long rhs);
936/// \brief Print a OID value
937/// \param out the output stream
938/// \param oid the OID
939inline std::ostream& operator<<(std::ostream& out, const OID &oid)
940 { return oid.Print(out); }
941#else
942inline bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
943 {return lhs.m_values == rhs.m_values;}
944inline bool operator!=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
945 {return lhs.m_values != rhs.m_values;}
946inline bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
947 {return std::lexicographical_compare(lhs.m_values.begin(), lhs.m_values.end(), rhs.m_values.begin(), rhs.m_values.end());}
948inline bool operator<=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
949 {return lhs<rhs || lhs==rhs;}
950inline bool operator>=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
951 {return ! (lhs<rhs);}
952inline ::CryptoPP::OID operator+(const ::CryptoPP::OID &lhs, unsigned long rhs)
953 {return ::CryptoPP::OID(lhs)+=rhs;}
954inline std::ostream& operator<<(std::ostream& out, const OID &oid)
955 { return oid.Print(out); }
956#endif
957
958NAMESPACE_END
959
960// Issue 340
961#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
962# pragma GCC diagnostic pop
963#endif
964
965#endif
CRYPTOPP_DLL size_t BERDecodeTextString(BufferedTransformation &bt, SecByteBlock &str, byte asnTag)
BER decode text string.
std::ostream & operator<<(std::ostream &out, const OID &oid)
Print a OID value.
Definition: asn.h:939
CRYPTOPP_DLL void DEREncodeNull(BufferedTransformation &bt)
DER encode NULL.
void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag=INTEGER, T minValue=0, T maxValue=T(0xffffffff))
BER Decode unsigned value.
Definition: asn.h:856
bool operator<=(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
CRYPTOPP_DLL bool BERLengthDecode(BufferedTransformation &bt, size_t &length)
BER decode a length.
CRYPTOPP_DLL size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits)
DER decode bit string.
CRYPTOPP_DLL size_t DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0)
DER encode bit string.
OID operator+(const OID &lhs, unsigned long rhs)
Append a value to an OID.
bool operator>=(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
CRYPTOPP_DLL size_t DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen)
DER encode octet string.
CRYPTOPP_DLL void BERDecodeNull(BufferedTransformation &bt)
BER decode NULL.
CRYPTOPP_DLL size_t BERDecodeDate(BufferedTransformation &bt, SecByteBlock &str, byte asnTag)
BER decode date.
size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag=INTEGER)
DER Encode unsigned value.
Definition: asn.h:820
ASNIdFlag
ASN.1 flags.
Definition: asn.h:86
@ PRIVATE
ASN.1 Private class.
Definition: asn.h:100
@ CONSTRUCTED
ASN.1 Constructed flag.
Definition: asn.h:94
@ APPLICATION
ASN.1 Application class.
Definition: asn.h:96
@ CONTEXT_SPECIFIC
ASN.1 Context specific class.
Definition: asn.h:98
@ UNIVERSAL
ASN.1 Universal class.
Definition: asn.h:88
@ PRIMITIVE
ASN.1 Primitive flag.
Definition: asn.h:92
CRYPTOPP_DLL size_t BERDecodePeekLength(const BufferedTransformation &bt)
BER decode size.
CRYPTOPP_DLL void DERReencode(BufferedTransformation &bt, BufferedTransformation &dest)
BER decode and DER re-encode.
CRYPTOPP_DLL size_t DEREncodeTextString(BufferedTransformation &bt, const byte *str, size_t strLen, byte asnTag)
DER encode text string.
bool operator<(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
CRYPTOPP_DLL size_t DEREncodeDate(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag)
DER encode date.
CRYPTOPP_DLL size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
BER decode octet string.
bool operator!=(const OID &lhs, const OID &rhs)
Compare two OIDs for inequality.
ASNTag
ASN.1 types.
Definition: asn.h:30
@ REAL
ASN.1 Real integer.
Definition: asn.h:48
@ UNIVERSAL_STRING
ASN.1 Universal string.
Definition: asn.h:78
@ NUMERIC_STRING
ASN.1 Numeric string.
Definition: asn.h:58
@ OCTET_STRING
ASN.1 Octet string.
Definition: asn.h:38
@ GRAPHIC_STRING
ASN.1 Graphic string.
Definition: asn.h:72
@ PRINTABLE_STRING
ASN.1 Printable string.
Definition: asn.h:60
@ INTEGER
ASN.1 Integer.
Definition: asn.h:34
@ ENUMERATED
ASN.1 Enumerated value.
Definition: asn.h:50
@ EXTERNAL
ASN.1 External reference.
Definition: asn.h:46
@ UTC_TIME
ASN.1 UTC time.
Definition: asn.h:68
@ OBJECT_IDENTIFIER
ASN.1 Object identifier.
Definition: asn.h:42
@ IA5_STRING
ASN.1 IA5 string.
Definition: asn.h:66
@ TAG_NULL
ASN.1 Null.
Definition: asn.h:40
@ BMP_STRING
ASN.1 BMP string.
Definition: asn.h:80
@ BOOLEAN
ASN.1 Boolean.
Definition: asn.h:32
@ VISIBLE_STRING
ASN.1 Visible string.
Definition: asn.h:74
@ BIT_STRING
ASN.1 Bit string.
Definition: asn.h:36
@ GENERAL_STRING
ASN.1 General string.
Definition: asn.h:76
@ SET
ASN.1 Set.
Definition: asn.h:56
@ SEQUENCE
ASN.1 Sequence.
Definition: asn.h:54
@ GENERALIZED_TIME
ASN.1 Generalized time.
Definition: asn.h:70
@ VIDEOTEXT_STRING
ASN.1 Videotext string.
Definition: asn.h:64
@ OBJECT_DESCRIPTOR
ASN.1 Object descriptor.
Definition: asn.h:44
@ UTF8_STRING
ASN.1 UTF-8 string.
Definition: asn.h:52
@ T61_STRING
ASN.1 T61 string.
Definition: asn.h:62
CRYPTOPP_DLL size_t DERLengthEncode(BufferedTransformation &bt, lword length)
DER encode a length.
void BERDecodeError()
Raises a BERDecodeErr.
Definition: asn.h:104
Encode and decode ASN.1 objects with additional information.
Definition: asn.h:684
void Load(BufferedTransformation &bt)
BER decode ASN.1 object.
Definition: asn.h:696
void Save(BufferedTransformation &bt) const
DER encode ASN.1 object.
Definition: asn.h:691
Interface for encoding and decoding ASN1 objects.
Definition: cryptlib.h:3284
Optional data encoder and decoder.
Definition: asn.h:655
void DEREncode(BufferedTransformation &out)
DER encode optional data.
Definition: asn.h:671
void BERDecode(BERSequenceDecoder &seqDecoder, byte tag, byte mask=~CONSTRUCTED)
BER decode optional data.
Definition: asn.h:662
Exception thrown when an ASN.1 BER decoing error is encountered.
Definition: cryptlib.h:3273
BER General Decoder.
Definition: asn.h:380
bool EndReached() const
Determine end of stream.
lword RemainingLength() const
Determine remaining length.
Definition: asn.h:412
bool IsDefiniteLength() const
Determine length encoding.
Definition: asn.h:404
BERGeneralDecoder(BufferedTransformation &inQueue)
Construct an ASN.1 decoder.
BERGeneralDecoder(BufferedTransformation &inQueue, byte asnTag)
Construct an ASN.1 decoder.
void MessageEnd()
Signals the end of messages to the object.
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes to another BufferedTransformation.
size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
Copy bytes to another BufferedTransformation.
byte PeekByte() const
Determine next octet.
BERGeneralDecoder(BERGeneralDecoder &inQueue, byte asnTag)
Construct an ASN.1 decoder.
void CheckByte(byte b)
Determine next octet.
BER Sequence Decoder.
Definition: asn.h:525
BERSequenceDecoder(BERSequenceDecoder &inQueue)
Construct an ASN.1 decoder.
Definition: asn.h:545
BERSequenceDecoder(BERSequenceDecoder &inQueue, byte asnTag)
Construct an ASN.1 decoder.
Definition: asn.h:551
BERSequenceDecoder(BufferedTransformation &inQueue)
Construct an ASN.1 decoder.
Definition: asn.h:533
BERSequenceDecoder(BufferedTransformation &inQueue, byte asnTag)
Construct an ASN.1 decoder.
Definition: asn.h:539
BER Set Decoder.
Definition: asn.h:589
BERSetDecoder(BufferedTransformation &inQueue)
Construct an ASN.1 decoder.
Definition: asn.h:597
BERSetDecoder(BufferedTransformation &inQueue, byte asnTag)
Construct an ASN.1 decoder.
Definition: asn.h:603
BERSetDecoder(BERSetDecoder &inQueue, byte asnTag)
Construct an ASN.1 decoder.
Definition: asn.h:615
BERSetDecoder(BERSetDecoder &inQueue)
Construct an ASN.1 decoder.
Definition: asn.h:609
Interface for buffered transformations.
Definition: cryptlib.h:1652
virtual size_t Get(byte &outByte)
Retrieve a 8-bit byte.
virtual size_t Peek(byte &outByte) const
Peek a 8-bit byte.
size_t Put(byte inByte, bool blocking=true)
Input a byte for processing.
Definition: cryptlib.h:1673
virtual lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Data structure used to store byte strings.
Definition: queue.h:23
DER General Encoder.
Definition: asn.h:491
DERGeneralEncoder(DERGeneralEncoder &outQueue, byte asnTag)
Construct an ASN.1 encoder.
DERGeneralEncoder(BufferedTransformation &outQueue)
Construct an ASN.1 encoder.
DERGeneralEncoder(BufferedTransformation &outQueue, byte asnTag)
Construct an ASN.1 encoder.
void MessageEnd()
Signals the end of messages to the object.
DER Sequence Encoder.
Definition: asn.h:557
DERSequenceEncoder(DERSequenceEncoder &outQueue, byte asnTag)
Construct an ASN.1 encoder.
Definition: asn.h:583
DERSequenceEncoder(BufferedTransformation &outQueue, byte asnTag)
Construct an ASN.1 encoder.
Definition: asn.h:571
DERSequenceEncoder(DERSequenceEncoder &outQueue)
Construct an ASN.1 encoder.
Definition: asn.h:577
DERSequenceEncoder(BufferedTransformation &outQueue)
Construct an ASN.1 encoder.
Definition: asn.h:565
DER Set Encoder.
Definition: asn.h:621
DERSetEncoder(DERSetEncoder &outQueue)
Construct an ASN.1 encoder.
Definition: asn.h:641
DERSetEncoder(BufferedTransformation &outQueue)
Construct an ASN.1 encoder.
Definition: asn.h:629
DERSetEncoder(BufferedTransformation &outQueue, byte asnTag)
Construct an ASN.1 encoder.
Definition: asn.h:635
DERSetEncoder(DERSetEncoder &outQueue, byte asnTag)
Construct an ASN.1 encoder.
Definition: asn.h:647
ASN.1 encoded object filter.
Definition: asn.h:347
EncodedObjectFilter(BufferedTransformation *attachment=NULL, unsigned int nObjects=1, word32 flags=0)
Construct an EncodedObjectFilter.
void Put(const byte *inString, size_t length)
Input a byte buffer for processing.
Implementation of BufferedTransformation's attachment interface.
Definition: filters.h:36
Interface for retrieving values given their names.
Definition: cryptlib.h:322
Object Identifier.
Definition: asn.h:265
void BERDecodeAndCheck(BufferedTransformation &bt) const
BER decode an OID.
friend bool operator<=(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
void DEREncode(BufferedTransformation &bt) const
DER encode this OID.
friend bool operator>=(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
OID()
Construct an OID.
Definition: asn.h:270
bool Empty() const
Determine if OID is empty.
Definition: asn.h:311
OID(word32 v)
Construct an OID.
Definition: asn.h:274
const std::vector< word32 > & GetValues() const
Retrieve OID value array.
Definition: asn.h:318
OID(BufferedTransformation &bt)
Construct an OID.
Definition: asn.h:278
std::ostream & Print(std::ostream &out) const
Print an OID.
friend bool operator<(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
OID & operator+=(word32 rhs)
Append a value to an OID.
Definition: asn.h:284
friend bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
friend bool operator!=(const OID &lhs, const OID &rhs)
Compare two OIDs for inequality.
void BERDecode(BufferedTransformation &bt)
BER decode an OID.
Encodes and Decodes privateKeyInfo.
Definition: asn.h:748
virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
Decode optional parameters.
Definition: asn.h:763
virtual void BERDecodeOptionalAttributes(BufferedTransformation &bt)
Decode optional attributes.
virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
Encode optional parameters.
Definition: asn.h:770
virtual void DEREncodePrivateKey(BufferedTransformation &bt) const =0
Encode privateKey part of privateKeyInfo.
void DEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
virtual OID GetAlgorithmID() const =0
Retrieves the OID of the algorithm.
void BERDecode(BufferedTransformation &bt)
Decode this object from a BufferedTransformation.
virtual void DEREncodeOptionalAttributes(BufferedTransformation &bt) const
Encode optional attributes.
virtual void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size)=0
Decode privateKey part of privateKeyInfo.
SecBlock<byte> typedef.
Definition: secblock.h:1226
Acts as a Source for pre-existing, static data.
Definition: simple.h:448
Exception thrown when an unknown object identifier is encountered.
Definition: asn.h:108
UnknownOID()
Construct an UnknownOID.
Definition: asn.h:111
UnknownOID(const char *err)
Construct an UnknownOID.
Definition: asn.h:114
Encodes and decodes subjectPublicKeyInfo.
Definition: asn.h:702
virtual OID GetAlgorithmID() const =0
Retrieves the OID of the algorithm.
void DEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size)=0
Decode subjectPublicKey part of subjectPublicKeyInfo.
void BERDecode(BufferedTransformation &bt)
Decode this object from a BufferedTransformation.
virtual void DEREncodePublicKey(BufferedTransformation &bt) const =0
Encode subjectPublicKey part of subjectPublicKeyInfo.
virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
Encode algorithm parameters.
Definition: asn.h:724
virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
Decode algorithm parameters.
Definition: asn.h:717
Pointer that overloads operator ->
Definition: smartptr.h:38
#define CRYPTOPP_API
Win32 calling convention.
Definition: config_dll.h:119
const lword LWORD_MAX
Large word type max value.
Definition: config_int.h:164
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:62
word64 lword
Large word type.
Definition: config_int.h:158
Abstract base classes that provide a uniform interface to this library.
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Definition: cryptlib.h:511
Implementation of BufferedTransformation's attachment interface.
Utility functions for the Crypto++ library.
#define EnumToInt(v)
Integer value.
Definition: misc.h:502
Crypto++ library namespace.
Classes for an unlimited queue to store bytes.
Classes for automatic resource management.
Common C++ header files.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:68