1 /*****************************************************************************\
3 * Name : security_infoton *
4 * Author : Chris Koeritz *
6 *******************************************************************************
7 * Copyright (c) 2002-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
15 #include "security_infoton.h"
17 #include <basis/byte_array.h>
18 #include <basis/functions.h>
19 #include <basis/mutex.h>
20 #include <structures/string_array.h>
21 #include <structures/static_memory_gremlin.h>
22 #include <octopus/tentacle.h>
24 using namespace basis;
25 using namespace structures;
26 //using namespace textual;
30 security_infoton::security_infoton()
31 : infoton(security_classifier()),
33 _success(tentacle::NOT_FOUND),
34 _verification(new byte_array)
37 security_infoton::security_infoton(login_modes mode, const outcome &success,
38 const byte_array &verification)
39 : infoton(security_classifier()),
42 _verification(new byte_array(verification))
45 security_infoton::security_infoton(const security_infoton &to_copy)
49 _success(to_copy._success),
50 _verification(new byte_array(*to_copy._verification))
54 security_infoton::~security_infoton()
55 { WHACK(_verification); }
57 clonable *security_infoton::clone() const
58 { return cloner<security_infoton>(*this); }
60 security_infoton &security_infoton::operator =(const security_infoton &to_copy)
62 if (this == &to_copy) return *this;
63 set_classifier(to_copy.classifier());
64 _mode = to_copy._mode;
65 _success = to_copy._success;
66 *_verification = *to_copy._verification;
70 const byte_array &security_infoton::verification() const
71 { return *_verification; }
73 byte_array &security_infoton::verification() { return *_verification; }
75 const astring login_classifier[] = { "#octsec" };
77 SAFE_STATIC_CONST(string_array, security_infoton::security_classifier,
78 (1, login_classifier))
80 int security_infoton::packed_size() const
83 + sizeof(int) // packed outcome.
84 + _verification->length() + sizeof(int);
87 void security_infoton::pack(byte_array &packed_form) const
89 structures::attach(packed_form, int(_mode));
90 attach(packed_form, _success.value());
91 structures::attach(packed_form, *_verification);
94 bool security_infoton::unpack(byte_array &packed_form)
97 if (!structures::detach(packed_form, int_hold)) return false;
98 _mode = login_modes(int_hold);
100 if (!detach(packed_form, value)) return false;
101 _success = outcome(value);
102 if (!structures::detach(packed_form, *_verification)) return false;