blob: 3d14afcdd7b709b80b9988b80a4b74b3cd0ca4ab [file] [log] [blame]
Zhenkai Zhu3457ed42013-03-12 15:15:21 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20 */
21
22#ifndef CCNX_KEY_H
23#define CCNX_KEY_H
24
25#include "ccnx-common.h"
26#include "ccnx-name.h"
27#include "ccnx-pco.h"
28#include "hash-helper.h"
29#include <boost/shared_ptr.hpp>
30
31namespace Ccnx {
32
33class Key
34{
35public:
36 enum VALIDITY
37 {
38 NOT_YET_VALID,
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070039 WITHIN_VALID_TIME_SPAN,
Zhenkai Zhu3457ed42013-03-12 15:15:21 -070040 EXPIRED,
41 OTHER
42 };
43
44 Key();
45 Key(const PcoPtr &keyObject, const PcoPtr &metaObject);
46
47 void
48 updateMeta(const PcoPtr &metaObject);
49
50 Name
51 name() { return m_name; }
52
53 Bytes
54 raw() { return m_raw; }
55
56 Hash
57 hash() { return m_hash; }
58
59 std::string
60 realworldID() { return m_meta.realworldID; }
61
62 std::string
63 affilication() { return m_meta.affiliation; }
64
65 VALIDITY
66 validity();
67
68private:
69 struct KeyMeta
70 {
71 KeyMeta(std::string id, std::string affi, time_t from, time_t to)
72 : realworldID(id)
73 , affiliation(affi)
74 , validFrom(from)
75 , validTo(to)
76 {
77 }
78 std::string realworldID;
79 std::string affiliation;
80 time_t validFrom;
81 time_t validTo;
82 };
83
84 Name m_name;
85 Hash m_hash; // publisherPublicKeyHash
86 Bytes m_raw;
87 KeyMeta m_meta;
88};
89
90typedef boost::shared_ptr<Key> KeyPtr;
91
92}
93
94#endif // CCNX_KEY_H