1 /*****************************************************************************\
3 * Name : key_repository *
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 "key_repository.h"
17 #include <crypto/blowfish_crypto.h>
18 #include <structures/symbol_table.h>
20 using namespace basis;
21 using namespace crypto;
22 using namespace structures;
27 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
29 //#define DEBUG_KEY_REPOSITORY
30 // uncomment for noisier execution. beware however, if the uls is in
31 // use, this can cause infinite recursion.
33 key_repository::~key_repository() {}
35 octenc_key_record *key_repository::lock(const octopus_entity &ent)
37 #ifdef DEBUG_KEY_REPOSITORY
39 LOG(astring("entity sought=") + ent.text_form());
41 octenc_key_record *to_return = NULL_POINTER;
43 to_return = _keys.find(ent.mangled_form());
45 #ifdef DEBUG_KEY_REPOSITORY
46 LOG(astring("did not find entity=") + ent.text_form());
50 #ifdef DEBUG_KEY_REPOSITORY
51 LOG(astring("found entity=") + ent.text_form());
57 void key_repository::unlock(octenc_key_record *to_unlock)
59 if (!to_unlock) return; // dolts! they cannot unlock a non-record.
63 outcome key_repository::add(const octopus_entity &ent,
64 const blowfish_crypto &key)
66 #ifdef DEBUG_KEY_REPOSITORY
68 LOG(astring("adding key for entity=") + ent.text_form());
70 auto_synchronizer loc(_locker);
71 octenc_key_record rec(ent, key);
72 return _keys.add(ent.mangled_form(), rec);
75 outcome key_repository::whack(const octopus_entity &ent)
77 #ifdef DEBUG_KEY_REPOSITORY
79 LOG(astring("removing key for entity=") + ent.text_form());
81 auto_synchronizer loc(_locker);
82 return _keys.whack(ent.mangled_form());