ndn_Error ndn_decodeTlvData (struct ndn_Data *data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset, struct ndn_TlvDecoder *decoder) { ndn_Error error; size_t endOffset; size_t dummyBeginOffset, dummyEndOffset; if ((error = ndn_TlvDecoder_readNestedTlvsStart(decoder, ndn_Tlv_Data, &endOffset))) return error; *signedPortionBeginOffset = decoder->offset; if ((error = ndn_decodeTlvName (&data->name, &dummyBeginOffset, &dummyEndOffset, decoder))) return error; if ((error = decodeMetaInfo(&data->metaInfo, decoder))) return error; if ((error = ndn_TlvDecoder_readBlobTlv(decoder, ndn_Tlv_Content, &data->content))) return error; if ((error = ndn_decodeTlvSignatureInfo(&data->signature, decoder))) return error; *signedPortionEndOffset = decoder->offset; if ((error = ndn_TlvDecoder_readBlobTlv(decoder, ndn_Tlv_SignatureValue, &data->signature.signature))) return error; if ((error = ndn_TlvDecoder_finishNestedTlvs(decoder, endOffset))) return error; return NDN_ERROR_success; }
ndn_Error ndn_decodeTlvDelegationSet_Delegation (struct ndn_DelegationSet_Delegation *delegation, struct ndn_TlvDecoder *decoder) { ndn_Error error; size_t endOffset; size_t dummyBeginOffset, dummyEndOffset; uint64_t unsignedPreference; if ((error = ndn_TlvDecoder_readNestedTlvsStart (decoder, ndn_Tlv_Link_Delegation, &endOffset))) return error; if ((error = ndn_TlvDecoder_readNonNegativeIntegerTlv (decoder, ndn_Tlv_Link_Preference, &unsignedPreference))) return error; delegation->preference = (int)unsignedPreference; if ((error = ndn_decodeTlvName (&delegation->name, &dummyBeginOffset, &dummyEndOffset, decoder))) return error; if ((error = ndn_TlvDecoder_finishNestedTlvs(decoder, endOffset))) return error; return NDN_ERROR_success; }
ndn_Error ndn_Tlv0_2WireFormat_decodeName (struct ndn_Name *name, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset) { struct ndn_TlvDecoder decoder; ndn_TlvDecoder_initialize(&decoder, input, inputLength); return ndn_decodeTlvName (name, signedPortionBeginOffset, signedPortionEndOffset, &decoder); }
ndn_Error ndn_decodeTlvKeyLocator (unsigned int expectedType, struct ndn_KeyLocator *keyLocator, struct ndn_TlvDecoder *decoder) { ndn_Error error; size_t endOffset; int gotExpectedType; if ((error = ndn_TlvDecoder_readNestedTlvsStart(decoder, expectedType, &endOffset))) return error; ndn_KeyLocator_initialize (keyLocator, keyLocator->keyName.components, keyLocator->keyName.maxComponents); if (decoder->offset == endOffset) // The KeyLocator is omitted, so leave the fields as none. return NDN_ERROR_success; if ((error = ndn_TlvDecoder_peekType(decoder, ndn_Tlv_Name, endOffset, &gotExpectedType))) return error; if (gotExpectedType) { size_t dummyBeginOffset, dummyEndOffset; // KeyLocator is a Name. if ((error = ndn_decodeTlvName (&keyLocator->keyName, &dummyBeginOffset, &dummyEndOffset, decoder))) return error; keyLocator->type = ndn_KeyLocatorType_KEYNAME; } else { if ((error = ndn_TlvDecoder_peekType(decoder, ndn_Tlv_KeyLocatorDigest, endOffset, &gotExpectedType))) return error; if (gotExpectedType) { // KeyLocator is a KeyLocatorDigest. keyLocator->type = ndn_KeyLocatorType_KEY_LOCATOR_DIGEST; if ((error = ndn_TlvDecoder_readBlobTlv(decoder, ndn_Tlv_KeyLocatorDigest, &keyLocator->keyData))) return error; } else return NDN_ERROR_decodeKeyLocator_unrecognized_key_locator_type; } if ((error = ndn_TlvDecoder_finishNestedTlvs(decoder, endOffset))) return error; return NDN_ERROR_success; }
static ndn_Error ndn_decodeTlvInterestV03 (struct ndn_Interest *interest, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset, struct ndn_TlvDecoder *decoder) { ndn_Error error; size_t endOffset; int canBePrefix, mustBeFresh; struct ndn_Blob dummyBlob; if ((error = ndn_TlvDecoder_readNestedTlvsStart (decoder, ndn_Tlv_Interest, &endOffset))) return error; if ((error = ndn_decodeTlvName (&interest->name, signedPortionBeginOffset, signedPortionEndOffset, decoder))) return error; if ((error = ndn_TlvDecoder_readBooleanTlv (decoder, ndn_Tlv_CanBePrefix, endOffset, &canBePrefix))) return error; ndn_Interest_setCanBePrefix(interest, canBePrefix); if ((error = ndn_TlvDecoder_readBooleanTlv (decoder, ndn_Tlv_MustBeFresh, endOffset, &mustBeFresh))) return error; ndn_Interest_setMustBeFresh(interest, mustBeFresh); // Get the encoded sequence of delegations as is. if ((error = ndn_TlvDecoder_readOptionalBlobTlv (decoder, ndn_Tlv_ForwardingHint, endOffset, &interest->forwardingHintWireEncoding))) return error; if ((error = ndn_TlvDecoder_readOptionalBlobTlv (decoder, ndn_Tlv_Nonce, endOffset, &interest->nonce))) return error; if ((error = ndn_TlvDecoder_readOptionalNonNegativeIntegerTlvAsDouble (decoder, ndn_Tlv_InterestLifetime, endOffset, &interest->interestLifetimeMilliseconds))) return error; // Clear the unused fields. interest->minSuffixComponents = -1; ndn_KeyLocator_initialize (&interest->keyLocator, interest->keyLocator.keyName.components, interest->keyLocator.keyName.maxComponents); interest->exclude.nEntries = 0; interest->childSelector = -1; ndn_Blob_initialize(&interest->linkWireEncoding, 0, 0); interest->selectedDelegationIndex = -1; // Ignore the HopLimit and Parameters. if ((error = ndn_TlvDecoder_readOptionalBlobTlv (decoder, ndn_Tlv_HopLimit, endOffset, &dummyBlob))) return error; if ((error = ndn_TlvDecoder_readOptionalBlobTlv (decoder, ndn_Tlv_Parameters, endOffset, &dummyBlob))) return error; if ((error = ndn_TlvDecoder_finishNestedTlvs(decoder, endOffset))) return error; return NDN_ERROR_success; }
static ndn_Error ndn_decodeTlvInterestV02 (struct ndn_Interest *interest, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset, struct ndn_TlvDecoder *decoder) { ndn_Error error; size_t endOffset; int gotExpectedType; if ((error = ndn_TlvDecoder_readNestedTlvsStart(decoder, ndn_Tlv_Interest, &endOffset))) return error; if ((error = ndn_decodeTlvName (&interest->name, signedPortionBeginOffset, signedPortionEndOffset, decoder))) return error; if ((error = ndn_TlvDecoder_peekType(decoder, ndn_Tlv_Selectors, endOffset, &gotExpectedType))) return error; if (gotExpectedType) { if ((error = decodeSelectors(interest, decoder))) return error; } else { // Set selectors to none. interest->minSuffixComponents = -1; interest->maxSuffixComponents = -1; ndn_KeyLocator_initialize (&interest->keyLocator, interest->keyLocator.keyName.components, interest->keyLocator.keyName.maxComponents); interest->exclude.nEntries = 0; interest->childSelector = -1; interest->mustBeFresh = 0; } // Require a Nonce, but don't force it to be 4 bytes. if ((error = ndn_TlvDecoder_readBlobTlv(decoder, ndn_Tlv_Nonce, &interest->nonce))) return error; if ((error = ndn_TlvDecoder_readOptionalNonNegativeIntegerTlvAsDouble (decoder, ndn_Tlv_InterestLifetime, endOffset, &interest->interestLifetimeMilliseconds))) return error; // Get the encoded sequence of delegations as is. if ((error = ndn_TlvDecoder_readOptionalBlobTlv (decoder, ndn_Tlv_ForwardingHint, endOffset, &interest->forwardingHintWireEncoding))) return error; if ((error = ndn_TlvDecoder_peekType(decoder, ndn_Tlv_Data, endOffset, &gotExpectedType))) return error; if (gotExpectedType) { // Get the bytes of the Link TLV. size_t linkBeginOffset = decoder->offset; size_t linkEndOffset; if ((error = ndn_TlvDecoder_readNestedTlvsStart (decoder, ndn_Tlv_Data, &linkEndOffset))) return error; ndn_TlvDecoder_seek(decoder, linkEndOffset); if ((error = ndn_TlvDecoder_getSlice (decoder, linkBeginOffset, linkEndOffset, &interest->linkWireEncoding))) return error; } else ndn_Blob_initialize(&interest->linkWireEncoding, 0, 0); if ((error = ndn_TlvDecoder_readOptionalNonNegativeIntegerTlv (decoder, ndn_Tlv_SelectedDelegation, endOffset, &interest->selectedDelegationIndex))) return error; if (interest->selectedDelegationIndex >= 0 && !interest->linkWireEncoding.value) return NDN_ERROR_Interest_has_a_selected_delegation_but_no_link_object; if ((error = ndn_TlvDecoder_finishNestedTlvs(decoder, endOffset))) return error; return NDN_ERROR_success; }