Crypto++
8.4
Free C++ class library of cryptographic schemes
|
Go to the documentation of this file.
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;
338 std::vector<word32> m_values;
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;
363 void Put(
const byte *inString,
size_t length);
365 unsigned int GetNumberOfCompletedObjects()
const {
return m_nCurrentObject;}
366 unsigned long GetPositionOfObject(
unsigned int i)
const {
return m_positions[i];}
372 std::vector<unsigned int> m_positions;
373 lword m_lengthRemaining;
374 word32 m_nObjects, m_nCurrentObject, m_level, m_flags;
405 return m_definiteLength;
414 return IsDefiniteLength() ? m_length : 0;
480 bool m_finished, m_definiteLength;
483 void Init(
byte asnTag);
665 if (seqDecoder.
Peek(b) && (b & mask) == tag)
666 reset(
new T(seqDecoder));
673 if (this->get() != NULLPTR)
674 this->get()->DEREncode(out);
682 template <
class BASE>
822 byte buf[
sizeof(w)+1];
826 buf[
sizeof(w)] = w ? 0xff : 0;
832 for (
unsigned int i=0; i<
sizeof(w); i++)
833 buf[i+1] =
byte(w >> (
sizeof(w)-1-i)*8);
835 while (bc > 1 && buf[
sizeof(w)+1-bc] == 0)
837 if (buf[
sizeof(w)+1-bc] & 0x80)
842 out.
Put(buf+
sizeof(w)+1-bc, bc);
843 return 1+lengthBytes+bc;
857 T minValue = 0, T maxValue = T(0xffffffff))
860 if (!in.
Get(b) || b != asnTag)
869 if (asnTag ==
BOOLEAN && bc != 1)
876 if (bc != in.
Get(buf, bc))
884 const byte *ptr = buf;
885 while (bc >
sizeof(w) && *ptr == 0)
894 for (
unsigned int i=0; i<bc; i++)
895 w = (w << 8) | ptr[i];
897 if (w < minValue || w > maxValue)
901 #ifdef CRYPTOPP_DOXYGEN_PROCESSING
940 {
return oid.
Print(out); }
942 inline bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
943 {
return lhs.m_values == rhs.m_values;}
944 inline bool operator!=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
945 {
return lhs.m_values != rhs.m_values;}
946 inline 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());}
948 inline bool operator<=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
949 {
return lhs<rhs || lhs==rhs;}
950 inline bool operator>=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
951 {
return ! (lhs<rhs);}
952 inline ::CryptoPP::OID
operator+(const ::CryptoPP::OID &lhs,
unsigned long rhs)
953 {return ::CryptoPP::OID(lhs)+=rhs;}
954 inline std::ostream&
operator<<(std::ostream& out,
const OID &oid)
955 {
return oid.
Print(out); }
961 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
962 # pragma GCC diagnostic pop
virtual void DEREncodeOptionalAttributes(BufferedTransformation &bt) const
Encode optional attributes.
virtual void BEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
OID(BufferedTransformation &bt)
Construct an OID.
friend bool operator<(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
BERSequenceDecoder(BERSequenceDecoder &inQueue, byte asnTag)
Construct an ASN.1 decoder.
bool IsDefiniteLength() const
Determine length encoding.
CRYPTOPP_DLL size_t BERDecodeTextString(BufferedTransformation &bt, SecByteBlock &str, byte asnTag)
BER decode text string.
Pointer that overloads operator ->
@ NUMERIC_STRING
ASN.1 Numeric string.
CRYPTOPP_DLL size_t DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0)
DER encode bit string.
CRYPTOPP_DLL bool BERLengthDecode(BufferedTransformation &bt, size_t &length)
BER decode a length.
@ APPLICATION
ASN.1 Application class.
@ OBJECT_IDENTIFIER
ASN.1 Object identifier.
void Put(const byte *inString, size_t length)
Input a byte buffer for processing.
Interface for encoding and decoding ASN1 objects.
Exception thrown when an unknown object identifier is encountered.
Data structure used to store byte strings.
Encode and decode ASN.1 objects with additional information.
@ GENERALIZED_TIME
ASN.1 Generalized time.
CRYPTOPP_DLL size_t BERDecodePeekLength(const BufferedTransformation &bt)
BER decode size.
@ CONTEXT_SPECIFIC
ASN.1 Context specific class.
void BERDecode(BufferedTransformation &bt)
BER decode an OID.
DERSetEncoder(BufferedTransformation &outQueue, byte asnTag)
Construct an ASN.1 encoder.
DERSetEncoder(DERSetEncoder &outQueue)
Construct an ASN.1 encoder.
virtual OID GetAlgorithmID() const =0
Retrieves the OID of the algorithm.
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.
void MessageEnd()
Signals the end of messages to the object.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
@ VIDEOTEXT_STRING
ASN.1 Videotext string.
DERSequenceEncoder(DERSequenceEncoder &outQueue)
Construct an ASN.1 encoder.
friend bool operator>=(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
Decode algorithm parameters.
Acts as a Source for pre-existing, static data.
@ GENERAL_STRING
ASN.1 General string.
Classes for automatic resource management.
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 inequality.
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
virtual OID GetAlgorithmID() const =0
Retrieves the OID of the algorithm.
@ REAL
ASN.1 Real integer.
@ T61_STRING
ASN.1 T61 string.
ASN.1 encoded object filter.
BERGeneralDecoder(BERGeneralDecoder &inQueue, byte asnTag)
Construct an ASN.1 decoder.
@ PRINTABLE_STRING
ASN.1 Printable string.
Optional data encoder and decoder.
unsigned int word32
32-bit unsigned datatype
@ BIT_STRING
ASN.1 Bit string.
bool operator<(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
void DEREncode(BufferedTransformation &out)
DER encode optional data.
Implementation of BufferedTransformation's attachment interface.
virtual void DEREncodePrivateKey(BufferedTransformation &bt) const =0
Encode privateKey part of privateKeyInfo.
void BERDecodeError()
Raises a BERDecodeErr.
CRYPTOPP_DLL size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits)
DER decode bit string.
Encodes and Decodes privateKeyInfo.
BERGeneralDecoder(BufferedTransformation &inQueue, byte asnTag)
Construct an ASN.1 decoder.
DERSequenceEncoder(BufferedTransformation &outQueue)
Construct an ASN.1 encoder.
size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag=INTEGER)
DER Encode unsigned value.
CRYPTOPP_DLL void DEREncodeNull(BufferedTransformation &bt)
DER encode NULL.
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.
@ UTC_TIME
ASN.1 UTC time.
Utility functions for the Crypto++ library.
Encodes and decodes subjectPublicKeyInfo.
virtual void BERDecode(BufferedTransformation &bt)=0
Decode this object from a BufferedTransformation.
Implementation of BufferedTransformation's attachment interface.
@ PRIVATE
ASN.1 Private class.
UnknownOID()
Construct an UnknownOID.
CRYPTOPP_DLL size_t DERLengthEncode(BufferedTransformation &bt, lword length)
DER encode a length.
BERGeneralDecoder(BufferedTransformation &inQueue)
Construct an ASN.1 decoder.
DERSetEncoder(BufferedTransformation &outQueue)
Construct an ASN.1 encoder.
lword RemainingLength() const
Determine remaining length.
@ PRIMITIVE
ASN.1 Primitive flag.
virtual void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size)=0
Decode privateKey part of privateKeyInfo.
@ VISIBLE_STRING
ASN.1 Visible string.
BERSequenceDecoder(BERSequenceDecoder &inQueue)
Construct an ASN.1 decoder.
@ GRAPHIC_STRING
ASN.1 Graphic string.
DERGeneralEncoder(DERGeneralEncoder &outQueue, byte asnTag)
Construct an ASN.1 encoder.
@ EXTERNAL
ASN.1 External reference.
@ UNIVERSAL
ASN.1 Universal class.
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes to another BufferedTransformation.
Classes for an unlimited queue to store bytes.
BERSetDecoder(BufferedTransformation &inQueue)
Construct an ASN.1 decoder.
byte PeekByte() const
Determine next octet.
void BERDecode(BufferedTransformation &bt)
Decode this object from a BufferedTransformation.
void DEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
void MessageEnd()
Signals the end of messages to the object.
@ ENUMERATED
ASN.1 Enumerated value.
void Load(BufferedTransformation &bt)
BER decode ASN.1 object.
void DEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
CRYPTOPP_DLL size_t DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen)
DER encode octet string.
OID(word32 v)
Construct an OID.
bool operator<=(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
CRYPTOPP_DLL size_t DEREncodeDate(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag)
DER encode date.
DERSequenceEncoder(BufferedTransformation &outQueue, byte asnTag)
Construct an ASN.1 encoder.
std::ostream & operator<<(std::ostream &out, const OID &oid)
Print a OID value.
DERGeneralEncoder(BufferedTransformation &outQueue, byte asnTag)
Construct an ASN.1 encoder.
virtual void BERDecodeOptionalAttributes(BufferedTransformation &bt)
Decode optional attributes.
virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size)=0
Decode subjectPublicKey part of subjectPublicKeyInfo.
word64 lword
Large word type.
virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
Encode optional parameters.
@ UNIVERSAL_STRING
ASN.1 Universal string.
const std::vector< word32 > & GetValues() const
Retrieve OID value array.
BERSetDecoder(BERSetDecoder &inQueue)
Construct an ASN.1 decoder.
@ SEQUENCE
ASN.1 Sequence.
friend bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
Decode optional parameters.
virtual void DEREncodePublicKey(BufferedTransformation &bt) const =0
Encode subjectPublicKey part of subjectPublicKeyInfo.
void Save(BufferedTransformation &bt) const
DER encode ASN.1 object.
@ BMP_STRING
ASN.1 BMP string.
BERSequenceDecoder(BufferedTransformation &inQueue, byte asnTag)
Construct an ASN.1 decoder.
DERSequenceEncoder(DERSequenceEncoder &outQueue, byte asnTag)
Construct an ASN.1 encoder.
@ OCTET_STRING
ASN.1 Octet string.
Crypto++ library namespace.
EncodedObjectFilter(BufferedTransformation *attachment=NULL, unsigned int nObjects=1, word32 flags=0)
Construct an EncodedObjectFilter.
BERSetDecoder(BERSetDecoder &inQueue, byte asnTag)
Construct an ASN.1 decoder.
virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
Encode algorithm parameters.
std::ostream & Print(std::ostream &out) const
Print an OID.
#define CRYPTOPP_API
Win32 calling convention.
@ IA5_STRING
ASN.1 IA5 string.
void BERDecode(BufferedTransformation &bt)
Decode this object from a BufferedTransformation.
CRYPTOPP_DLL size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
BER decode octet string.
BERSequenceDecoder(BufferedTransformation &inQueue)
Construct an ASN.1 decoder.
void BERDecodeAndCheck(BufferedTransformation &bt) const
BER decode an OID.
OID & operator+=(word32 rhs)
Append a value to an OID.
CRYPTOPP_DLL size_t DEREncodeTextString(BufferedTransformation &bt, const byte *str, size_t strLen, byte asnTag)
DER encode text string.
CRYPTOPP_DLL void BERDecodeNull(BufferedTransformation &bt)
BER decode NULL.
@ CONSTRUCTED
ASN.1 Constructed flag.
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 inequality.
@ OBJECT_DESCRIPTOR
ASN.1 Object descriptor.
void CheckByte(byte b)
Determine next octet.
Exception thrown when an ASN.1 BER decoing error is encountered.
void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag=INTEGER, T minValue=0, T maxValue=T(0xffffffff))
BER Decode unsigned value.
@ UTF8_STRING
ASN.1 UTF-8 string.
DERSetEncoder(DERSetEncoder &outQueue, byte asnTag)
Construct an ASN.1 encoder.
BERSetDecoder(BufferedTransformation &inQueue, byte asnTag)
Construct an ASN.1 decoder.
DERGeneralEncoder(BufferedTransformation &outQueue)
Construct an ASN.1 encoder.
const lword LWORD_MAX
Large word type max value.
Interface for retrieving values given their names.
void BERDecode(BERSequenceDecoder &seqDecoder, byte tag, byte mask=~CONSTRUCTED)
BER decode optional data.
Abstract base classes that provide a uniform interface to this library.
bool Empty() const
Determine if OID is empty.
bool EndReached() const
Determine end of stream.
CRYPTOPP_DLL void DERReencode(BufferedTransformation &bt, BufferedTransformation &dest)
BER decode and DER re-encode.
UnknownOID(const char *err)
Construct an UnknownOID.
CRYPTOPP_DLL size_t BERDecodeDate(BufferedTransformation &bt, SecByteBlock &str, byte asnTag)
BER decode date.