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