blob: 6af0f73a90fc06f7069b2a7ee7488667ec1e0d3f [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
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070022#ifndef NDNX_CONTENT_OBJECT_H
23#define NDNX_CONTENT_OBJECT_H
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080024
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070025#include "ndnx-wrapper.h"
26#include "ndnx-common.h"
27#include "ndnx-name.h"
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080028
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070029class Hash;
30typedef boost::shared_ptr<Hash> HashPtr;
31
32namespace Ndnx {
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080033
Alexander Afanasyevf278db32013-01-21 14:41:01 -080034struct MisformedContentObjectException : virtual boost::exception, virtual std::exception { };
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080035
Zhenkai Zhud5d99be2013-03-13 19:15:56 -070036class Cert;
37typedef boost::shared_ptr<Cert> CertPtr;
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070038
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080039class ParsedContentObject
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080040{
41public:
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070042 enum Type
43 {
44 DATA,
45 KEY,
46 OTHER
47 };
Zhenkai Zhud5d99be2013-03-13 19:15:56 -070048 ParsedContentObject(const unsigned char *data, size_t len, bool verified = false);
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070049 ParsedContentObject(const unsigned char *data, const ndn_parsed_ContentObject &pco, bool verified = false);
Zhenkai Zhud5d99be2013-03-13 19:15:56 -070050 ParsedContentObject(const Bytes &bytes, bool verified = false);
51 ParsedContentObject(const ParsedContentObject &other, bool verified = false);
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080052 virtual ~ParsedContentObject();
53
54 Bytes
Zhenkai Zhubad089c2012-12-28 10:28:27 -080055 content() const;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080056
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080057 BytesPtr
58 contentPtr() const;
Alexander Afanasyevf278db32013-01-21 14:41:01 -080059
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080060 Name
Zhenkai Zhubad089c2012-12-28 10:28:27 -080061 name() const;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080062
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070063 Name
64 keyName() const;
65
66 HashPtr
67 publisherPublicKeyDigest() const;
68
69 Type
70 type() const;
71
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -080072 inline const Bytes &
73 buf () const;
74
Zhenkai Zhu79264a42013-02-07 21:49:42 -080075 bool
76 verified() const { return m_verified; }
77
78 void
Zhenkai Zhud5d99be2013-03-13 19:15:56 -070079 verifySignature(const CertPtr &cert);
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070080
Zhenkai Zhu79264a42013-02-07 21:49:42 -080081 const unsigned char *
82 msg() const { return head(m_bytes); }
83
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070084 const ndn_parsed_ContentObject *
Zhenkai Zhu79264a42013-02-07 21:49:42 -080085 pco() const { return &m_pco; }
86
Zhenkai Zhu9f2ef6f2013-01-04 21:46:08 -080087private:
88 void
89 init(const unsigned char *data, size_t len);
90
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080091protected:
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070092 ndn_parsed_ContentObject m_pco;
93 ndn_indexbuf *m_comps;
Zhenkai Zhu90611802013-01-04 21:30:24 -080094 Bytes m_bytes;
Zhenkai Zhu79264a42013-02-07 21:49:42 -080095 bool m_verified;
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070096 bool m_integrityChecked;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080097};
98
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -080099const Bytes &
100ParsedContentObject::buf () const
101{
102 return m_bytes;
103}
104
105
Zhenkai Zhu43eb2732012-12-28 00:48:26 -0800106typedef boost::shared_ptr<ParsedContentObject> PcoPtr;
107
108}
109
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -0700110#endif // NDNX_CONTENT_OBJECT_H