00001
00002
00003
00004
00005
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
00018
00019 enum ASN1_Tag {
00020 UNIVERSAL = 0x00,
00021 APPLICATION = 0x40,
00022 CONTEXT_SPECIFIC = 0x80,
00023 PRIVATE = 0xC0,
00024
00025 CONSTRUCTED = 0x20,
00026
00027 EOC = 0x00,
00028 BOOLEAN = 0x01,
00029 INTEGER = 0x02,
00030 BIT_STRING = 0x03,
00031 OCTET_STRING = 0x04,
00032 NULL_TAG = 0x05,
00033 OBJECT_ID = 0x06,
00034 ENUMERATED = 0x0A,
00035 SEQUENCE = 0x10,
00036 SET = 0x11,
00037
00038 UTF8_STRING = 0x0C,
00039 NUMERIC_STRING = 0x12,
00040 PRINTABLE_STRING = 0x13,
00041 T61_STRING = 0x14,
00042 IA5_STRING = 0x16,
00043 VISIBLE_STRING = 0x1A,
00044 BMP_STRING = 0x1E,
00045
00046 UTC_TIME = 0x17,
00047 GENERALIZED_TIME = 0x18,
00048
00049 NO_OBJECT = 0xFF00,
00050 DIRECTORY_STRING = 0xFF01
00051 };
00052
00053
00054
00055
00056 class BOTAN_DLL ASN1_Object
00057 {
00058 public:
00059
00060
00061
00062
00063 virtual void encode_into(class DER_Encoder& to) const = 0;
00064
00065
00066
00067
00068
00069 virtual void decode_from(class BER_Decoder& from) = 0;
00070
00071 virtual ~ASN1_Object() {}
00072 };
00073
00074
00075
00076
00077 class BOTAN_DLL BER_Object
00078 {
00079 public:
00080 void assert_is_a(ASN1_Tag, ASN1_Tag);
00081
00082 ASN1_Tag type_tag, class_tag;
00083 SecureVector<byte> value;
00084 };
00085
00086
00087
00088
00089 class DataSource;
00090
00091 namespace ASN1 {
00092
00093 SecureVector<byte> put_in_sequence(const MemoryRegion<byte>& val);
00094 std::string to_string(const BER_Object& obj);
00095
00096
00097
00098
00099
00100 bool maybe_BER(DataSource& src);
00101
00102 }
00103
00104
00105
00106
00107 struct BOTAN_DLL BER_Decoding_Error : public Decoding_Error
00108 {
00109 BER_Decoding_Error(const std::string&);
00110 };
00111
00112
00113
00114
00115 struct BOTAN_DLL BER_Bad_Tag : public BER_Decoding_Error
00116 {
00117 BER_Bad_Tag(const std::string&, ASN1_Tag);
00118 BER_Bad_Tag(const std::string&, ASN1_Tag, ASN1_Tag);
00119 };
00120
00121 }
00122
00123 #endif