|
ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
|
#include <ndn/data.hpp>
Public Member Functions | |
| Data ()=default | |
| Default constructor. | |
| Data (const Name &name) | |
| Create a Data packet with a specified Name. | |
Encoding | |
| Error | encode (uint8_t *buf, size_t bufSize, size_t &encodedLen) const |
| Encode the Data packet to TLV wire format. | |
Name field | |
| const Name & | name () const |
| Get the Name (const reference) | |
| Name & | name () |
| Get the Name (reference) | |
| Data & | setName (const Name &name) |
| Set the Name (supports method chaining) | |
| Error | setName (std::string_view uri) |
| Set the Name from a URI string. | |
Content field | |
| const uint8_t * | content () const |
| Get a pointer to the content data. | |
| size_t | contentSize () const |
| Get the content size. | |
| bool | hasContent () const |
| Check if content is set. | |
| Error | setContent (const uint8_t *data, size_t size) |
| Set binary data as content. | |
| Error | setContent (std::string_view str) |
| Set a string as content. | |
ContentType field | |
| ContentType | contentType () const |
| Get the content type. | |
| Data & | setContentType (ContentType type) |
| Set the content type. | |
| bool | isLink () const |
| Check if this is a Link Object. | |
FreshnessPeriod field | |
| std::optional< uint32_t > | freshnessPeriod () const |
| Get the FreshnessPeriod. | |
| Data & | setFreshnessPeriod (uint32_t periodMs) |
| Set the FreshnessPeriod. | |
FinalBlockId field | |
| std::optional< uint64_t > | finalBlockId () const |
| Get the FinalBlockId. | |
| bool | hasFinalBlockId () const |
| Check if FinalBlockId is set. | |
| Data & | setFinalBlockId (uint64_t segmentNum) |
| Set the FinalBlockId. | |
| Data & | clearFinalBlockId () |
| Clear the FinalBlockId. | |
Signature fields | |
| SignatureType | signatureType () const |
| Get the signature type. | |
| Data & | setSignatureType (SignatureType type) |
| Set the signature type. | |
| const Name * | keyLocator () const |
| Get the KeyLocator. | |
| bool | hasKeyLocator () const |
| Check if KeyLocator is set. | |
| Data & | setKeyLocator (const Name &name) |
| Set the KeyLocator. | |
| Data & | clearKeyLocator () |
| Clear the KeyLocator. | |
| const uint8_t * | signatureValue () const |
| Get a pointer to the signature value. | |
| size_t | signatureValueSize () const |
| Get the size of the signature value. | |
| bool | hasSignature () const |
| Check if a signature is set. | |
| Error | signWithDigestSha256 () |
| Sign with DigestSha256. | |
| Error | signWithHmac (const uint8_t *key, size_t keyLen) |
| Sign with HMAC-SHA256. | |
| bool | verifyDigestSha256 () const |
| Verify a DigestSha256 signature. | |
| bool | verifyHmac (const uint8_t *key, size_t keyLen) const |
| Verify an HMAC-SHA256 signature. | |
| Error | signWithEcdsa (const uint8_t *privKey) |
| Sign with ECDSA P-256. | |
| bool | verifyEcdsa (const uint8_t *pubKey) const |
| Verify an ECDSA P-256 signature. | |
Static Public Member Functions | |
Decoding | |
| static Result< Data > | fromWire (const uint8_t *buf, size_t len) |
| Decode a Data packet from TLV wire format. | |
NDN Data packet.
A Data packet contains the content returned by a producer in response to an Interest. Only the Name field is required; Content and FreshnessPeriod are optional.
|
default |
|
explicit |
| Data & ndn::Data::clearFinalBlockId | ( | ) |
| Data & ndn::Data::clearKeyLocator | ( | ) |
|
inline |
Get a pointer to the content data.
Definition at line 135 of file data.hpp.
Referenced by ndn::Certificate::fromData(), and ndn::Link::fromData().
|
inline |
Get the content size.
Definition at line 141 of file data.hpp.
Referenced by ndn::Certificate::fromData(), and ndn::Link::fromData().
|
inline |
Get the content type.
Definition at line 177 of file data.hpp.
Referenced by ndn::Certificate::fromData(), and ndn::Link::fromData().
| Error ndn::Data::encode | ( | uint8_t * | buf, |
| size_t | bufSize, | ||
| size_t & | encodedLen | ||
| ) | const |
Encode the Data packet to TLV wire format.
| buf | Output buffer |
| bufSize | Buffer size |
| encodedLen | Stores the number of encoded bytes |
Definition at line 317 of file data.cpp.
References ndn::TlvEncoder::current(), ndn::tlv::Data, ndn::PACKET_MAX_SIZE, ndn::TlvEncoder::position(), ndn::TlvEncoder::remaining(), ndn::TlvEncoder::setPosition(), ndn::tlv::SignatureValue, ndn::TlvEncoder::size(), ndn::varNumberSize(), ndn::TlvEncoder::writeBytes(), ndn::TlvEncoder::writeLength(), ndn::TlvEncoder::writeTlv(), and ndn::TlvEncoder::writeType().
|
inline |
|
inline |
Get the FreshnessPeriod.
FreshnessPeriod indicates the freshness duration of the Data (milliseconds). Within this period, cached responses from the Content Store are possible.
Definition at line 205 of file data.hpp.
Referenced by ndn::ContentStore::insert().
Decode a Data packet from TLV wire format.
| buf | Input buffer |
| len | Buffer length |
Definition at line 362 of file data.cpp.
References ndn::tlv::Content, ndn::tlv::ContentType, ndn::TlvDecoder::current(), ndn::tlv::Data, ndn::DATA_MAX_CONTENT_SIZE, ndn::tlv::FinalBlockId, ndn::tlv::FreshnessPeriod, ndn::Name::fromWire(), ndn::tlv::KeyLocator, ndn::tlv::MetaInfo, ndn::tlv::Name, ndn::TlvDecoder::position(), ndn::TlvDecoder::readBytes(), ndn::TlvDecoder::readNonNegativeInteger(), ndn::TlvDecoder::readTlvHeader(), ndn::TlvDecoder::remaining(), ndn::TlvDecoder::setPosition(), ndn::SIGNATURE_MAX_SIZE, ndn::tlv::SignatureInfo, ndn::tlv::SignatureType, ndn::tlv::SignatureValue, and ndn::TlvDecoder::skip().
Referenced by ndn::Certificate::fromWire().
|
inline |
Check if content is set.
Definition at line 147 of file data.hpp.
Referenced by ndn::Certificate::fromData(), and ndn::Link::fromData().
|
inline |
|
inline |
|
inline |
Check if a signature is set.
Definition at line 314 of file data.hpp.
Referenced by ndn::Certificate::fromData().
|
inline |
Check if this is a Link Object.
|
inline |
|
inline |
|
inline |
Get the Name (const reference)
Definition at line 104 of file data.hpp.
Referenced by ndn::Certificate::fromData(), ndn::Link::fromData(), ndn::ContentStore::insert(), ndn::Forwarder::putData(), setKeyLocator(), and setName().
| Error ndn::Data::setContent | ( | const uint8_t * | data, |
| size_t | size | ||
| ) |
Set binary data as content.
| data | Pointer to the content data |
| size | Data size (bytes) |
Definition at line 26 of file data.cpp.
References ndn::DATA_MAX_CONTENT_SIZE.
Referenced by setContent(), ndn::Certificate::toData(), and ndn::Link::toData().
| Error ndn::Data::setContent | ( | std::string_view | str | ) |
Set a string as content.
| str | Content string |
Definition at line 35 of file data.cpp.
References setContent().
| Data & ndn::Data::setContentType | ( | ContentType | type | ) |
Set the content type.
| type | Content type |
Definition at line 54 of file data.cpp.
Referenced by ndn::Certificate::toData(), and ndn::Link::toData().
| Data & ndn::Data::setFinalBlockId | ( | uint64_t | segmentNum | ) |
| Data & ndn::Data::setFreshnessPeriod | ( | uint32_t | periodMs | ) |
Set the FreshnessPeriod.
| periodMs | Freshness period (milliseconds) |
Definition at line 39 of file data.cpp.
Referenced by ndn::Certificate::toData().
Set the Name (supports method chaining)
| name | Name to set |
Definition at line 12 of file data.cpp.
References name().
Referenced by ndn::Certificate::toData(), and ndn::Link::toData().
| Error ndn::Data::setName | ( | std::string_view | uri | ) |
Set the Name from a URI string.
| uri | URI string (e.g., "/sensor/temperature") |
Definition at line 17 of file data.cpp.
References ndn::Name::fromUri().
| Data & ndn::Data::setSignatureType | ( | SignatureType | type | ) |
Set the signature type.
| type | Signature type |
Definition at line 59 of file data.cpp.
Referenced by ndn::Certificate::toData().
|
inline |
Get the signature type.
Definition at line 260 of file data.hpp.
Referenced by ndn::Certificate::fromData().
|
inline |
Get a pointer to the signature value.
Definition at line 302 of file data.hpp.
Referenced by ndn::Certificate::fromData().
|
inline |
Get the size of the signature value.
Definition at line 308 of file data.hpp.
Referenced by ndn::Certificate::fromData().
| Error ndn::Data::signWithDigestSha256 | ( | ) |
Sign with DigestSha256.
Computes a SHA-256 digest from Name, MetaInfo, Content, and SignatureInfo, and stores it in SignatureValue. signatureType is set to DigestSha256.
Definition at line 169 of file data.cpp.
References ndn::PACKET_MAX_SIZE, and ndn::SHA256_DIGEST_SIZE.
| Error ndn::Data::signWithEcdsa | ( | const uint8_t * | privKey | ) |
Sign with ECDSA P-256.
Computes an ECDSA signature using the specified private key and stores it in SignatureValue. signatureType is set to SignatureSha256WithEcdsa. It is recommended to set the KeyLocator beforehand.
| privKey | Private key (32 bytes) |
Definition at line 272 of file data.cpp.
References ndn::PACKET_MAX_SIZE.
| Error ndn::Data::signWithHmac | ( | const uint8_t * | key, |
| size_t | keyLen | ||
| ) |
Sign with HMAC-SHA256.
Computes HMAC-SHA256 using the specified key and stores it in SignatureValue. signatureType is set to SignatureHmacWithSha256.
| key | Pointer to the key data |
| keyLen | Key length (bytes) |
Definition at line 190 of file data.cpp.
References ndn::HMAC_SHA256_SIZE, and ndn::PACKET_MAX_SIZE.
| bool ndn::Data::verifyDigestSha256 | ( | ) | const |
Verify a DigestSha256 signature.
Definition at line 215 of file data.cpp.
References ndn::PACKET_MAX_SIZE, and ndn::SHA256_DIGEST_SIZE.
| bool ndn::Data::verifyEcdsa | ( | const uint8_t * | pubKey | ) | const |
Verify an ECDSA P-256 signature.
| pubKey | Public key (65 bytes, uncompressed form) |
Definition at line 293 of file data.cpp.
References ndn::ECDSA_P256_SIG_MAX_SIZE, and ndn::PACKET_MAX_SIZE.
| bool ndn::Data::verifyHmac | ( | const uint8_t * | key, |
| size_t | keyLen | ||
| ) | const |
Verify an HMAC-SHA256 signature.
| key | Pointer to the key data |
| keyLen | Key length (bytes) |
Definition at line 242 of file data.cpp.
References ndn::HMAC_SHA256_SIZE, and ndn::PACKET_MAX_SIZE.