blob: 4b1f971e017d4e3785c0cb7a9517b87e2ea334b3 [file] [log] [blame]
Zhiyi Zhang5f133622015-10-17 08:49:54 +08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California
4 *
5 * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
6 * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
7 *
8 * ndn-group-encrypt is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Zhiyi Zhang <dreamerbarrychang@gmail.com>
20 */
21
22#ifndef NDN_GEP_CONSUMER_DB_HPP
23#define NDN_GEP_CONSUMER_DB_HPP
24
25#include "common.hpp"
26
27namespace ndn {
28namespace gep {
29
30/**
31 * @brief ConsumerDB is a class to manage decryption keys for consumer.
32 */
33class ConsumerDB
34{
35public:
36 class Error : public std::runtime_error
37 {
38 public:
39 explicit
40 Error(const std::string& what)
41 : std::runtime_error(what)
42 {
43 }
44 };
45
46public:
47 explicit
48 ConsumerDB(const std::string& dbDir);
49
50 ~ConsumerDB();
51
52public:
53 /**
54 * @brief Get the key with @p keyName from database.
55 *
56 * @return Empty buffer when there is no key with @p keyName in database
57 */
58 const Buffer
59 getKey(const Name& keyName) const;
60
61 /**
62 * @brief Add the key with @p keyName and @p keyBuf to database.
63 *
64 * @throw Error when a key with the same name already exists in database.
65 */
66 void
67 addKey(const Name& keyName, const Buffer& keyBuf);
68
69 /**
70 * @brief Remove the key with @p keyName from the database.
71 */
72 void
73 deleteKey(const Name& keyName);
74
75private:
76 class Impl;
77 unique_ptr<Impl> m_impl;
78};
79
80} // namespace gep
81} // namespace ndn
82
83#endif // NDN_GEP_CONSUMER_DB_HPP