blob: 29230ddd9710ec5601f4c42d1829c5d560957274 [file] [log] [blame]
Zhiyi Zhang5f133622015-10-17 08:49:54 +08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang19a11d22018-04-12 22:58:20 -07003 * Copyright (c) 2014-2018, Regents of the University of California
Zhiyi Zhang5f133622015-10-17 08:49:54 +08004 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04005 * This file is part of NAC (Name-Based Access Control for NDN).
6 * See AUTHORS.md for complete list of NAC authors and contributors.
Zhiyi Zhang5f133622015-10-17 08:49:54 +08007 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04008 * NAC is free software: you can redistribute it and/or modify it under the terms
Zhiyi Zhang5f133622015-10-17 08:49:54 +08009 * 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 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -040012 * NAC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Zhiyi Zhang5f133622015-10-17 08:49:54 +080013 * 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
Alexander Afanasyev9091d832018-04-18 17:21:08 -040017 * NAC, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Zhiyi Zhang5f133622015-10-17 08:49:54 +080018 *
19 * @author Zhiyi Zhang <dreamerbarrychang@gmail.com>
20 */
21
Alexander Afanasyev9091d832018-04-18 17:21:08 -040022#ifndef NDN_NAC_CONSUMER_DB_HPP
23#define NDN_NAC_CONSUMER_DB_HPP
Zhiyi Zhang5f133622015-10-17 08:49:54 +080024
25#include "common.hpp"
26
27namespace ndn {
Alexander Afanasyev9091d832018-04-18 17:21:08 -040028namespace nac {
Zhiyi Zhang5f133622015-10-17 08:49:54 +080029
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:
Alexander Afanasyev9091d832018-04-18 17:21:08 -040039 using std::runtime_error::runtime_error;
Zhiyi Zhang5f133622015-10-17 08:49:54 +080040 };
41
42public:
Yingdi Yu48967a62016-03-11 22:04:14 -080043 /** @brief Create a consumer database at @p dbPath
44 */
Zhiyi Zhang5f133622015-10-17 08:49:54 +080045 explicit
Yingdi Yu48967a62016-03-11 22:04:14 -080046 ConsumerDB(const std::string& dbPath);
Zhiyi Zhang5f133622015-10-17 08:49:54 +080047
48 ~ConsumerDB();
49
50public:
51 /**
52 * @brief Get the key with @p keyName from database.
53 *
54 * @return Empty buffer when there is no key with @p keyName in database
55 */
56 const Buffer
57 getKey(const Name& keyName) const;
58
59 /**
60 * @brief Add the key with @p keyName and @p keyBuf to database.
61 *
62 * @throw Error when a key with the same name already exists in database.
63 */
64 void
65 addKey(const Name& keyName, const Buffer& keyBuf);
66
67 /**
68 * @brief Remove the key with @p keyName from the database.
69 */
70 void
71 deleteKey(const Name& keyName);
72
73private:
74 class Impl;
75 unique_ptr<Impl> m_impl;
76};
77
Alexander Afanasyev9091d832018-04-18 17:21:08 -040078} // namespace nac
Zhiyi Zhang5f133622015-10-17 08:49:54 +080079} // namespace ndn
80
Alexander Afanasyev9091d832018-04-18 17:21:08 -040081#endif // NDN_NAC_CONSUMER_DB_HPP