8 NAMESPACE_BEGIN(CryptoPP)
18 OBJECT_IDENTIFIER = 0x06,
19 OBJECT_DESCRIPTOR = 0x07,
26 NUMERIC_STRING = 0x12,
27 PRINTABLE_STRING = 0x13,
29 VIDEOTEXT_STRING = 0x15,
32 GENERALIZED_TIME = 0x18,
33 GRAPHIC_STRING = 0x19,
34 VISIBLE_STRING = 0x1a,
45 CONTEXT_SPECIFIC = 0x80,
66 CRYPTOPP_DLL
size_t CRYPTOPP_API DEREncodeOctetString(
BufferedTransformation &out,
const byte *str,
size_t strLen);
72 CRYPTOPP_DLL
size_t CRYPTOPP_API DEREncodeTextString(
BufferedTransformation &out,
const std::string &str, byte asnTag);
73 CRYPTOPP_DLL
size_t CRYPTOPP_API BERDecodeTextString(
BufferedTransformation &in, std::string &str, byte asnTag);
75 CRYPTOPP_DLL
size_t CRYPTOPP_API DEREncodeBitString(
BufferedTransformation &out,
const byte *str,
size_t strLen,
unsigned int unusedBits=0);
82 class CRYPTOPP_DLL
OID
86 OID(word32 v) : m_values(1, v) {}
89 inline OID & operator+=(word32 rhs) {m_values.push_back(rhs);
return *
this;}
97 std::vector<word32> m_values;
107 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};
110 void Put(
const byte *inString,
size_t length);
112 unsigned int GetNumberOfCompletedObjects()
const {
return m_nCurrentObject;}
113 unsigned long GetPositionOfObject(
unsigned int i)
const {
return m_positions[i];}
119 unsigned int m_nObjects, m_nCurrentObject, m_level;
120 std::vector<unsigned int> m_positions;
122 enum State {IDENTIFIER, LENGTH, BODY, TAIL, ALL_DONE} m_state;
124 lword m_lengthRemaining;
135 bool IsDefiniteLength()
const {
return m_definiteLength;}
136 lword RemainingLength()
const {assert(m_definiteLength);
return m_length;}
137 bool EndReached()
const;
138 byte PeekByte()
const;
139 void CheckByte(byte b);
149 bool m_finished, m_definiteLength;
153 void Init(byte asnTag);
154 void StoreInitialize(
const NameValuePairs ¶meters) {assert(
false);}
155 lword ReduceLength(lword delta);
223 if (seqDecoder.
Peek(b) && (b & mask) == tag)
224 reset(
new T(seqDecoder));
228 if (this->
get() != NULL)
229 this->
get()->DEREncode(out);
234 template <
class BASE>
251 virtual OID GetAlgorithmID()
const =0;
253 {BERDecodeNull(bt);
return false;}
255 {DEREncodeNull(bt);
return false;}
270 virtual OID GetAlgorithmID()
const =0;
272 {BERDecodeNull(bt);
return false;}
274 {DEREncodeNull(bt);
return false;}
298 byte buf[
sizeof(w)+1];
300 if (asnTag == BOOLEAN)
302 buf[
sizeof(w)] = w ? 0xff : 0;
308 for (
unsigned int i=0; i<
sizeof(w); i++)
309 buf[i+1] = byte(w >> (
sizeof(w)-1-i)*8);
311 while (bc > 1 && buf[
sizeof(w)+1-bc] == 0)
313 if (buf[
sizeof(w)+1-bc] & 0x80)
317 size_t lengthBytes = DERLengthEncode(out, bc);
318 out.
Put(buf+
sizeof(w)+1-bc, bc);
319 return 1+lengthBytes+bc;
327 T minValue = 0, T maxValue = 0xffffffff)
330 if (!in.
Get(b) || b != asnTag)
334 BERLengthDecode(in, bc);
340 if (bc != in.
Get(buf, bc))
343 const byte *ptr = buf;
344 while (bc >
sizeof(w) && *ptr == 0)
353 for (
unsigned int i=0; i<bc; i++)
354 w = (w << 8) | ptr[i];
356 if (w < minValue || w > maxValue)
360 inline bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
361 {
return lhs.m_values == rhs.m_values;}
362 inline bool operator!=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
363 {
return lhs.m_values != rhs.m_values;}
364 inline bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
365 {
return std::lexicographical_compare(lhs.m_values.begin(), lhs.m_values.end(), rhs.m_values.begin(), rhs.m_values.end());}
366 inline ::CryptoPP::OID operator+(const ::CryptoPP::OID &lhs,
unsigned long rhs)
367 {return ::CryptoPP::OID(lhs)+=rhs;}
virtual void DEREncode(BufferedTransformation &bt) const =0
encode this object into a BufferedTransformation, using DER (Distinguished Encoding Rules) ...
encodes/decodes privateKeyInfo
A BufferedTransformation that only contains pre-existing data as "output".
const std::string DEFAULT_CHANNEL
the default channel for BufferedTransformation, equal to the empty string
virtual void BERDecode(BufferedTransformation &bt)=0
decode this object from a BufferedTransformation, using BER (Basic Encoding Rules) ...
interface for encoding and decoding ASN1 objects
bool operator<(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
virtual void BEREncode(BufferedTransformation &bt) const
encode this object into a BufferedTransformation, using BER
provides an implementation of BufferedTransformation's attachment interface
encodes/decodes subjectPublicKeyInfo
interface for retrieving values given their names
BER Decode Exception Class, may be thrown during an ASN1 BER decode operation.