blob: 69310221d8e28f1df3691cf12e2ad315cee0e88e [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
5 * Zhenkai Zhu
6 *
7 * BSD license, See the LICENSE file for more information
8 *
9 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
10 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
11 */
12
13#ifndef NDN_CONTENT_OBJECT_H
14#define NDN_CONTENT_OBJECT_H
15
16#include "ndn.cxx/wrapper.h"
17#include "ndn.cxx/common.h"
18#include "ndn.cxx/fields/name.h"
19#include "ndn.cxx/helpers/hash.h"
20
21namespace ndn {
22
23// class Cert;
24// typedef boost::shared_ptr<Cert> CertPtr;
25
26class ParsedContentObject
27{
28public:
29 enum Type
30 {
31 DATA,
32 KEY,
33 OTHER
34 };
35 ParsedContentObject(const unsigned char *data, size_t len, bool verified = false);
36 ParsedContentObject(const unsigned char *data, const ccn_parsed_ContentObject &pco, bool verified = false);
37 ParsedContentObject(const Bytes &bytes, bool verified = false);
38 ParsedContentObject(const ParsedContentObject &other, bool verified = false);
39 virtual ~ParsedContentObject();
40
41 Bytes
42 content() const;
43
44 BytesPtr
45 contentPtr() const;
46
47 Name
48 name() const;
49
50 Name
51 keyName() const;
52
53 HashPtr
54 publisherPublicKeyDigest() const;
55
56 Type
57 type() const;
58
59 inline const Bytes &
60 buf () const;
61
62 bool
63 verified() const { return m_verified; }
64
65 // void
66 // verifySignature(const CertPtr &cert);
67
68 const unsigned char *
69 msg() const { return head(m_bytes); }
70
71 const ccn_parsed_ContentObject *
72 pco() const { return &m_pco; }
73
74private:
75 void
76 init(const unsigned char *data, size_t len);
77
78protected:
79 ccn_parsed_ContentObject m_pco;
80 ccn_indexbuf *m_comps;
81 Bytes m_bytes;
82 bool m_verified;
83 bool m_integrityChecked;
84};
85
86typedef boost::shared_ptr<ParsedContentObject> PcoPtr;
87
88namespace Error {
89struct MisformedContentObject : virtual boost::exception, virtual std::exception { };
90}
91
92const Bytes &
93ParsedContentObject::buf () const
94{
95 return m_bytes;
96}
97
98
99}
100
101#endif // NDN_CONTENT_OBJECT_H