Crypto++
5.6.4
Free C++ class library of cryptographic schemes
|
Go to the documentation of this file.
27 OBJECT_IDENTIFIER = 0x06,
28 OBJECT_DESCRIPTOR = 0x07,
35 NUMERIC_STRING = 0x12,
36 PRINTABLE_STRING = 0x13,
38 VIDEOTEXT_STRING = 0x15,
41 GENERALIZED_TIME = 0x18,
42 GRAPHIC_STRING = 0x19,
43 VISIBLE_STRING = 0x1a,
57 CONTEXT_SPECIFIC = 0x80,
166 OID(word32 v) : m_values(1, v) {}
173 inline OID &
operator+=(word32 rhs) {m_values.push_back(rhs);
return *
this;}
195 std::vector<word32> m_values;
206 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};
217 void Put(
const byte *inString,
size_t length);
219 unsigned int GetNumberOfCompletedObjects()
const {
return m_nCurrentObject;}
220 unsigned long GetPositionOfObject(
unsigned int i)
const {
return m_positions[i];}
226 unsigned int m_nObjects, m_nCurrentObject, m_level;
227 std::vector<unsigned int> m_positions;
229 enum State {IDENTIFIER, LENGTH, BODY, TAIL, ALL_DONE} m_state;
231 lword m_lengthRemaining;
242 bool IsDefiniteLength()
const {
return m_definiteLength;}
243 lword RemainingLength()
const {assert(m_definiteLength);
return m_length;}
244 bool EndReached()
const;
245 byte PeekByte()
const;
246 void CheckByte(
byte b);
256 bool m_finished, m_definiteLength;
260 void Init(
byte asnTag);
262 {CRYPTOPP_UNUSED(parameters); assert(
false);}
263 lword ReduceLength(lword delta);
275 #if defined(CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562)
348 if (seqDecoder.
Peek(b) && (b & mask) == tag)
349 reset(
new T(seqDecoder));
356 if (this->get() != NULL)
357 this->get()->DEREncode(out);
365 template <
class BASE>
445 byte buf[
sizeof(w)+1];
447 if (asnTag == BOOLEAN)
449 buf[
sizeof(w)] = w ? 0xff : 0;
455 for (
unsigned int i=0; i<
sizeof(w); i++)
456 buf[i+1] =
byte(w >> (
sizeof(w)-1-i)*8);
458 while (bc > 1 && buf[
sizeof(w)+1-bc] == 0)
460 if (buf[
sizeof(w)+1-bc] & 0x80)
465 out.
Put(buf+
sizeof(w)+1-bc, bc);
466 return 1+lengthBytes+bc;
480 T minValue = 0, T maxValue = T(0xffffffff))
483 if (!in.
Get(b) || b != asnTag)
492 if (asnTag == BOOLEAN && bc != 1)
494 if ((asnTag == INTEGER || asnTag == ENUMERATED) && bc == 0)
499 if (bc != in.
Get(buf, bc))
507 const byte *ptr = buf;
508 while (bc >
sizeof(w) && *ptr == 0)
517 for (
unsigned int i=0; i<bc; i++)
518 w = (w << 8) | ptr[i];
520 if (w < minValue || w > maxValue)
524 #ifdef CRYPTOPP_DOXYGEN_PROCESSING
546 inline bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
547 {
return lhs.m_values == rhs.m_values;}
548 inline bool operator!=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
549 {
return lhs.m_values != rhs.m_values;}
550 inline bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
551 {
return std::lexicographical_compare(lhs.m_values.begin(), lhs.m_values.end(), rhs.m_values.begin(), rhs.m_values.end());}
552 inline ::CryptoPP::OID
operator+(const ::CryptoPP::OID &lhs,
unsigned long rhs)
553 {return ::CryptoPP::OID(lhs)+=rhs;}
size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
BER decode octet string.
virtual void BEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
OID(BufferedTransformation &bt)
Construct an OID.
size_t BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte asnTag)
BER decode text string.
Pointer that overloads operator ->
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.
void BERDecodeNull(BufferedTransformation &bt)
BER decode NULL.
Data structure used to store byte strings.
Encode and decode ASN.1 objects with additional information.
virtual OID GetAlgorithmID() const =0
Retrieves the OID of the algorithm.
Acts as a Source for pre-existing, static data.
Classes for automatic resource management.
void DEREncodeNull(BufferedTransformation &bt)
DER encode NULL.
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
virtual OID GetAlgorithmID() const =0
Retrieves the OID of the algorithm.
size_t DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0)
DER encode bit string.
ASN.1 encoded object filter.
Optional data encoder and decoder.
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, without the OCTET STRING header
void BERDecodeError()
Raises a BERDecodeErr.
Encodes and decodesprivateKeyInfo.
size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits)
DER decode bit string.
void DERReencode(BufferedTransformation &bt, BufferedTransformation &dest)
BER decode and DER re-encode.
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 equality.
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.
UnknownOID()
Construct an UnknownOID.
virtual void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size)=0
decode privateKey part of privateKeyInfo, without the OCTET STRING header
Classes for an unlimited queue to store bytes.
void Load(BufferedTransformation &bt)
BER decode ASN.1 object.
size_t DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen)
DER encode octet string.
OID(word32 v)
Construct an OID.
virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size)=0
decode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header
size_t DEREncodeTextString(BufferedTransformation &bt, const std::string &str, byte asnTag)
DER encode text string.
bool BERLengthDecode(BufferedTransformation &bt, size_t &length)
BER decode a length.
virtual void DEREncodePublicKey(BufferedTransformation &bt) const =0
encode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header
void Save(BufferedTransformation &bt) const
DER encode ASN.1 object.
Crypto++ library namespace.
EncodedObjectFilter(BufferedTransformation *attachment=NULL, unsigned int nObjects=1, word32 flags=0)
Construct an EncodedObjectFilter.
size_t DERLengthEncode(BufferedTransformation &bt, lword length)
DER encode a length.
OID & operator+=(word32 rhs)
Append a value to an OID.
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.
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.
virtual void DEREncode(BufferedTransformation &bt) const =0
Encode this object into a BufferedTransformation.
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.
UnknownOID(const char *err)
Construct an UnknownOID.