feisty meow concerns codebase 2.140
key_repository.cpp
Go to the documentation of this file.
1/*****************************************************************************\
2* *
3* Name : key_repository *
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 "key_repository.h"
16
19
20using namespace basis;
21using namespace crypto;
22using namespace structures;
23
24namespace octopi {
25
26#undef LOG
27#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
28
29//#define DEBUG_KEY_REPOSITORY
30 // uncomment for noisier execution. beware however, if the uls is in
31 // use, this can cause infinite recursion.
32
34
36{
37#ifdef DEBUG_KEY_REPOSITORY
38 FUNCDEF("lock");
39 LOG(astring("entity sought=") + ent.text_form());
40#endif
42 _locker.lock();
43 to_return = _keys.find(ent.mangled_form());
44 if (!to_return) {
45#ifdef DEBUG_KEY_REPOSITORY
46 LOG(astring("did not find entity=") + ent.text_form());
47#endif
48 _locker.unlock();
49 } else {
50#ifdef DEBUG_KEY_REPOSITORY
51 LOG(astring("found entity=") + ent.text_form());
52#endif
53 }
54 return to_return;
55}
56
58{
59 if (!to_unlock) return; // dolts! they cannot unlock a non-record.
60 _locker.unlock();
61}
62
64 const blowfish_crypto &key)
65{
66#ifdef DEBUG_KEY_REPOSITORY
67 FUNCDEF("add");
68 LOG(astring("adding key for entity=") + ent.text_form());
69#endif
70 auto_synchronizer loc(_locker);
71 octenc_key_record rec(ent, key);
72 return _keys.add(ent.mangled_form(), rec);
73}
74
76{
77#ifdef DEBUG_KEY_REPOSITORY
78 FUNCDEF("whack");
79 LOG(astring("removing key for entity=") + ent.text_form());
80#endif
81 auto_synchronizer loc(_locker);
82 return _keys.whack(ent.mangled_form());
83}
84
85} //namespace.
86
#define LOG(s)
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
auto_synchronizer simplifies concurrent code by automatically unlocking.
Definition mutex.h:113
void lock()
Clamps down on the mutex, if possible.
Definition mutex.cpp:101
void unlock()
Gives up the possession of the mutex.
Definition mutex.cpp:113
Outcomes describe the state of completion for an operation.
Definition outcome.h:31
Provides BlowFish encryption on byte_arrays using the OpenSSL package.
basis::outcome whack(const octopus_entity &ent)
removes the key for "ent".
void unlock(octenc_key_record *to_unlock)
drops the lock on the key record in "to_unlock".
basis::outcome add(const octopus_entity &ent, const crypto::blowfish_crypto &key)
adds a "key" for the "ent". this will fail if one is already listed.
octenc_key_record * lock(const octopus_entity &ent)
locates the key for "ent", if it's stored.
Tracks the keys that have been assigned for a secure channel.
Provides a way of identifying users of an octopus object.
Definition entity_defs.h:35
basis::astring text_form() const
returns a readable form of the identifier.
basis::astring mangled_form() const
returns the combined string form of the identifier.
#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 dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55