1 /*****************************************************************************\
3 * Name : encryption_wrapper *
4 * Author : Chris Koeritz *
6 *******************************************************************************
7 * Copyright (c) 2004-$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 "encryption_wrapper.h"
17 #include <basis/byte_array.h>
18 #include <basis/mutex.h>
19 #include <loggers/program_wide_logger.h>
20 #include <structures/static_memory_gremlin.h>
22 using namespace basis;
23 using namespace loggers;
24 using namespace structures;
29 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
31 encryption_wrapper::encryption_wrapper(const byte_array &wrapped)
32 : infoton(encryption_classifier()),
36 encryption_wrapper::encryption_wrapper(const encryption_wrapper &to_copy)
39 _wrapped(to_copy._wrapped)
42 encryption_wrapper::~encryption_wrapper() {}
44 clonable *encryption_wrapper::clone() const
45 { return cloner<encryption_wrapper>(*this); }
47 encryption_wrapper &encryption_wrapper::operator =
48 (const encryption_wrapper &to_copy)
50 if (this == &to_copy) return *this;
51 _wrapped = to_copy._wrapped;
55 const char *wrap_encryption_classifier[] = { "#octrap" };
57 SAFE_STATIC_CONST(string_array, encryption_wrapper::encryption_classifier,
58 (1, wrap_encryption_classifier))
60 int encryption_wrapper::packed_size() const
62 return _wrapped.length() + sizeof(int); // wrapped array size.
65 void encryption_wrapper::pack(byte_array &packed_form) const
67 structures::attach(packed_form, _wrapped);
70 bool encryption_wrapper::unpack(byte_array &packed_form)
72 if (!structures::detach(packed_form, _wrapped)) return false;
78 unwrapping_tentacle::unwrapping_tentacle()
79 : tentacle_helper<encryption_wrapper>
80 (encryption_wrapper::encryption_classifier(), false)
83 unwrapping_tentacle::~unwrapping_tentacle()
86 outcome unwrapping_tentacle::reconstitute(const string_array &classifier,
87 byte_array &packed_form, infoton * &reformed)
89 if (classifier != encryption_wrapper::encryption_classifier())
92 return reconstituter(classifier, packed_form, reformed,
93 (encryption_wrapper *)NULL_POINTER);
96 outcome unwrapping_tentacle::consume(infoton &formal(to_chow),
97 const octopus_request_id &formal(item_id), byte_array &transformed)
101 LOG("should never enter this method.");
102 return common::NOT_IMPLEMENTED;