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