Botan  1.11.15
src/lib/asn1/asn1_oid.h
Go to the documentation of this file.
00001 /*
00002 * ASN.1 OID
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_OID_H__
00009 #define BOTAN_ASN1_OID_H__
00010 
00011 #include <botan/asn1_obj.h>
00012 #include <string>
00013 #include <vector>
00014 
00015 namespace Botan {
00016 
00017 /**
00018 * This class represents ASN.1 object identifiers.
00019 */
00020 class BOTAN_DLL OID : public ASN1_Object
00021    {
00022    public:
00023       void encode_into(class DER_Encoder&) const;
00024       void decode_from(class BER_Decoder&);
00025 
00026       /**
00027       * Find out whether this OID is empty
00028       * @return true is no OID value is set
00029       */
00030       bool empty() const { return id.size() == 0; }
00031 
00032       /**
00033       * Get this OID as list (vector) of its components.
00034       * @return vector representing this OID
00035       */
00036       const std::vector<u32bit>& get_id() const { return id; }
00037 
00038       /**
00039       * Get this OID as a string
00040       * @return string representing this OID
00041       */
00042       std::string as_string() const;
00043 
00044       /**
00045       * Compare two OIDs.
00046       * @return true if they are equal, false otherwise
00047       */
00048       bool operator==(const OID&) const;
00049 
00050       /**
00051       * Reset this instance to an empty OID.
00052       */
00053       void clear();
00054 
00055       /**
00056       * Add a component to this OID.
00057       * @param new_comp the new component to add to the end of this OID
00058       * @return reference to *this
00059       */
00060       OID& operator+=(u32bit new_comp);
00061 
00062       /**
00063       * Construct an OID from a string.
00064       * @param str a string in the form "a.b.c" etc., where a,b,c are numbers
00065       */
00066       OID(const std::string& str = "");
00067    private:
00068       std::vector<u32bit> id;
00069    };
00070 
00071 /**
00072 * Append another component onto the OID.
00073 * @param oid the OID to add the new component to
00074 * @param new_comp the new component to add
00075 */
00076 OID BOTAN_DLL operator+(const OID& oid, u32bit new_comp);
00077 
00078 /**
00079 * Compare two OIDs.
00080 * @param a the first OID
00081 * @param b the second OID
00082 * @return true if a is not equal to b
00083 */
00084 bool BOTAN_DLL operator!=(const OID& a, const OID& b);
00085 
00086 /**
00087 * Compare two OIDs.
00088 * @param a the first OID
00089 * @param b the second OID
00090 * @return true if a is lexicographically smaller than b
00091 */
00092 bool BOTAN_DLL operator<(const OID& a, const OID& b);
00093 
00094 }
00095 
00096 #endif