blob: fd5bf909415f080ea8fe34514a85d0023d38b3ae [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_SIGNED_BLOB_H
14#define NDN_SIGNED_BLOB_H
15
16#include "blob.h"
17
18namespace ndn {
19
Jeff Thompson4454bf72013-06-18 13:33:12 -070020class SignedBlob;
21typedef boost::shared_ptr<SignedBlob> SignedBlobPtr;
22typedef boost::shared_ptr<const SignedBlob> ConstSignedBlobPtr;
23
Jeff Thompsonfa306642013-06-17 15:06:57 -070024/**
25 * @brief Class representing a blob, which has a signed portion (e.g., bytes of DATA packet)
26 */
27class SignedBlob : public Blob
28{
29public:
30 /**
31 * @brief Set signed portion of the blob
32 * @param offset An offset from the beginning of the blob
33 * @param size Size of the signed portion of the blob
34 */
35 inline void
36 setSignedPortion (size_t offset, size_t size);
37
38 /**
39 * @brief Get begin iterator to a signed portion of the blob
40 */
41 inline const_iterator
42 signed_begin () const;
43
44 /**
45 * @brief Get end iterator of a signed portion of the blob
46 */
47 inline const_iterator
48 signed_end () const;
49
50 /**
51 * @brief Get pointer to a first byte of the signed blob
52 */
53 inline const char*
54 signed_buf () const;
55
56 /**
57 * @brief Get size of the signed blob
58 */
59 inline size_t
60 signed_size () const;
61
62private:
63 const_iterator m_signedBegin;
64 const_iterator m_signedEnd;
65};
66
67
68inline void
69SignedBlob::setSignedPortion (size_t offset, size_t size)
70{
71 m_signedBegin = begin () + offset;
72 m_signedEnd = begin () + offset + size;
73}
74
75inline SignedBlob::const_iterator
76SignedBlob::signed_begin () const
77{
78 return m_signedBegin;
79}
80
81inline SignedBlob::const_iterator
82SignedBlob::signed_end () const
83{
84 return m_signedEnd;
85}
86
87inline const char*
88SignedBlob::signed_buf () const
89{
90 return &*m_signedBegin;
91}
92
93inline size_t
94SignedBlob::signed_size () const
95{
96 return m_signedEnd - m_signedBegin;
97}
98
Jeff Thompsonfa306642013-06-17 15:06:57 -070099} // ndn
100
101#endif // NDN_SIGNED_BLOB_H