key_repository.cpp

Go to the documentation of this file.
00001 #ifndef KEY_REPOSITORY_IMPLEMENTATION_FILE
00002 #define KEY_REPOSITORY_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : key_repository                                                    *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2004-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #ifndef OMIT_CRYPTO_SUPPORT
00019 
00020 #include "key_repository.h"
00021 
00022 #include <basis/auto_synch.h>
00023 #include <crypto/blowfish_crypto.h>
00024 #include <data_struct/symbol_table.cpp>
00025 
00026 #undef LOG
00027 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s)
00028 
00029 //#define DEBUG_KEY_REPOSITORY
00030   // uncomment for noisier execution.  beware however, if the uls is in
00031   // use, this can cause infinite recursion.
00032 
00033 key_repository::~key_repository() {}
00034 
00035 octenc_key_record *key_repository::lock(const octopus_entity &ent)
00036 {
00037   FUNCDEF("lock");
00038 #ifdef DEBUG_KEY_REPOSITORY
00039   LOG(istring("entity sought=") + ent.text_form());
00040 #endif
00041   octenc_key_record *to_return = NIL;
00042   _locker.lock();
00043   to_return = _keys.find(ent.mangled_form());
00044   if (!to_return) {
00045 #ifdef DEBUG_KEY_REPOSITORY
00046     LOG(istring("did not find entity=") + ent.text_form());
00047 #endif
00048     _locker.unlock();
00049   } else {
00050 #ifdef DEBUG_KEY_REPOSITORY
00051     LOG(istring("found entity=") + ent.text_form());
00052 #endif
00053   }
00054   return to_return;
00055 }
00056 
00057 void key_repository::unlock(octenc_key_record *to_unlock)
00058 {
00059   if (!to_unlock) return;  // dolts!  they cannot unlock a non-record.
00060   _locker.unlock();
00061 }
00062 
00063 outcome key_repository::add(const octopus_entity &ent,
00064     const blowfish_crypto &key)
00065 {
00066   FUNCDEF("add");
00067   auto_synchronizer loc(_locker);
00068 #ifdef DEBUG_KEY_REPOSITORY
00069   LOG(istring("adding key for entity=") + ent.text_form());
00070 #endif
00071   octenc_key_record rec(ent, key);
00072   return _keys.add(ent.mangled_form(), rec);
00073 }
00074 
00075 outcome key_repository::whack(const octopus_entity &ent)
00076 {
00077   FUNCDEF("whack");
00078   auto_synchronizer loc(_locker);
00079 #ifdef DEBUG_KEY_REPOSITORY
00080   LOG(istring("removing key for entity=") + ent.text_form());
00081 #endif
00082   return _keys.whack(ent.mangled_form());
00083 }
00084 
00085 #endif // crypto
00086 
00087 
00088 #endif //KEY_REPOSITORY_IMPLEMENTATION_FILE
00089 

Generated on Fri Nov 28 04:29:32 2008 for HOOPLE Libraries by  doxygen 1.5.1