tasty! apache remover is working
[feisty_meow.git] / octopi / library / tentacles / encryption_wrapper.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : encryption_wrapper                                                *
4 *  Author : Chris Koeritz                                                     *
5 *                                                                             *
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 \*****************************************************************************/
14
15 #include "encryption_wrapper.h"
16
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>
21
22 using namespace basis;
23 using namespace loggers;
24 using namespace structures;
25
26 namespace octopi {
27
28 #undef LOG
29 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
30
31 encryption_wrapper::encryption_wrapper(const byte_array &wrapped)
32 : infoton(encryption_classifier()),
33   _wrapped(wrapped)
34 {}
35
36 encryption_wrapper::encryption_wrapper(const encryption_wrapper &to_copy)
37 : root_object(),
38   infoton(to_copy),
39   _wrapped(to_copy._wrapped)
40 {}
41
42 encryption_wrapper::~encryption_wrapper() {}
43
44 clonable *encryption_wrapper::clone() const
45 { return cloner<encryption_wrapper>(*this); }
46
47 encryption_wrapper &encryption_wrapper::operator =
48     (const encryption_wrapper &to_copy)
49 {
50   if (this == &to_copy) return *this;
51   _wrapped = to_copy._wrapped;
52   return *this;
53 }
54
55 const char *wrap_encryption_classifier[] = { "#octrap" };
56
57 SAFE_STATIC_CONST(string_array, encryption_wrapper::encryption_classifier,
58     (1, wrap_encryption_classifier))
59
60 int encryption_wrapper::packed_size() const
61 {
62   return _wrapped.length() + sizeof(int);  // wrapped array size.
63 }
64
65 void encryption_wrapper::pack(byte_array &packed_form) const
66 {
67   structures::attach(packed_form, _wrapped);
68 }
69
70 bool encryption_wrapper::unpack(byte_array &packed_form)
71 {
72   if (!structures::detach(packed_form, _wrapped)) return false;
73   return true;
74 }
75
76 //////////////
77
78 unwrapping_tentacle::unwrapping_tentacle()
79 : tentacle_helper<encryption_wrapper>
80     (encryption_wrapper::encryption_classifier(), false)
81 {}
82
83 unwrapping_tentacle::~unwrapping_tentacle()
84 {}
85
86 outcome unwrapping_tentacle::reconstitute(const string_array &classifier,
87     byte_array &packed_form, infoton * &reformed)
88 {
89   if (classifier != encryption_wrapper::encryption_classifier())
90     return NO_HANDLER;
91
92   return reconstituter(classifier, packed_form, reformed,
93       (encryption_wrapper *)NULL_POINTER);
94 }
95
96 outcome unwrapping_tentacle::consume(infoton &formal(to_chow),
97     const octopus_request_id &formal(item_id), byte_array &transformed)
98 {
99   FUNCDEF("consume");
100   transformed.reset();
101   LOG("should never enter this method.");
102   return common::NOT_IMPLEMENTED;
103 }
104
105 } //namespace.
106