blob: 75326308e2d41374cc75fe0ce0c58a05c8be64ba [file] [log] [blame]
Alexander Afanasyevf278db32013-01-21 14:41:01 -08001/* -*- 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
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080022#ifndef CCNX_CONTENT_OBJECT_H
23#define CCNX_CONTENT_OBJECT_H
24
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080025#include "ccnx-wrapper.h"
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080026#include "ccnx-common.h"
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080027#include "ccnx-name.h"
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070028#include "hash-helper.h"
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080029
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080030namespace Ccnx {
31
Alexander Afanasyevf278db32013-01-21 14:41:01 -080032struct MisformedContentObjectException : virtual boost::exception, virtual std::exception { };
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080033
Zhenkai Zhud5d99be2013-03-13 19:15:56 -070034class Cert;
35typedef boost::shared_ptr<Cert> CertPtr;
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070036
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080037class ParsedContentObject
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080038{
39public:
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070040 enum Type
41 {
42 DATA,
43 KEY,
44 OTHER
45 };
Zhenkai Zhud5d99be2013-03-13 19:15:56 -070046 ParsedContentObject(const unsigned char *data, size_t len, bool verified = false);
47 ParsedContentObject(const unsigned char *data, const ccn_parsed_ContentObject &pco, bool verified = false);
48 ParsedContentObject(const Bytes &bytes, bool verified = false);
49 ParsedContentObject(const ParsedContentObject &other, bool verified = false);
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080050 virtual ~ParsedContentObject();
51
52 Bytes
Zhenkai Zhubad089c2012-12-28 10:28:27 -080053 content() const;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080054
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080055 BytesPtr
56 contentPtr() const;
Alexander Afanasyevf278db32013-01-21 14:41:01 -080057
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080058 Name
Zhenkai Zhubad089c2012-12-28 10:28:27 -080059 name() const;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080060
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070061 Name
62 keyName() const;
63
64 HashPtr
65 publisherPublicKeyDigest() const;
66
67 Type
68 type() const;
69
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -080070 inline const Bytes &
71 buf () const;
72
Zhenkai Zhu79264a42013-02-07 21:49:42 -080073 bool
74 verified() const { return m_verified; }
75
76 void
Zhenkai Zhud5d99be2013-03-13 19:15:56 -070077 verifySignature(const CertPtr &cert);
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070078
Zhenkai Zhu79264a42013-02-07 21:49:42 -080079 const unsigned char *
80 msg() const { return head(m_bytes); }
81
82 const ccn_parsed_ContentObject *
83 pco() const { return &m_pco; }
84
Zhenkai Zhu9f2ef6f2013-01-04 21:46:08 -080085private:
86 void
87 init(const unsigned char *data, size_t len);
88
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080089protected:
Zhenkai Zhu90611802013-01-04 21:30:24 -080090 ccn_parsed_ContentObject m_pco;
91 ccn_indexbuf *m_comps;
92 Bytes m_bytes;
Zhenkai Zhu79264a42013-02-07 21:49:42 -080093 bool m_verified;
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070094 bool m_integrityChecked;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080095};
96
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -080097const Bytes &
98ParsedContentObject::buf () const
99{
100 return m_bytes;
101}
102
103
Zhenkai Zhu43eb2732012-12-28 00:48:26 -0800104typedef boost::shared_ptr<ParsedContentObject> PcoPtr;
105
106}
107
108#endif // CCNX_CONTENT_OBJECT_H