Esempio n. 1
0
/**
 * This private function is called by ndn_TlvEncoder_writeNestedTlv to write the
 * TLVs in the body of a signature's ValidityPeriod.
 * @param context This is the ndn_ValidityPeriod struct pointer which was passed
 * to writeTlv.
 * @param encoder the ndn_TlvEncoder which is calling this.
 * @return 0 for success, else an error code.
 */
static ndn_Error
encodeValidityPeriodValue(const void *context, struct ndn_TlvEncoder *encoder)
{
    struct ndn_ValidityPeriod *validityPeriod = (struct ndn_ValidityPeriod *)context;
    ndn_Error error;
    struct ndn_Blob isoStringBlob;
    char isoString[23];

    // Encode notBefore.
    if ((error = ndn_toIsoString(validityPeriod->notBefore, 0, isoString)))
        return error;
    ndn_Blob_initialize
    (&isoStringBlob, (const uint8_t *)isoString, strlen(isoString));
    if ((error = ndn_TlvEncoder_writeOptionalBlobTlv
                 (encoder, ndn_Tlv_ValidityPeriod_NotBefore, &isoStringBlob)))
        return error;

    // Encode notAfter.
    if ((error = ndn_toIsoString(validityPeriod->notAfter, 0, isoString)))
        return error;
    ndn_Blob_initialize
    (&isoStringBlob, (const uint8_t *)isoString, strlen(isoString));
    if ((error = ndn_TlvEncoder_writeOptionalBlobTlv
                 (encoder, ndn_Tlv_ValidityPeriod_NotAfter, &isoStringBlob)))
        return error;

    return NDN_ERROR_success;
}
Esempio n. 2
0
 /**
  * Call writeBlobTlv using the raw string bytes.
  * @param type The type of the TLV.
  * @param value The raw string.
  */
 void
 writeRawStringTlv(unsigned int type, const std::string& value)
 {
   struct ndn_Blob valueBlob;
   ndn_Blob_initialize(&valueBlob, (const uint8_t*)&value[0], value.size());
   writeBlobTlv(type, &valueBlob);
 }
Esempio n. 3
0
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;
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
BlobLite::BlobLite(const uint8_t* buf, size_t size)
{
  ndn_Blob_initialize(this, buf, size);
}
Esempio n. 6
0
BlobLite::BlobLite()
{
  ndn_Blob_initialize(this, 0, 0);
}