1 #ifndef KEY_REPOSITORY_CLASS
2 #define KEY_REPOSITORY_CLASS
4 /*****************************************************************************\
6 * Name : key_repository *
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 2004-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include <basis/mutex.h>
19 #include <crypto/blowfish_crypto.h>
20 #include <structures/symbol_table.h>
21 #include <octopus/entity_defs.h>
25 //! Tracks the keys that have been assigned for a secure channel.
27 This class is thread-safe, as long as one uses the lock() method below in
30 NOTE: this is a heavy-weight header; do not include in other headers.
33 class octenc_key_record
36 octopus_entity _entity; //!< who the key belongs to.
37 crypto::blowfish_crypto _key; //!< used for communicating with an entity.
39 octenc_key_record() : _key(200) {} //!< bogus blank constructor.
41 octenc_key_record(const octopus_entity &entity, const crypto::blowfish_crypto &key)
42 : _entity(entity), _key(key) {}
50 key_repository() : _locker(), _keys() {}
51 virtual ~key_repository();
53 DEFINE_CLASS_NAME("key_repository");
55 octenc_key_record *lock(const octopus_entity &ent);
56 //!< locates the key for "ent", if it's stored.
57 /*!< the returned object, unless it's NULL_POINTER, must be unlocked. */
59 void unlock(octenc_key_record *to_unlock);
60 //!< drops the lock on the key record in "to_unlock".
62 basis::outcome add(const octopus_entity &ent, const crypto::blowfish_crypto &key);
63 //!< adds a "key" for the "ent". this will fail if one is already listed.
65 basis::outcome whack(const octopus_entity &ent);
66 //!< removes the key for "ent".
69 basis::mutex _locker; //!< protects our list of keys.
70 structures::symbol_table<octenc_key_record> _keys; //!< the list of keys.
75 #endif // outer guard.