2017-01-27 12:05:45 +00:00
|
|
|
// asn.h - originally written and placed in the public domain by Wei Dai
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \file asn.h
|
|
|
|
/// \brief Classes and functions for working with ANS.1 objects
|
2015-11-05 06:59:46 +00:00
|
|
|
|
|
|
|
#ifndef CRYPTOPP_ASN_H
|
|
|
|
#define CRYPTOPP_ASN_H
|
|
|
|
|
|
|
|
#include "cryptlib.h"
|
|
|
|
#include "filters.h"
|
|
|
|
#include "smartptr.h"
|
|
|
|
#include "stdcpp.h"
|
|
|
|
#include "queue.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
2019-09-29 19:09:25 +00:00
|
|
|
#include <iosfwd>
|
|
|
|
|
2016-12-02 19:47:31 +00:00
|
|
|
// Issue 340
|
|
|
|
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
|
|
|
|
# pragma GCC diagnostic push
|
|
|
|
# pragma GCC diagnostic ignored "-Wconversion"
|
|
|
|
# pragma GCC diagnostic ignored "-Wsign-conversion"
|
|
|
|
#endif
|
|
|
|
|
2015-11-05 06:59:46 +00:00
|
|
|
NAMESPACE_BEGIN(CryptoPP)
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief ASN.1 types
|
2019-10-08 00:07:32 +00:00
|
|
|
/// \note These tags are not complete
|
2015-11-05 06:59:46 +00:00
|
|
|
enum ASNTag
|
|
|
|
{
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Boolean
|
2015-11-05 06:59:46 +00:00
|
|
|
BOOLEAN = 0x01,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Integer
|
2015-11-05 06:59:46 +00:00
|
|
|
INTEGER = 0x02,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Bit string
|
2015-11-05 06:59:46 +00:00
|
|
|
BIT_STRING = 0x03,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Octet string
|
2015-11-05 06:59:46 +00:00
|
|
|
OCTET_STRING = 0x04,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Null
|
2015-11-05 06:59:46 +00:00
|
|
|
TAG_NULL = 0x05,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Object identifier
|
2015-11-05 06:59:46 +00:00
|
|
|
OBJECT_IDENTIFIER = 0x06,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Object descriptor
|
2015-11-05 06:59:46 +00:00
|
|
|
OBJECT_DESCRIPTOR = 0x07,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 External reference
|
2015-11-05 06:59:46 +00:00
|
|
|
EXTERNAL = 0x08,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Real integer
|
2015-11-05 06:59:46 +00:00
|
|
|
REAL = 0x09,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Enumerated value
|
2015-11-05 06:59:46 +00:00
|
|
|
ENUMERATED = 0x0a,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 UTF-8 string
|
2015-11-05 06:59:46 +00:00
|
|
|
UTF8_STRING = 0x0c,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Sequence
|
2015-11-05 06:59:46 +00:00
|
|
|
SEQUENCE = 0x10,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Set
|
2015-11-05 06:59:46 +00:00
|
|
|
SET = 0x11,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Numeric string
|
2015-11-05 06:59:46 +00:00
|
|
|
NUMERIC_STRING = 0x12,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Printable string
|
2015-11-05 06:59:46 +00:00
|
|
|
PRINTABLE_STRING = 0x13,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 T61 string
|
2015-11-05 06:59:46 +00:00
|
|
|
T61_STRING = 0x14,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Videotext string
|
2015-11-05 06:59:46 +00:00
|
|
|
VIDEOTEXT_STRING = 0x15,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 IA5 string
|
2015-11-05 06:59:46 +00:00
|
|
|
IA5_STRING = 0x16,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 UTC time
|
2015-11-05 06:59:46 +00:00
|
|
|
UTC_TIME = 0x17,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Generalized time
|
2015-11-05 06:59:46 +00:00
|
|
|
GENERALIZED_TIME = 0x18,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Graphic string
|
2015-11-05 06:59:46 +00:00
|
|
|
GRAPHIC_STRING = 0x19,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Visible string
|
2015-11-05 06:59:46 +00:00
|
|
|
VISIBLE_STRING = 0x1a,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 General string
|
2019-10-01 03:39:29 +00:00
|
|
|
GENERAL_STRING = 0x1b,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Universal string
|
2019-10-01 03:39:29 +00:00
|
|
|
UNIVERSAL_STRING = 0x1c,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 BMP string
|
2019-10-01 03:39:29 +00:00
|
|
|
BMP_STRING = 0x1e
|
2015-11-05 06:59:46 +00:00
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief ASN.1 flags
|
2019-10-08 00:07:32 +00:00
|
|
|
/// \note These flags are not complete
|
2015-11-05 06:59:46 +00:00
|
|
|
enum ASNIdFlag
|
|
|
|
{
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Universal class
|
2016-12-24 09:55:21 +00:00
|
|
|
UNIVERSAL = 0x00,
|
2019-10-28 19:33:36 +00:00
|
|
|
// DATA = 0x01,
|
|
|
|
// HEADER = 0x02,
|
|
|
|
/// \brief ASN.1 Primitive flag
|
2016-12-24 09:55:21 +00:00
|
|
|
PRIMITIVE = 0x00,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Constructed flag
|
2016-12-24 09:55:21 +00:00
|
|
|
CONSTRUCTED = 0x20,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Application class
|
2016-12-24 09:55:21 +00:00
|
|
|
APPLICATION = 0x40,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Context specific class
|
2016-12-24 09:55:21 +00:00
|
|
|
CONTEXT_SPECIFIC = 0x80,
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \brief ASN.1 Private class
|
2016-12-24 09:55:21 +00:00
|
|
|
PRIVATE = 0xc0
|
2015-11-05 06:59:46 +00:00
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Raises a BERDecodeErr
|
2015-11-05 06:59:46 +00:00
|
|
|
inline void BERDecodeError() {throw BERDecodeErr();}
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Exception thrown when an unknown object identifier is encountered
|
2015-11-05 06:59:46 +00:00
|
|
|
class CRYPTOPP_DLL UnknownOID : public BERDecodeErr
|
|
|
|
{
|
|
|
|
public:
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Construct an UnknownOID
|
2015-11-05 06:59:46 +00:00
|
|
|
UnknownOID() : BERDecodeErr("BER decode error: unknown object identifier") {}
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Construct an UnknownOID
|
|
|
|
/// \param err error message to use for the execption
|
2015-11-05 06:59:46 +00:00
|
|
|
UnknownOID(const char *err) : BERDecodeErr(err) {}
|
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER encode a length
|
|
|
|
/// \param bt BufferedTransformation object for writing
|
|
|
|
/// \param length the size to encode
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the number of octets used for the encoding
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API DERLengthEncode(BufferedTransformation &bt, lword length);
|
2016-04-08 05:51:21 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER decode a length
|
|
|
|
/// \param bt BufferedTransformation object for reading
|
|
|
|
/// \param length the decoded size
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return true if the value was decoded
|
|
|
|
/// \throw BERDecodeError if the value fails to decode or is too large for size_t
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \details BERLengthDecode() returns false if the encoding is indefinite length.
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL bool CRYPTOPP_API BERLengthDecode(BufferedTransformation &bt, size_t &length);
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER encode NULL
|
|
|
|
/// \param bt BufferedTransformation object for writing
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL void CRYPTOPP_API DEREncodeNull(BufferedTransformation &bt);
|
2016-04-08 05:51:21 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER decode NULL
|
|
|
|
/// \param bt BufferedTransformation object for reading
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL void CRYPTOPP_API BERDecodeNull(BufferedTransformation &bt);
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER encode octet string
|
|
|
|
/// \param bt BufferedTransformation object for writing
|
|
|
|
/// \param str the string to encode
|
|
|
|
/// \param strLen the length of the string
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the number of octets used for the encoding
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen);
|
2016-04-08 05:51:21 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER encode octet string
|
|
|
|
/// \param bt BufferedTransformation object for reading
|
|
|
|
/// \param str the string to encode
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the number of octets used for the encoding
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeOctetString(BufferedTransformation &bt, const SecByteBlock &str);
|
2016-04-08 05:51:21 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER decode octet string
|
|
|
|
/// \param bt BufferedTransformation object for reading
|
|
|
|
/// \param str the decoded string
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the number of octets used for the encoding
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str);
|
2016-04-08 05:51:21 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER decode octet string
|
|
|
|
/// \param bt BufferedTransformation object for reading
|
|
|
|
/// \param str the decoded string
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the number of octets used for the encoding
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeOctetString(BufferedTransformation &bt, BufferedTransformation &str);
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2019-09-30 03:28:30 +00:00
|
|
|
/// \brief DER encode text string
|
|
|
|
/// \param bt BufferedTransformation object for writing
|
|
|
|
/// \param str the string to encode
|
2019-10-01 23:23:29 +00:00
|
|
|
/// \param strLen the length of the string, in bytes
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \param asnTag the ASN.1 identifier
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the number of octets used for the encoding
|
2019-09-30 03:28:30 +00:00
|
|
|
/// \details DEREncodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
|
2019-09-30 03:43:56 +00:00
|
|
|
/// \since Crypto++ 8.3
|
2019-09-30 03:28:30 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const byte* str, size_t strLen, byte asnTag);
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER encode text string
|
|
|
|
/// \param bt BufferedTransformation object for writing
|
|
|
|
/// \param str the string to encode
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \param asnTag the ASN.1 identifier
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the number of octets used for the encoding
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \details DEREncodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
|
2019-09-30 03:43:56 +00:00
|
|
|
/// \since Crypto++ 8.3
|
2019-09-30 02:56:12 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag);
|
2016-04-08 05:51:21 +00:00
|
|
|
|
2019-09-30 03:28:30 +00:00
|
|
|
/// \brief DER encode text string
|
|
|
|
/// \param bt BufferedTransformation object for writing
|
|
|
|
/// \param str the string to encode
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \param asnTag the ASN.1 identifier
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the number of octets used for the encoding
|
2019-09-30 03:28:30 +00:00
|
|
|
/// \details DEREncodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
|
2019-09-30 03:43:56 +00:00
|
|
|
/// \since Crypto++ 6.0
|
2019-09-30 03:28:30 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt, const std::string &str, byte asnTag);
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER decode text string
|
|
|
|
/// \param bt BufferedTransformation object for reading
|
2019-09-30 02:56:12 +00:00
|
|
|
/// \param str the string to decode
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \param asnTag the ASN.1 identifier
|
2019-09-30 02:56:12 +00:00
|
|
|
/// \details BERDecodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
|
2019-09-30 03:43:56 +00:00
|
|
|
/// \since Crypto++ 8.3
|
2019-09-30 02:56:12 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &bt, SecByteBlock &str, byte asnTag);
|
|
|
|
|
|
|
|
/// \brief BER decode text string
|
|
|
|
/// \param bt BufferedTransformation object for reading
|
|
|
|
/// \param str the string to decode
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \param asnTag the ASN.1 identifier
|
2019-09-29 19:09:25 +00:00
|
|
|
/// \details BERDecodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
|
2019-09-30 03:43:56 +00:00
|
|
|
/// \since Crypto++ 6.0
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte asnTag);
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2019-09-30 02:56:12 +00:00
|
|
|
/// \brief DER encode date
|
|
|
|
/// \param bt BufferedTransformation object for writing
|
|
|
|
/// \param str the date to encode
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \param asnTag the ASN.1 identifier
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the number of octets used for the encoding
|
2019-09-30 02:56:12 +00:00
|
|
|
/// \details BERDecodeDate() can be used for UTC_TIME and GENERALIZED_TIME
|
2019-09-30 03:43:56 +00:00
|
|
|
/// \since Crypto++ 8.3
|
2019-09-30 02:56:12 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeDate(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag);
|
|
|
|
|
|
|
|
/// \brief BER decode date
|
|
|
|
/// \param bt BufferedTransformation object for reading
|
|
|
|
/// \param str the date to decode
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \param asnTag the ASN.1 identifier
|
2019-09-30 02:56:12 +00:00
|
|
|
/// \details BERDecodeDate() can be used for UTC_TIME and GENERALIZED_TIME
|
2019-09-30 03:43:56 +00:00
|
|
|
/// \since Crypto++ 8.3
|
2019-09-30 02:56:12 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeDate(BufferedTransformation &bt, SecByteBlock &str, byte asnTag);
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER encode bit string
|
|
|
|
/// \param bt BufferedTransformation object for writing
|
|
|
|
/// \param str the string to encode
|
|
|
|
/// \param strLen the length of the string
|
|
|
|
/// \param unusedBits the number of unused bits
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the number of octets used for the encoding
|
2019-10-05 22:25:10 +00:00
|
|
|
/// \details The caller is responsible for shifting octets if unusedBits is
|
|
|
|
/// not 0. For example, to DER encode a web server X.509 key usage, the 101b
|
|
|
|
/// bit mask is often used (digitalSignature and keyEncipherment). In this
|
|
|
|
/// case <tt>str</tt> is one octet with a value=0xa0 and unusedBits=5. The
|
|
|
|
/// value 0xa0 is <tt>101b << 5</tt>.
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeBitString(BufferedTransformation &bt, const byte *str, size_t strLen, unsigned int unusedBits=0);
|
2016-04-08 05:51:21 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER decode bit string
|
|
|
|
/// \param bt BufferedTransformation object for reading
|
|
|
|
/// \param str the decoded string
|
|
|
|
/// \param unusedBits the number of unused bits
|
2019-10-05 22:25:10 +00:00
|
|
|
/// \details The caller is responsible for shifting octets if unusedBits is
|
|
|
|
/// not 0. For example, to DER encode a web server X.509 key usage, the 101b
|
|
|
|
/// bit mask is often used (digitalSignature and keyEncipherment). In this
|
|
|
|
/// case <tt>str</tt> is one octet with a value=0xa0 and unusedBits=5. The
|
|
|
|
/// value 0xa0 is <tt>101b << 5</tt>.
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits);
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER decode and DER re-encode
|
|
|
|
/// \param bt BufferedTransformation object for writing
|
|
|
|
/// \param dest BufferedTransformation object
|
2016-04-20 23:03:46 +00:00
|
|
|
CRYPTOPP_DLL void CRYPTOPP_API DERReencode(BufferedTransformation &bt, BufferedTransformation &dest);
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2019-09-30 02:56:12 +00:00
|
|
|
/// \brief BER decode size
|
2019-09-30 07:32:09 +00:00
|
|
|
/// \param bt BufferedTransformation object for reading
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return the length of the ASN.1 value, in bytes
|
2019-09-30 07:32:09 +00:00
|
|
|
/// \details BERDecodePeekLength() determines the length of a value without
|
|
|
|
/// consuming octets in the stream. The stream must use definite length encoding.
|
|
|
|
/// If indefinite length encoding is used or an error occurs, then 0 is returned.
|
2019-09-30 03:43:56 +00:00
|
|
|
/// \since Crypto++ 8.3
|
2019-10-08 11:41:01 +00:00
|
|
|
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodePeekLength(const BufferedTransformation &bt);
|
2019-09-30 02:56:12 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Object Identifier
|
2015-11-05 06:59:46 +00:00
|
|
|
class CRYPTOPP_DLL OID
|
|
|
|
{
|
|
|
|
public:
|
2016-12-03 05:32:07 +00:00
|
|
|
virtual ~OID() {}
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Construct an OID
|
2015-11-05 06:59:46 +00:00
|
|
|
OID() {}
|
2019-10-01 23:47:47 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Construct an OID
|
|
|
|
/// \param v value to initialize the OID
|
2015-11-05 06:59:46 +00:00
|
|
|
OID(word32 v) : m_values(1, v) {}
|
2019-10-01 23:47:47 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Construct an OID
|
|
|
|
/// \param bt BufferedTransformation object
|
2019-10-01 23:47:47 +00:00
|
|
|
OID(BufferedTransformation &bt) {
|
|
|
|
BERDecode(bt);
|
|
|
|
}
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Append a value to an OID
|
|
|
|
/// \param rhs the value to append
|
2019-10-01 23:47:47 +00:00
|
|
|
inline OID & operator+=(word32 rhs) {
|
|
|
|
m_values.push_back(rhs); return *this;
|
|
|
|
}
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER encode this OID
|
|
|
|
/// \param bt BufferedTransformation object
|
2015-11-05 06:59:46 +00:00
|
|
|
void DEREncode(BufferedTransformation &bt) const;
|
2016-09-10 08:57:48 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER decode an OID
|
|
|
|
/// \param bt BufferedTransformation object
|
2015-11-05 06:59:46 +00:00
|
|
|
void BERDecode(BufferedTransformation &bt);
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER decode an OID
|
|
|
|
/// \param bt BufferedTransformation object
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \throw BERDecodeErr() if decoded value doesn't match an expected OID
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \details BERDecodeAndCheck() can be used to parse an OID and verify it matches an expected.
|
|
|
|
/// <pre>
|
|
|
|
/// BERSequenceDecoder key(bt);
|
|
|
|
/// ...
|
|
|
|
/// BERSequenceDecoder algorithm(key);
|
|
|
|
/// GetAlgorithmID().BERDecodeAndCheck(algorithm);
|
|
|
|
/// </pre>
|
2015-11-05 06:59:46 +00:00
|
|
|
void BERDecodeAndCheck(BufferedTransformation &bt) const;
|
|
|
|
|
2019-10-01 23:47:47 +00:00
|
|
|
/// \brief Determine if OID is empty
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return true if OID has 0 elements, false otherwise
|
2019-10-01 23:47:47 +00:00
|
|
|
/// \since Crypto++ 8.0
|
2018-12-24 22:17:32 +00:00
|
|
|
bool Empty() const {
|
|
|
|
return m_values.empty();
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:47:47 +00:00
|
|
|
/// \brief Retrieve OID value array
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return OID value vector
|
2019-10-01 23:47:47 +00:00
|
|
|
/// \since Crypto++ 8.0
|
2018-04-03 21:32:56 +00:00
|
|
|
const std::vector<word32>& GetValues() const {
|
|
|
|
return m_values;
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:47:47 +00:00
|
|
|
/// \brief Print an OID
|
|
|
|
/// \param out ostream object
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return ostream reference
|
2019-10-01 23:47:47 +00:00
|
|
|
/// \details Print() writes the OID in a customary format, like
|
|
|
|
/// 1.2.840.113549.1.1.11. The caller is reposnsible to convert the
|
2019-10-02 00:07:02 +00:00
|
|
|
/// OID to a friendly name, like sha256WithRSAEncryption.
|
2019-10-01 23:47:47 +00:00
|
|
|
/// \since Crypto++ 8.3
|
2019-09-29 19:09:25 +00:00
|
|
|
std::ostream& Print(std::ostream& out) const;
|
|
|
|
|
2018-04-03 21:32:56 +00:00
|
|
|
protected:
|
|
|
|
friend bool operator==(const OID &lhs, const OID &rhs);
|
|
|
|
friend bool operator!=(const OID &lhs, const OID &rhs);
|
|
|
|
friend bool operator<(const OID &lhs, const OID &rhs);
|
2019-10-01 23:47:47 +00:00
|
|
|
friend bool operator<=(const OID &lhs, const OID &rhs);
|
|
|
|
friend bool operator>=(const OID &lhs, const OID &rhs);
|
2018-04-03 21:32:56 +00:00
|
|
|
|
2015-11-05 06:59:46 +00:00
|
|
|
std::vector<word32> m_values;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void EncodeValue(BufferedTransformation &bt, word32 v);
|
|
|
|
static size_t DecodeValue(BufferedTransformation &bt, word32 &v);
|
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief ASN.1 encoded object filter
|
2015-11-05 06:59:46 +00:00
|
|
|
class EncodedObjectFilter : public Filter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
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};
|
2018-04-03 21:32:56 +00:00
|
|
|
enum State {IDENTIFIER, LENGTH, BODY, TAIL, ALL_DONE} m_state;
|
2016-04-08 05:51:21 +00:00
|
|
|
|
2016-12-03 05:32:07 +00:00
|
|
|
virtual ~EncodedObjectFilter() {}
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Construct an EncodedObjectFilter
|
|
|
|
/// \param attachment a BufferedTrasformation to attach to this object
|
|
|
|
/// \param nObjects the number of objects
|
|
|
|
/// \param flags bitwise OR of EncodedObjectFilter::Flag
|
2017-03-01 11:10:06 +00:00
|
|
|
EncodedObjectFilter(BufferedTransformation *attachment = NULLPTR, unsigned int nObjects = 1, word32 flags = 0);
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Input a byte buffer for processing
|
|
|
|
/// \param inString the byte buffer to process
|
|
|
|
/// \param length the size of the string, in bytes
|
2015-11-05 06:59:46 +00:00
|
|
|
void Put(const byte *inString, size_t length);
|
|
|
|
|
|
|
|
unsigned int GetNumberOfCompletedObjects() const {return m_nCurrentObject;}
|
|
|
|
unsigned long GetPositionOfObject(unsigned int i) const {return m_positions[i];}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BufferedTransformation & CurrentTarget();
|
|
|
|
|
|
|
|
ByteQueue m_queue;
|
2018-04-03 21:32:56 +00:00
|
|
|
std::vector<unsigned int> m_positions;
|
2015-11-05 06:59:46 +00:00
|
|
|
lword m_lengthRemaining;
|
2018-04-03 21:32:56 +00:00
|
|
|
word32 m_nObjects, m_nCurrentObject, m_level, m_flags;
|
|
|
|
byte m_id;
|
2015-11-05 06:59:46 +00:00
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER General Decoder
|
2019-07-01 17:29:46 +00:00
|
|
|
class CRYPTOPP_DLL BERGeneralDecoder : public Store
|
2015-11-05 06:59:46 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Default ASN.1 tag
|
2021-03-10 03:51:19 +00:00
|
|
|
enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
|
2019-06-04 06:49:16 +00:00
|
|
|
|
2016-12-03 05:32:07 +00:00
|
|
|
virtual ~BERGeneralDecoder();
|
|
|
|
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \details BERGeneralDecoder uses DefaultTag
|
|
|
|
explicit BERGeneralDecoder(BufferedTransformation &inQueue);
|
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
2015-11-05 06:59:46 +00:00
|
|
|
explicit BERGeneralDecoder(BufferedTransformation &inQueue, byte asnTag);
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
2015-11-05 06:59:46 +00:00
|
|
|
explicit BERGeneralDecoder(BERGeneralDecoder &inQueue, byte asnTag);
|
|
|
|
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Determine length encoding
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return true if the ASN.1 object is definite length encoded, false otherwise
|
2019-06-04 13:29:01 +00:00
|
|
|
bool IsDefiniteLength() const {
|
|
|
|
return m_definiteLength;
|
|
|
|
}
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Determine remaining length
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return number of octets that remain to be consumed
|
2019-06-04 13:29:01 +00:00
|
|
|
/// \details RemainingLength() is only valid if IsDefiniteLength()
|
|
|
|
/// returns true.
|
|
|
|
lword RemainingLength() const {
|
|
|
|
CRYPTOPP_ASSERT(m_definiteLength);
|
|
|
|
return IsDefiniteLength() ? m_length : 0;
|
|
|
|
}
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Determine end of stream
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return true if all octets have been consumed, false otherwise
|
2015-11-05 06:59:46 +00:00
|
|
|
bool EndReached() const;
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Determine next octet
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return next octet in the stream
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \details PeekByte does not consume the octet.
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \throw BERDecodeError if there are no octets remaining
|
2015-11-05 06:59:46 +00:00
|
|
|
byte PeekByte() const;
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Determine next octet
|
|
|
|
/// \details CheckByte reads the next byte in the stream and verifies
|
|
|
|
/// the octet matches b.
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \throw BERDecodeError if the next octet is not b
|
2015-11-05 06:59:46 +00:00
|
|
|
void CheckByte(byte b);
|
|
|
|
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Transfer bytes to another BufferedTransformation
|
|
|
|
/// \param target the destination BufferedTransformation
|
|
|
|
/// \param transferBytes the number of bytes to transfer
|
|
|
|
/// \param channel the channel on which the transfer should occur
|
|
|
|
/// \param blocking specifies whether the object should block when
|
|
|
|
/// processing input
|
|
|
|
/// \return the number of bytes that remain in the transfer block
|
|
|
|
/// (i.e., bytes not transferred)
|
|
|
|
/// \details TransferTo2() removes bytes and moves
|
|
|
|
/// them to the destination. Transfer begins at the index position
|
|
|
|
/// in the current stream, and not from an absolute position in the
|
|
|
|
/// stream.
|
|
|
|
/// \details transferBytes is an \a IN and \a OUT parameter. When
|
|
|
|
/// the call is made, transferBytes is the requested size of the
|
|
|
|
/// transfer. When the call returns, transferBytes is the number
|
|
|
|
/// of bytes that were transferred.
|
2015-11-05 06:59:46 +00:00
|
|
|
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Copy bytes to another BufferedTransformation
|
|
|
|
/// \param target the destination BufferedTransformation
|
|
|
|
/// \param begin the 0-based index of the first byte to copy in
|
|
|
|
/// the stream
|
|
|
|
/// \param end the 0-based index of the last byte to copy in
|
|
|
|
/// the stream
|
|
|
|
/// \param channel the channel on which the transfer should occur
|
|
|
|
/// \param blocking specifies whether the object should block when
|
|
|
|
/// processing input
|
|
|
|
/// \return the number of bytes that remain in the copy block
|
|
|
|
/// (i.e., bytes not copied)
|
|
|
|
/// \details CopyRangeTo2 copies bytes to the
|
|
|
|
/// destination. The bytes are not removed from this object. Copying
|
|
|
|
/// begins at the index position in the current stream, and not from
|
|
|
|
/// an absolute position in the stream.
|
|
|
|
/// \details begin is an \a IN and \a OUT parameter. When the call is
|
|
|
|
/// made, begin is the starting position of the copy. When the call
|
|
|
|
/// returns, begin is the position of the first byte that was \a not
|
|
|
|
/// copied (which may be different than end). begin can be used for
|
|
|
|
/// subsequent calls to CopyRangeTo2().
|
2015-11-05 06:59:46 +00:00
|
|
|
size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
|
|
|
|
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Signals the end of messages to the object
|
|
|
|
/// \details Call this to denote end of sequence
|
2015-11-05 06:59:46 +00:00
|
|
|
void MessageEnd();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BufferedTransformation &m_inQueue;
|
|
|
|
lword m_length;
|
2018-04-03 21:32:56 +00:00
|
|
|
bool m_finished, m_definiteLength;
|
2015-11-05 06:59:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void Init(byte asnTag);
|
|
|
|
void StoreInitialize(const NameValuePairs ¶meters)
|
2016-09-16 15:27:15 +00:00
|
|
|
{CRYPTOPP_UNUSED(parameters); CRYPTOPP_ASSERT(false);}
|
2015-11-05 06:59:46 +00:00
|
|
|
lword ReduceLength(lword delta);
|
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER General Encoder
|
2019-07-01 17:29:46 +00:00
|
|
|
class CRYPTOPP_DLL DERGeneralEncoder : public ByteQueue
|
2015-11-05 06:59:46 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Default ASN.1 tag
|
2021-03-10 03:51:19 +00:00
|
|
|
enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
|
2019-06-04 06:49:16 +00:00
|
|
|
|
2016-12-03 05:32:07 +00:00
|
|
|
virtual ~DERGeneralEncoder();
|
|
|
|
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \details DERGeneralEncoder uses DefaultTag
|
|
|
|
explicit DERGeneralEncoder(BufferedTransformation &outQueue);
|
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
|
|
|
explicit DERGeneralEncoder(BufferedTransformation &outQueue, byte asnTag);
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
|
|
|
explicit DERGeneralEncoder(DERGeneralEncoder &outQueue, byte asnTag);
|
|
|
|
|
|
|
|
/// \brief Signals the end of messages to the object
|
|
|
|
/// \details Call this to denote end of sequence
|
2015-11-05 06:59:46 +00:00
|
|
|
void MessageEnd();
|
|
|
|
|
|
|
|
private:
|
|
|
|
BufferedTransformation &m_outQueue;
|
|
|
|
byte m_asnTag;
|
2018-04-03 21:32:56 +00:00
|
|
|
bool m_finished;
|
2015-11-05 06:59:46 +00:00
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER Sequence Decoder
|
2015-11-05 06:59:46 +00:00
|
|
|
class CRYPTOPP_DLL BERSequenceDecoder : public BERGeneralDecoder
|
|
|
|
{
|
|
|
|
public:
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Default ASN.1 tag
|
2021-03-10 03:51:19 +00:00
|
|
|
enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \details BERSequenceDecoder uses DefaultTag
|
|
|
|
explicit BERSequenceDecoder(BufferedTransformation &inQueue)
|
|
|
|
: BERGeneralDecoder(inQueue, DefaultTag) {}
|
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
|
|
|
explicit BERSequenceDecoder(BufferedTransformation &inQueue, byte asnTag)
|
2015-11-05 06:59:46 +00:00
|
|
|
: BERGeneralDecoder(inQueue, asnTag) {}
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \details BERSequenceDecoder uses DefaultTag
|
|
|
|
explicit BERSequenceDecoder(BERSequenceDecoder &inQueue)
|
|
|
|
: BERGeneralDecoder(inQueue, DefaultTag) {}
|
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
|
|
|
explicit BERSequenceDecoder(BERSequenceDecoder &inQueue, byte asnTag)
|
2015-11-05 06:59:46 +00:00
|
|
|
: BERGeneralDecoder(inQueue, asnTag) {}
|
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER Sequence Encoder
|
2015-11-05 06:59:46 +00:00
|
|
|
class CRYPTOPP_DLL DERSequenceEncoder : public DERGeneralEncoder
|
|
|
|
{
|
|
|
|
public:
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Default ASN.1 tag
|
2021-03-10 03:51:19 +00:00
|
|
|
enum {DefaultTag = SEQUENCE | EnumToInt(CONSTRUCTED)};
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \details DERSequenceEncoder uses DefaultTag
|
|
|
|
explicit DERSequenceEncoder(BufferedTransformation &outQueue)
|
|
|
|
: DERGeneralEncoder(outQueue, DefaultTag) {}
|
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
|
|
|
explicit DERSequenceEncoder(BufferedTransformation &outQueue, byte asnTag)
|
2015-11-05 06:59:46 +00:00
|
|
|
: DERGeneralEncoder(outQueue, asnTag) {}
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \details DERSequenceEncoder uses DefaultTag
|
|
|
|
explicit DERSequenceEncoder(DERSequenceEncoder &outQueue)
|
|
|
|
: DERGeneralEncoder(outQueue, DefaultTag) {}
|
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
|
|
|
explicit DERSequenceEncoder(DERSequenceEncoder &outQueue, byte asnTag)
|
2015-11-05 06:59:46 +00:00
|
|
|
: DERGeneralEncoder(outQueue, asnTag) {}
|
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER Set Decoder
|
2015-11-05 06:59:46 +00:00
|
|
|
class CRYPTOPP_DLL BERSetDecoder : public BERGeneralDecoder
|
|
|
|
{
|
|
|
|
public:
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Default ASN.1 tag
|
2021-03-10 03:51:19 +00:00
|
|
|
enum {DefaultTag = SET | EnumToInt(CONSTRUCTED)};
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \details BERSetDecoder uses DefaultTag
|
|
|
|
explicit BERSetDecoder(BufferedTransformation &inQueue)
|
|
|
|
: BERGeneralDecoder(inQueue, DefaultTag) {}
|
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
|
|
|
explicit BERSetDecoder(BufferedTransformation &inQueue, byte asnTag)
|
2015-11-05 06:59:46 +00:00
|
|
|
: BERGeneralDecoder(inQueue, asnTag) {}
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \details BERSetDecoder uses DefaultTag
|
|
|
|
explicit BERSetDecoder(BERSetDecoder &inQueue)
|
2021-03-10 02:59:35 +00:00
|
|
|
: BERGeneralDecoder(inQueue, DefaultTag) {}
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 decoder
|
|
|
|
/// \param inQueue input byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
|
|
|
explicit BERSetDecoder(BERSetDecoder &inQueue, byte asnTag)
|
2015-11-05 06:59:46 +00:00
|
|
|
: BERGeneralDecoder(inQueue, asnTag) {}
|
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER Set Encoder
|
2015-11-05 06:59:46 +00:00
|
|
|
class CRYPTOPP_DLL DERSetEncoder : public DERGeneralEncoder
|
|
|
|
{
|
|
|
|
public:
|
2019-06-04 06:49:16 +00:00
|
|
|
/// \brief Default ASN.1 tag
|
2021-03-10 03:51:19 +00:00
|
|
|
enum {DefaultTag = SET | EnumToInt(CONSTRUCTED)};
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \details DERSetEncoder uses DefaultTag
|
|
|
|
explicit DERSetEncoder(BufferedTransformation &outQueue)
|
|
|
|
: DERGeneralEncoder(outQueue, DefaultTag) {}
|
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
|
|
|
explicit DERSetEncoder(BufferedTransformation &outQueue, byte asnTag)
|
2015-11-05 06:59:46 +00:00
|
|
|
: DERGeneralEncoder(outQueue, asnTag) {}
|
2019-06-04 06:49:16 +00:00
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \details DERSetEncoder uses DefaultTag
|
|
|
|
explicit DERSetEncoder(DERSetEncoder &outQueue)
|
|
|
|
: DERGeneralEncoder(outQueue, DefaultTag) {}
|
|
|
|
|
|
|
|
/// \brief Construct an ASN.1 encoder
|
|
|
|
/// \param outQueue output byte queue
|
|
|
|
/// \param asnTag ASN.1 tag
|
|
|
|
explicit DERSetEncoder(DERSetEncoder &outQueue, byte asnTag)
|
2015-11-05 06:59:46 +00:00
|
|
|
: DERGeneralEncoder(outQueue, asnTag) {}
|
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Optional data encoder and decoder
|
|
|
|
/// \tparam T class or type
|
2015-11-05 06:59:46 +00:00
|
|
|
template <class T>
|
|
|
|
class ASNOptional : public member_ptr<T>
|
|
|
|
{
|
|
|
|
public:
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER decode optional data
|
|
|
|
/// \param seqDecoder sequence with the optional ASN.1 data
|
|
|
|
/// \param tag ASN.1 tag to match as optional data
|
|
|
|
/// \param mask the mask to apply when matching the tag
|
|
|
|
/// \sa ASNTag and ASNIdFlag
|
2015-11-05 06:59:46 +00:00
|
|
|
void BERDecode(BERSequenceDecoder &seqDecoder, byte tag, byte mask = ~CONSTRUCTED)
|
|
|
|
{
|
|
|
|
byte b;
|
|
|
|
if (seqDecoder.Peek(b) && (b & mask) == tag)
|
|
|
|
reset(new T(seqDecoder));
|
|
|
|
}
|
2016-04-08 08:23:42 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER encode optional data
|
|
|
|
/// \param out BufferedTransformation object
|
2015-11-05 06:59:46 +00:00
|
|
|
void DEREncode(BufferedTransformation &out)
|
|
|
|
{
|
2017-03-01 11:10:06 +00:00
|
|
|
if (this->get() != NULLPTR)
|
2015-11-05 06:59:46 +00:00
|
|
|
this->get()->DEREncode(out);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Encode and decode ASN.1 objects with additional information
|
|
|
|
/// \tparam BASE base class or type
|
|
|
|
/// \details Encodes and decodes public keys, private keys and group
|
|
|
|
/// parameters with OID identifying the algorithm or scheme.
|
2015-11-05 06:59:46 +00:00
|
|
|
template <class BASE>
|
|
|
|
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ASN1CryptoMaterial : public ASN1Object, public BASE
|
|
|
|
{
|
|
|
|
public:
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER encode ASN.1 object
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \details Save() will write the OID associated with algorithm or scheme.
|
|
|
|
/// In the case of public and private keys, this function writes the
|
2021-07-04 03:25:03 +00:00
|
|
|
/// subjectPublicKeyInfo and privateKeyInfo parts.
|
2015-11-05 06:59:46 +00:00
|
|
|
void Save(BufferedTransformation &bt) const
|
|
|
|
{BEREncode(bt);}
|
2016-04-08 08:23:42 +00:00
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER decode ASN.1 object
|
|
|
|
/// \param bt BufferedTransformation object
|
2015-11-05 06:59:46 +00:00
|
|
|
void Load(BufferedTransformation &bt)
|
|
|
|
{BERDecode(bt);}
|
|
|
|
};
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Encodes and decodes subjectPublicKeyInfo
|
2015-11-05 06:59:46 +00:00
|
|
|
class CRYPTOPP_DLL X509PublicKey : public ASN1CryptoMaterial<PublicKey>
|
|
|
|
{
|
|
|
|
public:
|
2016-12-03 05:32:07 +00:00
|
|
|
virtual ~X509PublicKey() {}
|
|
|
|
|
2015-11-05 06:59:46 +00:00
|
|
|
void BERDecode(BufferedTransformation &bt);
|
|
|
|
void DEREncode(BufferedTransformation &bt) const;
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Retrieves the OID of the algorithm
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return OID of the algorithm
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual OID GetAlgorithmID() const =0;
|
2019-09-28 07:57:21 +00:00
|
|
|
|
|
|
|
/// \brief Decode algorithm parameters
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \sa BERDecodePublicKey, <A HREF="http://www.ietf.org/rfc/rfc2459.txt">RFC
|
|
|
|
/// 2459, section 7.3.1</A>
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
|
|
|
|
{BERDecodeNull(bt); return false;}
|
2019-09-28 07:57:21 +00:00
|
|
|
|
|
|
|
/// \brief Encode algorithm parameters
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \sa DEREncodePublicKey, <A HREF="http://www.ietf.org/rfc/rfc2459.txt">RFC
|
|
|
|
/// 2459, section 7.3.1</A>
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
|
2019-09-28 07:57:21 +00:00
|
|
|
{DEREncodeNull(bt); return false;}
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2019-09-28 07:57:21 +00:00
|
|
|
/// \brief Decode subjectPublicKey part of subjectPublicKeyInfo
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \param parametersPresent flag indicating if algorithm parameters are present
|
|
|
|
/// \param size number of octets to read for the parameters, in bytes
|
|
|
|
/// \details BERDecodePublicKey() the decodes subjectPublicKey part of
|
|
|
|
/// subjectPublicKeyInfo, without the BIT STRING header.
|
|
|
|
/// \details When <tt>parametersPresent = true</tt> then BERDecodePublicKey() calls
|
|
|
|
/// BERDecodeAlgorithmParameters() to parse algorithm parameters.
|
|
|
|
/// \sa BERDecodeAlgorithmParameters
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0;
|
2019-09-28 07:57:21 +00:00
|
|
|
|
|
|
|
/// \brief Encode subjectPublicKey part of subjectPublicKeyInfo
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \details DEREncodePublicKey() encodes the subjectPublicKey part of
|
|
|
|
/// subjectPublicKeyInfo, without the BIT STRING header.
|
|
|
|
/// \sa DEREncodeAlgorithmParameters
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual void DEREncodePublicKey(BufferedTransformation &bt) const =0;
|
|
|
|
};
|
|
|
|
|
2018-12-24 22:17:32 +00:00
|
|
|
/// \brief Encodes and Decodes privateKeyInfo
|
2015-11-05 06:59:46 +00:00
|
|
|
class CRYPTOPP_DLL PKCS8PrivateKey : public ASN1CryptoMaterial<PrivateKey>
|
|
|
|
{
|
|
|
|
public:
|
2016-12-03 05:32:07 +00:00
|
|
|
virtual ~PKCS8PrivateKey() {}
|
|
|
|
|
2015-11-05 06:59:46 +00:00
|
|
|
void BERDecode(BufferedTransformation &bt);
|
|
|
|
void DEREncode(BufferedTransformation &bt) const;
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Retrieves the OID of the algorithm
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return OID of the algorithm
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual OID GetAlgorithmID() const =0;
|
2019-09-28 07:57:21 +00:00
|
|
|
|
|
|
|
/// \brief Decode optional parameters
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \sa BERDecodePrivateKey, <A HREF="http://www.ietf.org/rfc/rfc2459.txt">RFC
|
|
|
|
/// 2459, section 7.3.1</A>
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual bool BERDecodeAlgorithmParameters(BufferedTransformation &bt)
|
|
|
|
{BERDecodeNull(bt); return false;}
|
2019-09-28 07:57:21 +00:00
|
|
|
|
|
|
|
/// \brief Encode optional parameters
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \sa DEREncodePrivateKey, <A HREF="http://www.ietf.org/rfc/rfc2459.txt">RFC
|
|
|
|
/// 2459, section 7.3.1</A>
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const
|
2019-09-28 07:57:21 +00:00
|
|
|
{DEREncodeNull(bt); return false;}
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2019-09-28 07:57:21 +00:00
|
|
|
/// \brief Decode privateKey part of privateKeyInfo
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \param parametersPresent flag indicating if algorithm parameters are present
|
|
|
|
/// \param size number of octets to read for the parameters, in bytes
|
|
|
|
/// \details BERDecodePrivateKey() the decodes privateKey part of privateKeyInfo,
|
|
|
|
/// without the OCTET STRING header.
|
|
|
|
/// \details When <tt>parametersPresent = true</tt> then BERDecodePrivateKey() calls
|
|
|
|
/// BERDecodeAlgorithmParameters() to parse algorithm parameters.
|
|
|
|
/// \sa BERDecodeAlgorithmParameters
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size) =0;
|
2019-09-28 07:57:21 +00:00
|
|
|
|
|
|
|
/// \brief Encode privateKey part of privateKeyInfo
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \details DEREncodePrivateKey() encodes the privateKey part of privateKeyInfo,
|
|
|
|
/// without the OCTET STRING header.
|
|
|
|
/// \sa DEREncodeAlgorithmParameters
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual void DEREncodePrivateKey(BufferedTransformation &bt) const =0;
|
|
|
|
|
2019-09-28 07:57:21 +00:00
|
|
|
/// \brief Decode optional attributes
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \details BERDecodeOptionalAttributes() decodes optional attributes including
|
|
|
|
/// context-specific tag.
|
|
|
|
/// \sa BERDecodeAlgorithmParameters, DEREncodeOptionalAttributes
|
|
|
|
/// \note default implementation stores attributes to be output using
|
|
|
|
/// DEREncodeOptionalAttributes
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual void BERDecodeOptionalAttributes(BufferedTransformation &bt);
|
2019-09-28 07:57:21 +00:00
|
|
|
|
|
|
|
/// \brief Encode optional attributes
|
|
|
|
/// \param bt BufferedTransformation object
|
|
|
|
/// \details DEREncodeOptionalAttributes() encodes optional attributes including
|
|
|
|
/// context-specific tag.
|
|
|
|
/// \sa BERDecodeAlgorithmParameters
|
2015-11-05 06:59:46 +00:00
|
|
|
virtual void DEREncodeOptionalAttributes(BufferedTransformation &bt) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ByteQueue m_optionalAttributes;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ********************************************************
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief DER Encode unsigned value
|
|
|
|
/// \tparam T class or type
|
|
|
|
/// \param out BufferedTransformation object
|
|
|
|
/// \param w unsigned value to encode
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \param asnTag the ASN.1 identifier
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \details DEREncodeUnsigned() can be used with INTEGER, BOOLEAN, and ENUM
|
2015-11-05 06:59:46 +00:00
|
|
|
template <class T>
|
|
|
|
size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag = INTEGER)
|
|
|
|
{
|
|
|
|
byte buf[sizeof(w)+1];
|
|
|
|
unsigned int bc;
|
|
|
|
if (asnTag == BOOLEAN)
|
|
|
|
{
|
|
|
|
buf[sizeof(w)] = w ? 0xff : 0;
|
|
|
|
bc = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf[0] = 0;
|
|
|
|
for (unsigned int i=0; i<sizeof(w); i++)
|
|
|
|
buf[i+1] = byte(w >> (sizeof(w)-1-i)*8);
|
|
|
|
bc = sizeof(w);
|
|
|
|
while (bc > 1 && buf[sizeof(w)+1-bc] == 0)
|
|
|
|
--bc;
|
|
|
|
if (buf[sizeof(w)+1-bc] & 0x80)
|
|
|
|
++bc;
|
|
|
|
}
|
|
|
|
out.Put(asnTag);
|
|
|
|
size_t lengthBytes = DERLengthEncode(out, bc);
|
|
|
|
out.Put(buf+sizeof(w)+1-bc, bc);
|
|
|
|
return 1+lengthBytes+bc;
|
|
|
|
}
|
|
|
|
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief BER Decode unsigned value
|
|
|
|
/// \tparam T fundamental C++ type
|
|
|
|
/// \param in BufferedTransformation object
|
|
|
|
/// \param w the decoded value
|
2019-10-28 19:33:36 +00:00
|
|
|
/// \param asnTag the ASN.1 identifier
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \param minValue the minimum expected value
|
|
|
|
/// \param maxValue the maximum expected value
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \throw BERDecodeErr() if the value cannot be parsed or the decoded value is not within range.
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \details DEREncodeUnsigned() can be used with INTEGER, BOOLEAN, and ENUM
|
2015-11-05 06:59:46 +00:00
|
|
|
template <class T>
|
|
|
|
void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag = INTEGER,
|
2016-12-24 09:55:21 +00:00
|
|
|
T minValue = 0, T maxValue = T(0xffffffff))
|
2015-11-05 06:59:46 +00:00
|
|
|
{
|
|
|
|
byte b;
|
|
|
|
if (!in.Get(b) || b != asnTag)
|
|
|
|
BERDecodeError();
|
|
|
|
|
|
|
|
size_t bc;
|
2015-11-18 20:32:28 +00:00
|
|
|
bool definite = BERLengthDecode(in, bc);
|
|
|
|
if (!definite)
|
2016-12-14 12:19:01 +00:00
|
|
|
BERDecodeError();
|
2016-12-24 09:55:21 +00:00
|
|
|
if (bc > in.MaxRetrievable()) // Issue 346
|
|
|
|
BERDecodeError();
|
|
|
|
if (asnTag == BOOLEAN && bc != 1) // X.690, 8.2.1
|
|
|
|
BERDecodeError();
|
|
|
|
if ((asnTag == INTEGER || asnTag == ENUMERATED) && bc == 0) // X.690, 8.3.1 and 8.4
|
2015-11-18 20:32:28 +00:00
|
|
|
BERDecodeError();
|
2015-11-05 06:59:46 +00:00
|
|
|
|
|
|
|
SecByteBlock buf(bc);
|
|
|
|
|
|
|
|
if (bc != in.Get(buf, bc))
|
|
|
|
BERDecodeError();
|
|
|
|
|
2016-12-24 09:55:21 +00:00
|
|
|
// This consumes leading 0 octets. According to X.690, 8.3.2, it could be non-conforming behavior.
|
|
|
|
// X.690, 8.3.2 says "the bits of the first octet and bit 8 of the second octet ... (a) shall
|
|
|
|
// not all be ones and (b) shall not all be zeros ... These rules ensure that an integer value
|
|
|
|
// is always encoded in the smallest possible number of octet".
|
|
|
|
// We invented AER (Alternate Encoding Rules), which is more relaxed than BER, CER, and DER.
|
2015-11-05 06:59:46 +00:00
|
|
|
const byte *ptr = buf;
|
|
|
|
while (bc > sizeof(w) && *ptr == 0)
|
|
|
|
{
|
|
|
|
bc--;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
if (bc > sizeof(w))
|
|
|
|
BERDecodeError();
|
|
|
|
|
|
|
|
w = 0;
|
|
|
|
for (unsigned int i=0; i<bc; i++)
|
|
|
|
w = (w << 8) | ptr[i];
|
|
|
|
|
|
|
|
if (w < minValue || w > maxValue)
|
|
|
|
BERDecodeError();
|
|
|
|
}
|
|
|
|
|
2016-04-08 08:23:42 +00:00
|
|
|
#ifdef CRYPTOPP_DOXYGEN_PROCESSING
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Compare two OIDs for equality
|
|
|
|
/// \param lhs the first OID
|
|
|
|
/// \param rhs the second OID
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return true if the OIDs are equal, false otherwise
|
2016-04-08 08:23:42 +00:00
|
|
|
inline bool operator==(const OID &lhs, const OID &rhs);
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Compare two OIDs for inequality
|
|
|
|
/// \param lhs the first OID
|
|
|
|
/// \param rhs the second OID
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return true if the OIDs are not equal, false otherwise
|
2016-04-08 08:23:42 +00:00
|
|
|
inline bool operator!=(const OID &lhs, const OID &rhs);
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Compare two OIDs for ordering
|
|
|
|
/// \param lhs the first OID
|
|
|
|
/// \param rhs the second OID
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return true if the first OID is less than the second OID, false otherwise
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \details operator<() calls std::lexicographical_compare() on each element in the array of values.
|
2016-04-08 08:23:42 +00:00
|
|
|
inline bool operator<(const OID &lhs, const OID &rhs);
|
2019-10-01 06:59:27 +00:00
|
|
|
/// \brief Compare two OIDs for ordering
|
|
|
|
/// \param lhs the first OID
|
|
|
|
/// \param rhs the second OID
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return true if the first OID is less than or equal to the second OID, false otherwise
|
2019-10-01 06:59:27 +00:00
|
|
|
/// \details operator<=() is implemented in terms of operator==() and operator<().
|
2019-10-01 23:47:47 +00:00
|
|
|
/// \since Crypto++ 8.3
|
2019-10-02 00:07:02 +00:00
|
|
|
inline bool operator<=(const OID &lhs, const OID &rhs);
|
2019-10-01 06:59:27 +00:00
|
|
|
/// \brief Compare two OIDs for ordering
|
|
|
|
/// \param lhs the first OID
|
|
|
|
/// \param rhs the second OID
|
2020-12-08 04:35:10 +00:00
|
|
|
/// \return true if the first OID is greater than or equal to the second OID, false otherwise
|
2019-10-01 06:59:27 +00:00
|
|
|
/// \details operator>=() is implemented in terms of operator<().
|
2019-10-01 23:47:47 +00:00
|
|
|
/// \since Crypto++ 8.3
|
2019-10-02 00:07:02 +00:00
|
|
|
inline bool operator>=(const OID &lhs, const OID &rhs);
|
2017-11-29 15:54:33 +00:00
|
|
|
/// \brief Append a value to an OID
|
|
|
|
/// \param lhs the OID
|
|
|
|
/// \param rhs the value to append
|
2016-04-08 08:23:42 +00:00
|
|
|
inline OID operator+(const OID &lhs, unsigned long rhs);
|
2019-09-30 02:56:12 +00:00
|
|
|
/// \brief Print a OID value
|
|
|
|
/// \param out the output stream
|
|
|
|
/// \param oid the OID
|
|
|
|
inline std::ostream& operator<<(std::ostream& out, const OID &oid)
|
|
|
|
{ return oid.Print(out); }
|
2016-04-08 08:23:42 +00:00
|
|
|
#else
|
2015-11-05 06:59:46 +00:00
|
|
|
inline bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
|
|
|
|
{return lhs.m_values == rhs.m_values;}
|
|
|
|
inline bool operator!=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
|
|
|
|
{return lhs.m_values != rhs.m_values;}
|
|
|
|
inline bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
|
|
|
|
{return std::lexicographical_compare(lhs.m_values.begin(), lhs.m_values.end(), rhs.m_values.begin(), rhs.m_values.end());}
|
2019-10-01 06:09:43 +00:00
|
|
|
inline bool operator<=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
|
|
|
|
{return lhs<rhs || lhs==rhs;}
|
|
|
|
inline bool operator>=(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
|
|
|
|
{return ! (lhs<rhs);}
|
2015-11-05 06:59:46 +00:00
|
|
|
inline ::CryptoPP::OID operator+(const ::CryptoPP::OID &lhs, unsigned long rhs)
|
|
|
|
{return ::CryptoPP::OID(lhs)+=rhs;}
|
2019-09-29 19:09:25 +00:00
|
|
|
inline std::ostream& operator<<(std::ostream& out, const OID &oid)
|
|
|
|
{ return oid.Print(out); }
|
2016-04-08 08:23:42 +00:00
|
|
|
#endif
|
2015-11-05 06:59:46 +00:00
|
|
|
|
|
|
|
NAMESPACE_END
|
|
|
|
|
2016-12-02 19:47:31 +00:00
|
|
|
// Issue 340
|
|
|
|
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
|
|
|
|
# pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2015-11-05 06:59:46 +00:00
|
|
|
#endif
|