00001 // Credentials.h 00002 00003 00004 #ifndef CREDENTIALS_H 00005 #define CREDENTIALS_H 00006 00007 #include <stdint.h> 00008 #include <vector> 00009 00010 #include "ServiceException.h" 00011 00012 namespace Yosokumo 00013 { 00014 00015 /** 00016 * Specifies credentials (user id and key) for Yosokumo authentication. 00017 */ 00018 00019 class Credentials 00020 { 00021 public: 00022 00023 /** 00024 * The exact length of a key. 00025 */ 00026 enum { KEY_LEN = 64 }; 00027 00028 private: 00029 00030 /** 00031 * The user to whom the key belongs. 00032 */ 00033 std::string userId; 00034 00035 /** 00036 * The key belonging to the user. It contains KEY_LEN bytes. 00037 */ 00038 std::vector<uint8_t> key; 00039 00040 public: 00041 00042 /** 00043 * Default constructor - initializes a newly created 00044 * <code>Credentials</code> object with default values. 00045 */ 00046 Credentials(); 00047 00048 /** 00049 * Initializes a newly created <code>Credentials</code> object to 00050 * the user id and key given as parameters. 00051 * 00052 * @param userId the user to whom the key belongs. 00053 * @param key the key. 00054 * 00055 * @throws ServiceException if the key length is not correct. 00056 */ 00057 Credentials(const std::string &userId, const std::vector<uint8_t> &key) 00058 throw(ServiceException); 00059 00060 /** 00061 * Copy constructor - initializes a newly created <code>Credentials</code> 00062 * object with a copy of another <code>Credentials</code> object. 00063 * 00064 * @param rhs the <code>Credentials</code> to make a copy of. 00065 */ 00066 Credentials(const Credentials &rhs); 00067 00068 00069 /** 00070 * Destructor - destroy a <code>Credentials</code> object. 00071 */ 00072 virtual ~Credentials(); 00073 00074 /** 00075 * Assignment operator - assign one <code>Credentials</code> to another. 00076 * 00077 * @param rhs the righthand side of the assignment. 00078 * 00079 * @return a reference to <code>this</code> Credentials. 00080 */ 00081 Credentials& operator=(const Credentials& rhs); 00082 00083 00084 // Equality operators 00085 00086 /** 00087 * Equality operator - compare two <code>Credentials</code> for equality. 00088 * 00089 * @param rhs the righthand side of the equality. 00090 * 00091 * @return <code>true</code> if and only if <code>this</code> 00092 * <code>Credentials</code> and the righthand side 00093 * <code>Credentials</code> are identically equal. 00094 */ 00095 bool operator==(const Credentials &rhs) const; 00096 00097 /** 00098 * Inequality operator - compare two <code>Credentials</code> for inequality. 00099 * 00100 * @param rhs the righthand side of the inequality. 00101 * 00102 * @return <code>true</code> if and only if <code>this</code> 00103 * <code>Credentials</code> and the righthand side 00104 * <code>Credentials</code> are not identically equal. 00105 */ 00106 bool operator!=(const Credentials &rhs) const; 00107 00108 /** 00109 * Return the user id. 00110 * 00111 * @return the user id. 00112 */ 00113 std::string getUserId(); 00114 00115 /** 00116 * Return a copy of the user key. 00117 * 00118 * @param theKey a copy of the user key is placed in this vector. 00119 */ 00120 void getKey(std::vector<uint8_t> &theKey); 00121 00122 /** 00123 * Return a string representation of the <code>Credentials</code>. 00124 * 00125 * @return the string representation of the <code>Credentials</code>. 00126 */ 00127 std::string toString(); 00128 00129 /** 00130 * Return a string representation of a key. 00131 * 00132 * @param key the key to convert to a string. 00133 * @return the string representation of key. 00134 */ 00135 static std::string keyToString(const std::vector<uint8_t> &key); 00136 00137 /* 00138 key = 64 bytes 00139 -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx 00140 -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx 00141 -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx 00142 -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx -xxx 00143 -xxx -xxx -xxx -xxx 00144 */ 00145 00146 }; // end class Credentials 00147 00148 } // end namespace Yosokumo 00149 00150 #endif // CREDENTIALS_H` 00151 00152 // end Credentials.h