blob: 61646e844b101c38946fd741a1d8a83ce8997d6e [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:
Yingdi Yu48967a62016-03-11 22:04:14 -080047 /** @brief Create a consumer database at @p dbPath
48 */
Zhiyi Zhang5f133622015-10-17 08:49:54 +080049 explicit
Yingdi Yu48967a62016-03-11 22:04:14 -080050 ConsumerDB(const std::string& dbPath);
Zhiyi Zhang5f133622015-10-17 08:49:54 +080051
52 ~ConsumerDB();
53
54public:
55 /**
56 * @brief Get the key with @p keyName from database.
57 *
58 * @return Empty buffer when there is no key with @p keyName in database
59 */
60 const Buffer
61 getKey(const Name& keyName) const;
62
63 /**
64 * @brief Add the key with @p keyName and @p keyBuf to database.
65 *
66 * @throw Error when a key with the same name already exists in database.
67 */
68 void
69 addKey(const Name& keyName, const Buffer& keyBuf);
70
71 /**
72 * @brief Remove the key with @p keyName from the database.
73 */
74 void
75 deleteKey(const Name& keyName);
76
77private:
78 class Impl;
79 unique_ptr<Impl> m_impl;
80};
81
82} // namespace gep
83} // namespace ndn
84
85#endif // NDN_GEP_CONSUMER_DB_HPP