Alexander Afanasyev | f278db3 | 2013-01-21 14:41:01 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 22 | #ifndef NDNX_CONTENT_OBJECT_H |
| 23 | #define NDNX_CONTENT_OBJECT_H |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 24 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 25 | #include "ndnx-wrapper.h" |
| 26 | #include "ndnx-common.h" |
| 27 | #include "ndnx-name.h" |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 29 | class Hash; |
| 30 | typedef boost::shared_ptr<Hash> HashPtr; |
| 31 | |
| 32 | namespace Ndnx { |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 33 | |
Alexander Afanasyev | f278db3 | 2013-01-21 14:41:01 -0800 | [diff] [blame] | 34 | struct MisformedContentObjectException : virtual boost::exception, virtual std::exception { }; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 35 | |
Zhenkai Zhu | d5d99be | 2013-03-13 19:15:56 -0700 | [diff] [blame] | 36 | class Cert; |
| 37 | typedef boost::shared_ptr<Cert> CertPtr; |
Zhenkai Zhu | dd1f14d | 2013-03-13 12:04:28 -0700 | [diff] [blame] | 38 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 39 | class ParsedContentObject |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 40 | { |
| 41 | public: |
Zhenkai Zhu | dd1f14d | 2013-03-13 12:04:28 -0700 | [diff] [blame] | 42 | enum Type |
| 43 | { |
| 44 | DATA, |
| 45 | KEY, |
| 46 | OTHER |
| 47 | }; |
Zhenkai Zhu | d5d99be | 2013-03-13 19:15:56 -0700 | [diff] [blame] | 48 | ParsedContentObject(const unsigned char *data, size_t len, bool verified = false); |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 49 | ParsedContentObject(const unsigned char *data, const ndn_parsed_ContentObject &pco, bool verified = false); |
Zhenkai Zhu | d5d99be | 2013-03-13 19:15:56 -0700 | [diff] [blame] | 50 | ParsedContentObject(const Bytes &bytes, bool verified = false); |
| 51 | ParsedContentObject(const ParsedContentObject &other, bool verified = false); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 52 | virtual ~ParsedContentObject(); |
| 53 | |
| 54 | Bytes |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 55 | content() const; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 56 | |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 57 | BytesPtr |
| 58 | contentPtr() const; |
Alexander Afanasyev | f278db3 | 2013-01-21 14:41:01 -0800 | [diff] [blame] | 59 | |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 60 | Name |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 61 | name() const; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 62 | |
Zhenkai Zhu | dd1f14d | 2013-03-13 12:04:28 -0700 | [diff] [blame] | 63 | Name |
| 64 | keyName() const; |
| 65 | |
| 66 | HashPtr |
| 67 | publisherPublicKeyDigest() const; |
| 68 | |
| 69 | Type |
| 70 | type() const; |
| 71 | |
Alexander Afanasyev | 053e5ac | 2013-01-22 20:59:13 -0800 | [diff] [blame] | 72 | inline const Bytes & |
| 73 | buf () const; |
| 74 | |
Zhenkai Zhu | 79264a4 | 2013-02-07 21:49:42 -0800 | [diff] [blame] | 75 | bool |
| 76 | verified() const { return m_verified; } |
| 77 | |
| 78 | void |
Zhenkai Zhu | d5d99be | 2013-03-13 19:15:56 -0700 | [diff] [blame] | 79 | verifySignature(const CertPtr &cert); |
Zhenkai Zhu | dd1f14d | 2013-03-13 12:04:28 -0700 | [diff] [blame] | 80 | |
Zhenkai Zhu | 79264a4 | 2013-02-07 21:49:42 -0800 | [diff] [blame] | 81 | const unsigned char * |
| 82 | msg() const { return head(m_bytes); } |
| 83 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 84 | const ndn_parsed_ContentObject * |
Zhenkai Zhu | 79264a4 | 2013-02-07 21:49:42 -0800 | [diff] [blame] | 85 | pco() const { return &m_pco; } |
| 86 | |
Zhenkai Zhu | 9f2ef6f | 2013-01-04 21:46:08 -0800 | [diff] [blame] | 87 | private: |
| 88 | void |
| 89 | init(const unsigned char *data, size_t len); |
| 90 | |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 91 | protected: |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 92 | ndn_parsed_ContentObject m_pco; |
| 93 | ndn_indexbuf *m_comps; |
Zhenkai Zhu | 9061180 | 2013-01-04 21:30:24 -0800 | [diff] [blame] | 94 | Bytes m_bytes; |
Zhenkai Zhu | 79264a4 | 2013-02-07 21:49:42 -0800 | [diff] [blame] | 95 | bool m_verified; |
Zhenkai Zhu | dd1f14d | 2013-03-13 12:04:28 -0700 | [diff] [blame] | 96 | bool m_integrityChecked; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
Alexander Afanasyev | 053e5ac | 2013-01-22 20:59:13 -0800 | [diff] [blame] | 99 | const Bytes & |
| 100 | ParsedContentObject::buf () const |
| 101 | { |
| 102 | return m_bytes; |
| 103 | } |
| 104 | |
| 105 | |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 106 | typedef boost::shared_ptr<ParsedContentObject> PcoPtr; |
| 107 | |
| 108 | } |
| 109 | |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 110 | #endif // NDNX_CONTENT_OBJECT_H |