19#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
20# pragma GCC diagnostic push
21# pragma GCC diagnostic ignored "-Wconversion"
22# pragma GCC diagnostic ignored "-Wsign-conversion"
285 m_values.push_back(rhs);
return *
this;
312 return m_values.empty();
329 std::ostream&
Print(std::ostream& out)
const;
339 std::vector<word32> m_values;
350 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};
351 enum State {IDENTIFIER, LENGTH, BODY, TAIL, ALL_DONE} m_state;
364 void Put(
const byte *inString,
size_t length);
366 unsigned int GetNumberOfCompletedObjects()
const {
return m_nCurrentObject;}
367 unsigned long GetPositionOfObject(
unsigned int i)
const {
return m_positions[i];}
373 std::vector<unsigned int> m_positions;
374 lword m_lengthRemaining;
375 word32 m_nObjects, m_nCurrentObject, m_level, m_flags;
406 return m_definiteLength;
415 return IsDefiniteLength() ? m_length : 0;
481 bool m_finished, m_definiteLength;
484 void Init(
byte asnTag);
666 if (seqDecoder.
Peek(b) && (b & mask) == tag)
667 reset(
new T(seqDecoder));
674 if (this->get() != NULLPTR)
675 this->get()->DEREncode(out);
823 byte buf[
sizeof(w)+1];
827 buf[
sizeof(w)] = w ? 0xff : 0;
833 for (
unsigned int i=0; i<
sizeof(w); i++)
834 buf[i+1] =
byte(w >> (
sizeof(w)-1-i)*8);
836 while (bc > 1 && buf[
sizeof(w)+1-bc] == 0)
838 if (buf[
sizeof(w)+1-bc] & 0x80)
843 out.
Put(buf+
sizeof(w)+1-bc, bc);
844 return 1+lengthBytes+bc;
858 T minValue = 0, T maxValue = T(0xffffffff))
861 if (!in.
Get(b) || b != asnTag)
870 if (asnTag ==
BOOLEAN && bc != 1)
877 if (bc != in.
Get(buf, bc))
885 const byte *ptr = buf;
886 while (bc >
sizeof(w) && *ptr == 0)
895 for (
unsigned int i=0; i<bc; i++)
896 w = (w << 8) | ptr[i];
898 if (w < minValue || w > maxValue)
902#ifdef CRYPTOPP_DOXYGEN_PROCESSING
949inline bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
950 {
return lhs.m_values == rhs.m_values;}
951inline bool operator!=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
952 {
return lhs.m_values != rhs.m_values;}
953inline bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
954 {
return std::lexicographical_compare(lhs.m_values.begin(), lhs.m_values.end(), rhs.m_values.begin(), rhs.m_values.end());}
955inline bool operator>(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
956 {
return ! (lhs<rhs || lhs==rhs);}
957inline bool operator<=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
958 {
return lhs<rhs || lhs==rhs;}
959inline bool operator>=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
960 {
return ! (lhs<rhs);}
961inline ::CryptoPP::OID
operator+(const ::CryptoPP::OID &lhs,
unsigned long rhs)
962 {return ::CryptoPP::OID(lhs)+=rhs;}
963inline std::ostream&
operator<<(std::ostream& out,
const OID &oid)
964 {
return oid.
Print(out); }
970#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
971# pragma GCC diagnostic pop
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.
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.
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.
bool operator>(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
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.
@ PRIVATE
ASN.1 Private class.
@ CONSTRUCTED
ASN.1 Constructed flag.
@ APPLICATION
ASN.1 Application class.
@ CONTEXT_SPECIFIC
ASN.1 Context specific class.
@ UNIVERSAL
ASN.1 Universal class.
@ PRIMITIVE
ASN.1 Primitive flag.
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.
@ REAL
ASN.1 Real integer.
@ UNIVERSAL_STRING
ASN.1 Universal string.
@ NUMERIC_STRING
ASN.1 Numeric string.
@ OCTET_STRING
ASN.1 Octet string.
@ GRAPHIC_STRING
ASN.1 Graphic string.
@ PRINTABLE_STRING
ASN.1 Printable string.
@ ENUMERATED
ASN.1 Enumerated value.
@ EXTERNAL
ASN.1 External reference.
@ UTC_TIME
ASN.1 UTC time.
@ OBJECT_IDENTIFIER
ASN.1 Object identifier.
@ IA5_STRING
ASN.1 IA5 string.
@ BMP_STRING
ASN.1 BMP string.
@ VISIBLE_STRING
ASN.1 Visible string.
@ BIT_STRING
ASN.1 Bit string.
@ GENERAL_STRING
ASN.1 General string.
@ SEQUENCE
ASN.1 Sequence.
@ GENERALIZED_TIME
ASN.1 Generalized time.
@ VIDEOTEXT_STRING
ASN.1 Videotext string.
@ OBJECT_DESCRIPTOR
ASN.1 Object descriptor.
@ UTF8_STRING
ASN.1 UTF-8 string.
@ T61_STRING
ASN.1 T61 string.
CRYPTOPP_DLL size_t DERLengthEncode(BufferedTransformation &bt, lword length)
DER encode a length.
void BERDecodeError()
Raises a BERDecodeErr.
Encode and decode ASN.1 objects with additional information.
void Load(BufferedTransformation &bt)
BER decode ASN.1 object.
void Save(BufferedTransformation &bt) const
DER encode ASN.1 object.
Interface for encoding and decoding ASN1 objects.
Optional data encoder and decoder.
void DEREncode(BufferedTransformation &out)
DER encode optional data.
void BERDecode(BERSequenceDecoder &seqDecoder, byte tag, byte mask=~CONSTRUCTED)
BER decode optional data.
Exception thrown when an ASN.1 BER decoing error is encountered.
bool EndReached() const
Determine end of stream.
lword RemainingLength() const
Determine remaining length.
bool IsDefiniteLength() const
Determine length encoding.
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.
BERSequenceDecoder(BERSequenceDecoder &inQueue)
Construct an ASN.1 decoder.
BERSequenceDecoder(BERSequenceDecoder &inQueue, byte asnTag)
Construct an ASN.1 decoder.
BERSequenceDecoder(BufferedTransformation &inQueue)
Construct an ASN.1 decoder.
BERSequenceDecoder(BufferedTransformation &inQueue, byte asnTag)
Construct an ASN.1 decoder.
BERSetDecoder(BufferedTransformation &inQueue)
Construct an ASN.1 decoder.
BERSetDecoder(BufferedTransformation &inQueue, byte asnTag)
Construct an ASN.1 decoder.
BERSetDecoder(BERSetDecoder &inQueue, byte asnTag)
Construct an ASN.1 decoder.
BERSetDecoder(BERSetDecoder &inQueue)
Construct an ASN.1 decoder.
Data structure used to store byte strings.
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.
DERSequenceEncoder(DERSequenceEncoder &outQueue, byte asnTag)
Construct an ASN.1 encoder.
DERSequenceEncoder(BufferedTransformation &outQueue, byte asnTag)
Construct an ASN.1 encoder.
DERSequenceEncoder(DERSequenceEncoder &outQueue)
Construct an ASN.1 encoder.
DERSequenceEncoder(BufferedTransformation &outQueue)
Construct an ASN.1 encoder.
DERSetEncoder(DERSetEncoder &outQueue)
Construct an ASN.1 encoder.
DERSetEncoder(BufferedTransformation &outQueue)
Construct an ASN.1 encoder.
DERSetEncoder(BufferedTransformation &outQueue, byte asnTag)
Construct an ASN.1 encoder.
DERSetEncoder(DERSetEncoder &outQueue, byte asnTag)
Construct an ASN.1 encoder.
ASN.1 encoded object filter.
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.
Interface for retrieving values given their names.
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.
bool Empty() const
Determine if OID is empty.
OID(word32 v)
Construct an OID.
const std::vector< word32 > & GetValues() const
Retrieve OID value array.
OID(BufferedTransformation &bt)
Construct an OID.
std::ostream & Print(std::ostream &out) const
Print an OID.
OID & operator+=(word32 rhs)
Append a value to an OID.
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.
virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
Decode optional parameters.
virtual void BERDecodeOptionalAttributes(BufferedTransformation &bt)
Decode optional attributes.
virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
Encode optional parameters.
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.
Acts as a Source for pre-existing, static data.
Exception thrown when an unknown object identifier is encountered.
UnknownOID()
Construct an UnknownOID.
UnknownOID(const char *err)
Construct an UnknownOID.
Encodes and decodes subjectPublicKeyInfo.
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.
virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
Decode algorithm parameters.
Pointer that overloads operator ->
#define CRYPTOPP_API
Win32 calling convention.
const lword LWORD_MAX
Large word type max value.
unsigned int word32
32-bit unsigned datatype
word64 lword
Large word type.
Abstract base classes that provide a uniform interface to this library.
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Implementation of BufferedTransformation's attachment interface.
Utility functions for the Crypto++ library.
#define EnumToInt(v)
Integer value.
Crypto++ library namespace.
Classes for an unlimited queue to store bytes.
Classes for automatic resource management.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.