Botan
1.11.15
|
00001 /* 00002 * ASN.1 Internals 00003 * (C) 1999-2007 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_ASN1_H__ 00009 #define BOTAN_ASN1_H__ 00010 00011 #include <botan/secmem.h> 00012 #include <botan/exceptn.h> 00013 00014 namespace Botan { 00015 00016 /** 00017 * ASN.1 Type and Class Tags 00018 */ 00019 enum ASN1_Tag { 00020 UNIVERSAL = 0x00, 00021 APPLICATION = 0x40, 00022 CONTEXT_SPECIFIC = 0x80, 00023 00024 CONSTRUCTED = 0x20, 00025 00026 PRIVATE = CONSTRUCTED | CONTEXT_SPECIFIC, 00027 00028 EOC = 0x00, 00029 BOOLEAN = 0x01, 00030 INTEGER = 0x02, 00031 BIT_STRING = 0x03, 00032 OCTET_STRING = 0x04, 00033 NULL_TAG = 0x05, 00034 OBJECT_ID = 0x06, 00035 ENUMERATED = 0x0A, 00036 SEQUENCE = 0x10, 00037 SET = 0x11, 00038 00039 UTF8_STRING = 0x0C, 00040 NUMERIC_STRING = 0x12, 00041 PRINTABLE_STRING = 0x13, 00042 T61_STRING = 0x14, 00043 IA5_STRING = 0x16, 00044 VISIBLE_STRING = 0x1A, 00045 BMP_STRING = 0x1E, 00046 00047 UTC_TIME = 0x17, 00048 GENERALIZED_TIME = 0x18, 00049 00050 NO_OBJECT = 0xFF00, 00051 DIRECTORY_STRING = 0xFF01 00052 }; 00053 00054 /** 00055 * Basic ASN.1 Object Interface 00056 */ 00057 class BOTAN_DLL ASN1_Object 00058 { 00059 public: 00060 /** 00061 * Encode whatever this object is into to 00062 * @param to the DER_Encoder that will be written to 00063 */ 00064 virtual void encode_into(class DER_Encoder& to) const = 0; 00065 00066 /** 00067 * Decode whatever this object is from from 00068 * @param from the BER_Decoder that will be read from 00069 */ 00070 virtual void decode_from(class BER_Decoder& from) = 0; 00071 00072 virtual ~ASN1_Object() {} 00073 }; 00074 00075 /** 00076 * BER Encoded Object 00077 */ 00078 class BOTAN_DLL BER_Object 00079 { 00080 public: 00081 void assert_is_a(ASN1_Tag, ASN1_Tag); 00082 00083 ASN1_Tag type_tag, class_tag; 00084 secure_vector<byte> value; 00085 }; 00086 00087 /* 00088 * ASN.1 Utility Functions 00089 */ 00090 class DataSource; 00091 00092 namespace ASN1 { 00093 00094 std::vector<byte> put_in_sequence(const std::vector<byte>& val); 00095 std::string to_string(const BER_Object& obj); 00096 00097 /** 00098 * Heuristics tests; is this object possibly BER? 00099 * @param src a data source that will be peeked at but not modified 00100 */ 00101 bool maybe_BER(DataSource& src); 00102 00103 } 00104 00105 /** 00106 * General BER Decoding Error Exception 00107 */ 00108 struct BOTAN_DLL BER_Decoding_Error : public Decoding_Error 00109 { 00110 BER_Decoding_Error(const std::string&); 00111 }; 00112 00113 /** 00114 * Exception For Incorrect BER Taggings 00115 */ 00116 struct BOTAN_DLL BER_Bad_Tag : public BER_Decoding_Error 00117 { 00118 BER_Bad_Tag(const std::string& msg, ASN1_Tag tag); 00119 BER_Bad_Tag(const std::string& msg, ASN1_Tag tag1, ASN1_Tag tag2); 00120 }; 00121 00122 } 00123 00124 #endif