Security Scol plugin
asn.h
Go to the documentation of this file.
1// asn.h - originally written and placed in the public domain by Wei Dai
2
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
82
86{
88 UNIVERSAL = 0x00,
89 // DATA = 0x01,
90 // HEADER = 0x02,
92 PRIMITIVE = 0x00,
100 PRIVATE = 0xc0
102
104inline void BERDecodeError() {throw BERDecodeErr();}
105
107class CRYPTOPP_DLL UnknownOID : public BERDecodeErr
108{
109public:
111 UnknownOID() : BERDecodeErr("BER decode error: unknown object identifier") {}
114 UnknownOID(const char *err) : BERDecodeErr(err) {}
115};
116
121CRYPTOPP_DLL size_t CRYPTOPP_API DERLengthEncode(BufferedTransformation &bt, lword length);
122
129CRYPTOPP_DLL bool CRYPTOPP_API BERLengthDecode(BufferedTransformation &bt, size_t &length);
130
133CRYPTOPP_DLL void CRYPTOPP_API DEREncodeNull(BufferedTransformation &bt);
134
137CRYPTOPP_DLL void CRYPTOPP_API BERDecodeNull(BufferedTransformation &bt);
138
144CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen);
145
150CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &bt, const SecByteBlock &str);
151
156CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str);
157
162CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &bt, BufferedTransformation &str);
163
172CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const byte* str, size_t strLen, byte asnTag);
173
181CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag);
182
190CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const std::string &str, byte asnTag);
191
198CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &bt, SecByteBlock &str, byte asnTag);
199
206CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte asnTag);
207
215CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeDate(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag);
216
223CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeDate(BufferedTransformation &bt, SecByteBlock &str, byte asnTag);
224
236CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0);
237
247CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits);
248
252CRYPTOPP_DLL void CRYPTOPP_API DERReencode(BufferedTransformation &bt, BufferedTransformation &dest);
253
261CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodePeekLength(const BufferedTransformation &bt);
262
264class CRYPTOPP_DLL OID
265{
266public:
267 virtual ~OID() {}
268
270 OID() {}
271
274 OID(word32 v) : m_values(1, v) {}
275
279 BERDecode(bt);
280 }
281
284 inline OID & operator+=(word32 rhs) {
285 m_values.push_back(rhs); return *this;
286 }
287
290 void DEREncode(BufferedTransformation &bt) const;
291
294 void BERDecode(BufferedTransformation &bt);
295
306 void BERDecodeAndCheck(BufferedTransformation &bt) const;
307
311 bool Empty() const {
312 return m_values.empty();
313 }
314
318 const std::vector<word32>& GetValues() const {
319 return m_values;
320 }
321
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
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
358 EncodedObjectFilter(BufferedTransformation *attachment = NULLPTR, unsigned int nObjects = 1, word32 flags = 0);
359
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
379class CRYPTOPP_DLL BERGeneralDecoder : public Store
380{
381public:
383 enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
384
385 virtual ~BERGeneralDecoder();
386
390 explicit BERGeneralDecoder(BufferedTransformation &inQueue);
391
395 explicit BERGeneralDecoder(BufferedTransformation &inQueue, byte asnTag);
396
400 explicit BERGeneralDecoder(BERGeneralDecoder &inQueue, byte asnTag);
401
404 bool IsDefiniteLength() const {
405 return m_definiteLength;
406 }
407
413 CRYPTOPP_ASSERT(m_definiteLength);
414 return IsDefiniteLength() ? m_length : 0;
415 }
416
419 bool EndReached() const;
420
425 byte PeekByte() const;
426
431 void CheckByte(byte b);
432
449 size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
450
471 size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
472
475 void MessageEnd();
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
490class CRYPTOPP_DLL DERGeneralEncoder : public ByteQueue
491{
492public:
494 enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
495
496 virtual ~DERGeneralEncoder();
497
501 explicit DERGeneralEncoder(BufferedTransformation &outQueue);
502
506 explicit DERGeneralEncoder(BufferedTransformation &outQueue, byte asnTag);
507
511 explicit DERGeneralEncoder(DERGeneralEncoder &outQueue, byte asnTag);
512
515 void MessageEnd();
516
517private:
518 BufferedTransformation &m_outQueue;
519 byte m_asnTag;
520 bool m_finished;
521};
522
524class CRYPTOPP_DLL BERSequenceDecoder : public BERGeneralDecoder
525{
526public:
528 enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
529
534 : BERGeneralDecoder(inQueue, DefaultTag) {}
535
539 explicit BERSequenceDecoder(BufferedTransformation &inQueue, byte asnTag)
540 : BERGeneralDecoder(inQueue, asnTag) {}
541
546 : BERGeneralDecoder(inQueue, DefaultTag) {}
547
551 explicit BERSequenceDecoder(BERSequenceDecoder &inQueue, byte asnTag)
552 : BERGeneralDecoder(inQueue, asnTag) {}
553};
554
556class CRYPTOPP_DLL DERSequenceEncoder : public DERGeneralEncoder
557{
558public:
560 enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
561
566 : DERGeneralEncoder(outQueue, DefaultTag) {}
567
571 explicit DERSequenceEncoder(BufferedTransformation &outQueue, byte asnTag)
572 : DERGeneralEncoder(outQueue, asnTag) {}
573
578 : DERGeneralEncoder(outQueue, DefaultTag) {}
579
583 explicit DERSequenceEncoder(DERSequenceEncoder &outQueue, byte asnTag)
584 : DERGeneralEncoder(outQueue, asnTag) {}
585};
586
588class CRYPTOPP_DLL BERSetDecoder : public BERGeneralDecoder
589{
590public:
592 enum {DefaultTag = SET | EnumToInt(CONSTRUCTED)};
593
598 : BERGeneralDecoder(inQueue, DefaultTag) {}
599
603 explicit BERSetDecoder(BufferedTransformation &inQueue, byte asnTag)
604 : BERGeneralDecoder(inQueue, asnTag) {}
605
609 explicit BERSetDecoder(BERSetDecoder &inQueue)
610 : BERGeneralDecoder(inQueue, DefaultTag) {}
611
615 explicit BERSetDecoder(BERSetDecoder &inQueue, byte asnTag)
616 : BERGeneralDecoder(inQueue, asnTag) {}
617};
618
620class CRYPTOPP_DLL DERSetEncoder : public DERGeneralEncoder
621{
622public:
624 enum {DefaultTag = SET | EnumToInt(CONSTRUCTED)};
625
630 : DERGeneralEncoder(outQueue, DefaultTag) {}
631
635 explicit DERSetEncoder(BufferedTransformation &outQueue, byte asnTag)
636 : DERGeneralEncoder(outQueue, asnTag) {}
637
641 explicit DERSetEncoder(DERSetEncoder &outQueue)
642 : DERGeneralEncoder(outQueue, DefaultTag) {}
643
647 explicit DERSetEncoder(DERSetEncoder &outQueue, byte asnTag)
648 : DERGeneralEncoder(outQueue, asnTag) {}
649};
650
653template <class T>
654class ASNOptional : public member_ptr<T>
655{
656public:
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
672 {
673 if (this->get() != NULLPTR)
674 this->get()->DEREncode(out);
675 }
676};
677
682template <class BASE>
683class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ASN1CryptoMaterial : public ASN1Object, public BASE
684{
685public:
692 {BEREncode(bt);}
693
697 {BERDecode(bt);}
698};
699
701class CRYPTOPP_DLL X509PublicKey : public ASN1CryptoMaterial<PublicKey>
702{
703public:
704 virtual ~X509PublicKey() {}
705
706 void BERDecode(BufferedTransformation &bt);
707 void DEREncode(BufferedTransformation &bt) const;
708
711 virtual OID GetAlgorithmID() const =0;
712
718 {BERDecodeNull(bt); return false;}
719
725 {DEREncodeNull(bt); return false;}
726
736 virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0;
737
743 virtual void DEREncodePublicKey(BufferedTransformation &bt) const =0;
744};
745
747class CRYPTOPP_DLL PKCS8PrivateKey : public ASN1CryptoMaterial<PrivateKey>
748{
749public:
750 virtual ~PKCS8PrivateKey() {}
751
752 void BERDecode(BufferedTransformation &bt);
753 void DEREncode(BufferedTransformation &bt) const;
754
757 virtual OID GetAlgorithmID() const =0;
758
764 {BERDecodeNull(bt); return false;}
765
771 {DEREncodeNull(bt); return false;}
772
782 virtual void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0;
783
789 virtual void DEREncodePrivateKey(BufferedTransformation &bt) const =0;
790
798 virtual void BERDecodeOptionalAttributes(BufferedTransformation &bt);
799
805 virtual void DEREncodeOptionalAttributes(BufferedTransformation &bt) const;
806
807protected:
808 ByteQueue m_optionalAttributes;
809};
810
811// ********************************************************
812
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
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
906inline bool operator==(const OID &lhs, const OID &rhs);
911inline bool operator!=(const OID &lhs, const OID &rhs);
917inline bool operator<(const OID &lhs, const OID &rhs);
924inline bool operator<=(const OID &lhs, const OID &rhs);
931inline bool operator>=(const OID &lhs, const OID &rhs);
935inline OID operator+(const OID &lhs, unsigned long rhs);
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 bool CRYPTOPP_API BERLengthDecode(BufferedTransformation &bt, size_t &length)
BER decode a length.
Definition asn.cpp:79
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodePeekLength(const BufferedTransformation &bt)
BER decode size.
Definition asn.cpp:288
void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag=INTEGER, T minValue=0, T maxValue=T(0xffffffff))
BER Decode unsigned value.
Definition asn.h:856
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeDate(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag)
DER encode date.
Definition asn.cpp:210
CRYPTOPP_DLL void CRYPTOPP_API DERReencode(BufferedTransformation &bt, BufferedTransformation &dest)
BER decode and DER re-encode.
Definition asn.cpp:271
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0)
DER encode bit string.
Definition asn.cpp:237
CRYPTOPP_DLL void CRYPTOPP_API DEREncodeNull(BufferedTransformation &bt)
DER encode NULL.
Definition asn.cpp:90
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeDate(BufferedTransformation &bt, SecByteBlock &str, byte asnTag)
BER decode date.
Definition asn.cpp:218
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &bt, SecByteBlock &str, byte asnTag)
BER decode text string.
Definition asn.cpp:172
CRYPTOPP_DLL void CRYPTOPP_API BERDecodeNull(BufferedTransformation &bt)
BER decode NULL.
Definition asn.cpp:96
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 CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen)
DER encode octet string.
Definition asn.cpp:107
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits)
DER decode bit string.
Definition asn.cpp:246
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
BER decode octet string.
Definition asn.cpp:120
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 CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const byte *str, size_t strLen, byte asnTag)
DER encode text string.
Definition asn.cpp:154
void BERDecodeError()
Raises a BERDecodeErr.
Definition asn.h:104
CRYPTOPP_DLL size_t CRYPTOPP_API DERLengthEncode(BufferedTransformation &bt, lword length)
DER encode a length.
Definition asn.cpp:20
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
lword RemainingLength() const
Determine remaining length.
Definition asn.h:412
bool IsDefiniteLength() const
Determine length encoding.
Definition asn.h:404
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 lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Definition cryptlib.cpp:505
virtual size_t Get(byte &outByte)
Retrieve a 8-bit byte.
Definition cryptlib.cpp:528
virtual size_t Peek(byte &outByte) const
Peek a 8-bit byte.
Definition cryptlib.cpp:551
size_t Put(byte inByte, bool blocking=true)
Input a byte for processing.
Definition cryptlib.h:1673
Data structure used to store byte strings.
Definition queue.h:23
DER General Encoder.
Definition asn.h:491
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=NULLPTR, unsigned int nObjects=1, word32 flags=0)
Construct an EncodedObjectFilter.
void Put(const byte *inString, size_t length)
Input a byte buffer for processing.
Definition asn.cpp:401
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
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.
Definition asn.cpp:381
OID & operator+=(word32 rhs)
Append a value to an OID.
Definition asn.h:284
Encodes and Decodes privateKeyInfo.
Definition asn.h:748
virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
Decode optional parameters.
Definition asn.h:763
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.
virtual OID GetAlgorithmID() const =0
Retrieves the OID of the algorithm.
virtual void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size)=0
Decode privateKey part of privateKeyInfo.
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.
virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size)=0
Decode subjectPublicKey part of subjectPublicKeyInfo.
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
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.
Implementation of BufferedTransformation's attachment interface.
Utility functions for the Crypto++ library.
#define EnumToInt(v)
Integer value.
Definition misc.h:502
Classes for an unlimited queue to store bytes.
Classes for automatic resource management.
Common C++ header files.