feisty meow concerns codebase 2.140
encryption_wrapper.cpp
Go to the documentation of this file.
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>
21
22using namespace basis;
23using namespace loggers;
24using namespace structures;
25
26namespace octopi {
27
28#undef LOG
29#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
30
32: infoton(encryption_classifier()),
33 _wrapped(wrapped)
34{}
35
37: root_object(),
38 infoton(to_copy),
39 _wrapped(to_copy._wrapped)
40{}
41
43
45{ return cloner<encryption_wrapper>(*this); }
46
47encryption_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
55const char *wrap_encryption_classifier[] = { "#octrap" };
56
59
61{
62 return _wrapped.length() + sizeof(int); // wrapped array size.
63}
64
65void encryption_wrapper::pack(byte_array &packed_form) const
66{
67 structures::attach(packed_form, _wrapped);
68}
69
71{
72 if (!structures::detach(packed_form, _wrapped)) return false;
73 return true;
74}
75
77
82
85
87 byte_array &packed_form, infoton * &reformed)
88{
90 return NO_HANDLER;
91
92 return reconstituter(classifier, packed_form, reformed,
94}
95
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
#define LOG(s)
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
Definition array.h:349
int length() const
Returns the current reported length of the allocated C array.
Definition array.h:115
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
A clonable object knows how to make copy of itself.
Definition contracts.h:109
Outcomes describe the state of completion for an operation.
Definition outcome.h:31
Wraps an encrypted infoton when the octopus is in an encrypted mode.
virtual clonable * clone() const
must be provided to allow creation of a copy of this object.
virtual bool unpack(basis::byte_array &packed_form)
restores an infoton from a packed form.
encryption_wrapper(const basis::byte_array &wrapped=basis::byte_array::empty_array())
virtual int packed_size() const
reports how large the infoton will be when packed.
basis::byte_array _wrapped
the encrypted data that's held here.
virtual void pack(basis::byte_array &packed_form) const
stuffs the data in the infoton into the "packed_form".
static const structures::string_array & encryption_classifier()
returns the classifier for this type of infoton.
An infoton is an individual request parcel with accompanying information.
Definition infoton.h:32
Identifies requests made on an octopus by users.
provides prefab implementations for parts of the tentacle object.
@ NO_HANDLER
no handler for that type of infoton.
Definition tentacle.h:73
virtual basis::outcome consume(infoton &to_chow, const octopus_request_id &item_id, basis::byte_array &transformed)
this should never be called.
virtual basis::outcome reconstitute(const structures::string_array &classifier, basis::byte_array &packed_form, infoton *&reformed)
this is a simple enough action that it is totally automated.
An array of strings with some additional helpful methods.
#define formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
Definition definitions.h:48
#define NULL_POINTER
The value representing a pointer to nothing.
Definition definitions.h:32
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
A logger that sends to the console screen using the standard output device.
basis::outcome reconstituter(const structures::string_array &classifier, basis::byte_array &packed_form, infoton *&reformed, contents *formal(junk))
< reconstituter should work for most infotons to restore flattened infotons.
const char * wrap_encryption_classifier[]
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55
void attach(byte_array &packed_form, const byte_array &to_attach)
Packs a byte_array "to_attach" into "packed_form".
bool detach(byte_array &packed_form, byte_array &to_detach)
Unpacks a byte_array "to_detach" from "packed_form".
#define SAFE_STATIC_CONST(type, func_name, parms)
this version returns a constant object instead.