17 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 18 # pragma GCC diagnostic push 19 # pragma GCC diagnostic ignored "-Wconversion" 20 # pragma GCC diagnostic ignored "-Wsign-conversion" 34 OBJECT_IDENTIFIER = 0x06,
35 OBJECT_DESCRIPTOR = 0x07,
42 NUMERIC_STRING = 0x12,
43 PRINTABLE_STRING = 0x13,
45 VIDEOTEXT_STRING = 0x15,
48 GENERALIZED_TIME = 0x18,
49 GRAPHIC_STRING = 0x19,
50 VISIBLE_STRING = 0x1a,
64 CONTEXT_SPECIFIC = 0x80,
175 OID(word32 v) : m_values(1, v) {}
182 inline OID &
operator+=(word32 rhs) {m_values.push_back(rhs);
return *
this;}
205 return m_values.empty();
208 const std::vector<word32>& GetValues()
const {
217 std::vector<word32> m_values;
228 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};
229 enum State {IDENTIFIER, LENGTH, BODY, TAIL, ALL_DONE} m_state;
242 void Put(
const byte *inString,
size_t length);
244 unsigned int GetNumberOfCompletedObjects()
const {
return m_nCurrentObject;}
245 unsigned long GetPositionOfObject(
unsigned int i)
const {
return m_positions[i];}
251 std::vector<unsigned int> m_positions;
252 lword m_lengthRemaining;
253 word32 m_nObjects, m_nCurrentObject, m_level, m_flags;
266 bool IsDefiniteLength()
const {
return m_definiteLength;}
267 lword RemainingLength()
const {
CRYPTOPP_ASSERT(m_definiteLength);
return m_length;}
268 bool EndReached()
const;
269 byte PeekByte()
const;
270 void CheckByte(byte b);
281 bool m_finished, m_definiteLength;
284 void Init(byte asnTag);
287 lword ReduceLength(lword delta);
362 if (seqDecoder.
Peek(b) && (b & mask) == tag)
363 reset(
new T(seqDecoder));
370 if (this->
get() != NULLPTR)
379 template <
class BASE>
408 virtual OID GetAlgorithmID()
const =0;
431 virtual OID GetAlgorithmID()
const =0;
463 byte buf[
sizeof(w)+1];
465 if (asnTag == BOOLEAN)
467 buf[
sizeof(w)] = w ? 0xff : 0;
473 for (
unsigned int i=0; i<
sizeof(w); i++)
474 buf[i+1] = byte(w >> (
sizeof(w)-1-i)*8);
476 while (bc > 1 && buf[
sizeof(w)+1-bc] == 0)
478 if (buf[
sizeof(w)+1-bc] & 0x80)
483 out.
Put(buf+
sizeof(w)+1-bc, bc);
484 return 1+lengthBytes+bc;
498 T minValue = 0, T maxValue = T(0xffffffff))
501 if (!in.
Get(b) || b != asnTag)
510 if (asnTag == BOOLEAN && bc != 1)
512 if ((asnTag == INTEGER || asnTag == ENUMERATED) && bc == 0)
517 if (bc != in.
Get(buf, bc))
525 const byte *ptr = buf;
526 while (bc >
sizeof(w) && *ptr == 0)
535 for (
unsigned int i=0; i<bc; i++)
536 w = (w << 8) | ptr[i];
538 if (w < minValue || w > maxValue)
542 #ifdef CRYPTOPP_DOXYGEN_PROCESSING 564 inline bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
565 {
return lhs.m_values == rhs.m_values;}
566 inline bool operator!=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
567 {
return lhs.m_values != rhs.m_values;}
568 inline bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
569 {
return std::lexicographical_compare(lhs.m_values.begin(), lhs.m_values.end(), rhs.m_values.begin(), rhs.m_values.end());}
570 inline ::CryptoPP::OID
operator+(const ::CryptoPP::OID &lhs,
unsigned long rhs)
571 {return ::CryptoPP::OID(lhs)+=rhs;}
577 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 578 # pragma GCC diagnostic pop UnknownOID(const char *err)
Construct an UnknownOID.
virtual void DEREncode(BufferedTransformation &bt) const =0
Encode this object into a BufferedTransformation.
Utility functions for the Crypto++ library.
size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag=INTEGER)
DER Encode unsigned value.
Encodes and Decodes privateKeyInfo.
void DEREncodeNull(BufferedTransformation &bt)
DER encode NULL.
Abstract base classes that provide a uniform interface to this library.
void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag=INTEGER, T minValue=0, T maxValue=T(0xffffffff))
BER Decode unsigned value.
Classes for automatic resource management.
void DEREncode(BufferedTransformation &out)
DER encode optional data.
EncodedObjectFilter(BufferedTransformation *attachment=NULL, unsigned int nObjects=1, word32 flags=0)
Construct an EncodedObjectFilter.
Acts as a Source for pre-existing, static data.
OID(BufferedTransformation &bt)
Construct an OID.
bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
Pointer that overloads operator ->
Optional data encoder and decoder.
void BERDecode(BERSequenceDecoder &seqDecoder, byte tag, byte mask=~CONSTRUCTED)
BER decode optional data.
bool operator!=(const OID &lhs, const OID &rhs)
Compare two OIDs for inequality.
Classes for an unlimited queue to store bytes.
void BERDecodeNull(BufferedTransformation &bt)
BER decode NULL.
bool operator<(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
BER decode octet string.
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
UnknownOID()
Construct an UnknownOID.
OID & operator+=(word32 rhs)
Append a value to an OID.
virtual void BERDecode(BufferedTransformation &bt)=0
Decode this object from a BufferedTransformation.
ASN.1 encoded object filter.
Interface for encoding and decoding ASN1 objects.
OID operator+(const OID &lhs, unsigned long rhs)
Append a value to an OID.
size_t DEREncodeTextString(BufferedTransformation &bt, const std::string &str, byte asnTag)
DER encode text string.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
void Save(BufferedTransformation &bt) const
DER encode ASN.1 object.
void BERDecodeError()
Raises a BERDecodeErr.
Data structure used to store byte strings.
size_t DERLengthEncode(BufferedTransformation &bt, lword length)
DER encode a length.
void Put(const byte *inString, size_t length)
Input a byte buffer for processing.
Implementation of BufferedTransformation's attachment interface.
void DERReencode(BufferedTransformation &bt, BufferedTransformation &dest)
BER decode and DER re-encode.
OID(word32 v)
Construct an OID.
void Load(BufferedTransformation &bt)
BER decode ASN.1 object.
Exception thrown when an unknown object identifier is encountered.
Implementation of BufferedTransformation's attachment interface.
size_t DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen)
DER encode octet string.
size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits)
DER decode bit string.
Crypto++ library namespace.
Encodes and decodes subjectPublicKeyInfo.
virtual void BEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
size_t BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte asnTag)
BER decode text string.
Encode and decode ASN.1 objects with additional information.
bool BERLengthDecode(BufferedTransformation &bt, size_t &length)
BER decode a length.
size_t DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0)
DER encode bit string.
Interface for retrieving values given their names.
Exception thrown when an ASN.1 BER decoing error is encountered.