00001 #ifndef SECURITY_INFOTON_IMPLEMENTATION_FILE
00002 #define SECURITY_INFOTON_IMPLEMENTATION_FILE
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "security_infoton.h"
00019
00020 #include <basis/byte_array.h>
00021 #include <basis/function.h>
00022 #include <basis/mutex.h>
00023 #include <basis/string_array.h>
00024 #include <data_struct/static_memory_gremlin.h>
00025 #include <octopus/tentacle.h>
00026
00027 security_infoton::security_infoton()
00028 : infoton(security_classifier()),
00029 _mode(LI_LOGIN),
00030 _success(tentacle::NOT_FOUND),
00031 _verification(new byte_array)
00032 {}
00033
00034 security_infoton::security_infoton(login_modes mode, const outcome &success,
00035 const byte_array &verification)
00036 : infoton(security_classifier()),
00037 _mode(mode),
00038 _success(success),
00039 _verification(new byte_array(verification))
00040 {}
00041
00042 security_infoton::security_infoton(const security_infoton &to_copy)
00043 : object_base(),
00044 infoton(to_copy),
00045 _mode(to_copy._mode),
00046 _success(to_copy._success),
00047 _verification(new byte_array(*to_copy._verification))
00048 {
00049 }
00050
00051 security_infoton::~security_infoton()
00052 { WHACK(_verification); }
00053
00054 clonable *security_infoton::clone() const
00055 { return cloner<security_infoton>(*this); }
00056
00057 security_infoton &security_infoton::operator =(const security_infoton &to_copy)
00058 {
00059 if (this == &to_copy) return *this;
00060 set_classifier(to_copy.classifier());
00061 _mode = to_copy._mode;
00062 _success = to_copy._success;
00063 *_verification = *to_copy._verification;
00064 return *this;
00065 }
00066
00067 const byte_array &security_infoton::verification() const
00068 { return *_verification; }
00069
00070 byte_array &security_infoton::verification() { return *_verification; }
00071
00072 const istring login_classifier[] = { "#octsec" };
00073
00074 SAFE_STATIC_CONST(string_array, security_infoton::security_classifier,
00075 (1, login_classifier))
00076
00077 int security_infoton::packed_size() const
00078 {
00079 return sizeof(_mode)
00080 + sizeof(int)
00081 + _verification->length() + sizeof(int);
00082 }
00083
00084 void security_infoton::pack(byte_array &packed_form) const
00085 {
00086 basis::attach(packed_form, int(_mode));
00087 _success.pack(packed_form);
00088 basis::attach(packed_form, *_verification);
00089 }
00090
00091 bool security_infoton::unpack(byte_array &packed_form)
00092 {
00093 int int_hold;
00094 if (!basis::detach(packed_form, int_hold)) return false;
00095 _mode = login_modes(int_hold);
00096 if (!_success.unpack(packed_form)) return false;
00097 if (!basis::detach(packed_form, *_verification)) return false;
00098 return true;
00099 }
00100
00101
00102 #endif //SECURITY_INFOTON_IMPLEMENTATION_FILE
00103