Crypto++
8.3
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"
274 OID(word32 v) : m_values(1, v) {}
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;
419 bool EndReached()
const;
425 byte PeekByte()
const;
431 void CheckByte(
byte b);
480 bool m_finished, m_definiteLength;
483 void Init(
byte asnTag);
486 lword ReduceLength(lword delta);
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 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.
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen)
DER encode octet string.
bool IsDefiniteLength() const
Determine length encoding.
Pointer that overloads operator ->
@ NUMERIC_STRING
ASN.1 Numeric string.
@ 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.
CRYPTOPP_DLL void CRYPTOPP_API DERReencode(BufferedTransformation &bt, BufferedTransformation &dest)
BER decode and DER re-encode.
Data structure used to store byte strings.
Encode and decode ASN.1 objects with additional information.
@ GENERALIZED_TIME
ASN.1 Generalized time.
@ CONTEXT_SPECIFIC
ASN.1 Context specific class.
DERSetEncoder(BufferedTransformation &outQueue, byte asnTag)
Construct an ASN.1 encoder.
DERSetEncoder(DERSetEncoder &outQueue)
Construct an ASN.1 encoder.
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits)
DER decode bit string.
virtual OID GetAlgorithmID() const =0
Retrieves the OID of the algorithm.
#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.
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &bt, SecByteBlock &str, byte asnTag)
BER decode text string.
Classes for automatic resource management.
friend bool operator<=(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
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.
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodePeekLength(const BufferedTransformation &bt)
BER decode size.
@ T61_STRING
ASN.1 T61 string.
ASN.1 encoded object filter.
@ PRINTABLE_STRING
ASN.1 Printable string.
Optional data encoder and decoder.
CRYPTOPP_DLL size_t CRYPTOPP_API DERLengthEncode(BufferedTransformation &bt, lword length)
DER encode a length.
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeDate(BufferedTransformation &bt, SecByteBlock &str, byte asnTag)
BER decode date.
@ 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.
Encodes and Decodes privateKeyInfo.
DERSequenceEncoder(BufferedTransformation &outQueue)
Construct an ASN.1 encoder.
size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag=INTEGER)
DER Encode unsigned value.
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.
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeDate(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag)
DER encode date.
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.
DERSetEncoder(BufferedTransformation &outQueue)
Construct an ASN.1 encoder.
lword RemainingLength() const
Determine remaining length.
@ PRIMITIVE
ASN.1 Primitive flag.
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0)
DER encode bit string.
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.
@ EXTERNAL
ASN.1 External reference.
@ UNIVERSAL
ASN.1 Universal class.
Classes for an unlimited queue to store bytes.
BERSetDecoder(BufferedTransformation &inQueue)
Construct an ASN.1 decoder.
@ ENUMERATED
ASN.1 Enumerated value.
void Load(BufferedTransformation &bt)
BER decode ASN.1 object.
OID(word32 v)
Construct an OID.
bool operator<=(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
DERSequenceEncoder(BufferedTransformation &outQueue, byte asnTag)
Construct an ASN.1 encoder.
std::ostream & operator<<(std::ostream &out, const OID &oid)
Print a OID value.
virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size)=0
Decode subjectPublicKey part of subjectPublicKeyInfo.
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.
@ IA5_STRING
ASN.1 IA5 string.
BERSequenceDecoder(BufferedTransformation &inQueue)
Construct an ASN.1 decoder.
OID & operator+=(word32 rhs)
Append a value to an OID.
std::ostream & Print(std::ostream &out) const
Print an OID.
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
BER decode octet string.
@ 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.
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.
CRYPTOPP_DLL void CRYPTOPP_API DEREncodeNull(BufferedTransformation &bt)
DER encode NULL.
DERSetEncoder(DERSetEncoder &outQueue, byte asnTag)
Construct an ASN.1 encoder.
virtual void DEREncode(BufferedTransformation &bt) const =0
Encode this object into a BufferedTransformation.
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const byte *str, size_t strLen, byte asnTag)
DER encode text string.
CRYPTOPP_DLL bool CRYPTOPP_API BERLengthDecode(BufferedTransformation &bt, size_t &length)
BER decode a length.
BERSetDecoder(BufferedTransformation &inQueue, byte asnTag)
Construct an ASN.1 decoder.
CRYPTOPP_DLL void CRYPTOPP_API BERDecodeNull(BufferedTransformation &bt)
BER decode NULL.
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.
UnknownOID(const char *err)
Construct an UnknownOID.