ndn::SignatureInfo Class Reference

Represents a SignatureInfo or InterestSignatureInfo TLV element. More...

#include <ndn-cxx/signature-info.hpp>

Classes

class  Error
 

Public Types

enum class  Type : uint32_t {
  Data = tlv::SignatureInfo ,
  Interest = tlv::InterestSignatureInfo
}
 

Public Member Functions

 SignatureInfo ()
 
 SignatureInfo (const Block &wire, Type type=Type::Data)
 Create from wire encoding. More...
 
 SignatureInfo (tlv::SignatureTypeValue type, std::optional< KeyLocator > keyLocator=std::nullopt)
 Create with the specified type and KeyLocator. More...
 
void addCustomTlv (Block block)
 Append an arbitrary TLV element to this SignatureInfo. More...
 
std::optional< BlockgetCustomTlv (uint32_t type) const
 Get first custom TLV element with the specified TLV-TYPE. More...
 
const KeyLocatorgetKeyLocator () const
 Get the KeyLocator element. More...
 
std::optional< std::vector< uint8_t > > getNonce () const
 Get SignatureNonce. More...
 
std::optional< uint64_t > getSeqNum () const
 Get SignatureSeqNum. More...
 
int32_t getSignatureType () const noexcept
 Get the SignatureType. More...
 
std::optional< time::system_clock::time_pointgetTime () const
 Get SignatureTime. More...
 
security::ValidityPeriod getValidityPeriod () const
 Get the ValidityPeriod element. More...
 
bool hasKeyLocator () const noexcept
 Check if KeyLocator is present. More...
 
bool hasWire () const noexcept
 Check if this instance has cached wire encoding. More...
 
 operator bool () const noexcept
 Determine whether SignatureInfo is valid. More...
 
void removeCustomTlv (uint32_t type)
 Remove all arbitrary TLV elements with the specified TLV-TYPE from this SignatureInfo. More...
 
SignatureInfosetKeyLocator (std::optional< KeyLocator > keyLocator)
 Set or unset the KeyLocator element. More...
 
SignatureInfosetNonce (std::optional< span< const uint8_t >> nonce)
 Append or replace SignatureNonce. More...
 
SignatureInfosetSeqNum (std::optional< uint64_t > seqNum)
 Append or replace SignatureSeqNum. More...
 
SignatureInfosetSignatureType (tlv::SignatureTypeValue type)
 Set the SignatureType. More...
 
SignatureInfosetTime (std::optional< time::system_clock::time_point > time=time::system_clock::now())
 Append or replace SignatureTime. More...
 
SignatureInfosetValidityPeriod (std::optional< security::ValidityPeriod > validityPeriod)
 Append, replace, or remove the ValidityPeriod element. More...
 
void wireDecode (const Block &wire, Type type=Type::Data)
 Decode from wire format. More...
 
template<encoding::Tag TAG>
size_t wireEncode (EncodingImpl< TAG > &encoder, Type type=Type::Data) const
 Fast encoding or block size estimation. More...
 
const BlockwireEncode (Type type=Type::Data) const
 Encode to wire format. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const SignatureInfo &info)
 
bool operator== (const SignatureInfo &lhs, const SignatureInfo &rhs)
 

Detailed Description

Represents a SignatureInfo or InterestSignatureInfo TLV element.

Definition at line 33 of file signature-info.hpp.

Member Enumeration Documentation

◆ Type

enum ndn::SignatureInfo::Type : uint32_t
strong
Enumerator
Data 
Interest 

Definition at line 42 of file signature-info.hpp.

Constructor & Destructor Documentation

◆ SignatureInfo() [1/3]

ndn::SignatureInfo::SignatureInfo ( )
default

◆ SignatureInfo() [2/3]

ndn::SignatureInfo::SignatureInfo ( tlv::SignatureTypeValue  type,
std::optional< KeyLocator keyLocator = std::nullopt 
)
explicit

Create with the specified type and KeyLocator.

Definition at line 33 of file signature-info.cpp.

◆ SignatureInfo() [3/3]

ndn::SignatureInfo::SignatureInfo ( const Block wire,
SignatureInfo::Type  type = Type::Data 
)
explicit

Create from wire encoding.

Parameters
wireWire to decode from
typeWhich type of SignatureInfo block decoding should expect
Exceptions
tlv::ErrorDecode error

Definition at line 39 of file signature-info.cpp.

Member Function Documentation

◆ addCustomTlv()

void ndn::SignatureInfo::addCustomTlv ( Block  block)

Append an arbitrary TLV element to this SignatureInfo.

If an element of the same TLV-TYPE already exists, it will be replaced by the new element.

Definition at line 301 of file signature-info.cpp.

◆ getCustomTlv()

std::optional< Block > ndn::SignatureInfo::getCustomTlv ( uint32_t  type) const

Get first custom TLV element with the specified TLV-TYPE.

Parameters
typeTLV-TYPE of element to get
Return values
nulloptNo custom TLV elements with the specified TLV-TYPE exist

Definition at line 291 of file signature-info.cpp.

◆ getKeyLocator()

const KeyLocator & ndn::SignatureInfo::getKeyLocator ( ) const

Get the KeyLocator element.

Exceptions
ErrorThis SignatureInfo does not contain a KeyLocator element.

Definition at line 183 of file signature-info.cpp.

◆ getNonce()

std::optional< std::vector< uint8_t > > ndn::SignatureInfo::getNonce ( ) const

Get SignatureNonce.

Return values
nulloptSignatureNonce is not set

Definition at line 224 of file signature-info.cpp.

◆ getSeqNum()

std::optional< uint64_t > ndn::SignatureInfo::getSeqNum ( ) const

Get SignatureSeqNum.

Return values
nulloptSignatureSeqNum is not set

Definition at line 269 of file signature-info.cpp.

◆ getSignatureType()

int32_t ndn::SignatureInfo::getSignatureType ( ) const
inlinenoexcept

Get the SignatureType.

Returns
tlv::SignatureTypeValue, or -1 to indicate an invalid SignatureInfo.

Definition at line 114 of file signature-info.hpp.

◆ getTime()

std::optional< time::system_clock::time_point > ndn::SignatureInfo::getTime ( ) const

Get SignatureTime.

Return values
nulloptSignatureTime is not set

Definition at line 246 of file signature-info.cpp.

◆ getValidityPeriod()

security::ValidityPeriod ndn::SignatureInfo::getValidityPeriod ( ) const

Get the ValidityPeriod element.

Exceptions
ErrorThis SignatureInfo does not contain a ValidityPeriod

Definition at line 202 of file signature-info.cpp.

◆ hasKeyLocator()

bool ndn::SignatureInfo::hasKeyLocator ( ) const
inlinenoexcept

Check if KeyLocator is present.

Definition at line 128 of file signature-info.hpp.

◆ hasWire()

bool ndn::SignatureInfo::hasWire ( ) const
inlinenoexcept

Check if this instance has cached wire encoding.

Definition at line 104 of file signature-info.hpp.

◆ operator bool()

ndn::SignatureInfo::operator bool ( ) const
inlineexplicitnoexcept

Determine whether SignatureInfo is valid.

Definition at line 66 of file signature-info.hpp.

◆ removeCustomTlv()

void ndn::SignatureInfo::removeCustomTlv ( uint32_t  type)

Remove all arbitrary TLV elements with the specified TLV-TYPE from this SignatureInfo.

Parameters
typeTLV-TYPE of elements to remove

Definition at line 317 of file signature-info.cpp.

◆ setKeyLocator()

SignatureInfo & ndn::SignatureInfo::setKeyLocator ( std::optional< KeyLocator keyLocator)

Set or unset the KeyLocator element.

Passing nullopt will remove the KeyLocator element.

Returns
A reference to this SignatureInfo, to allow chaining.

Definition at line 192 of file signature-info.cpp.

◆ setNonce()

SignatureInfo & ndn::SignatureInfo::setNonce ( std::optional< span< const uint8_t >>  nonce)

Append or replace SignatureNonce.

Passing nullopt will remove the SignatureNonce.

Returns
A reference to this SignatureInfo, to allow chaining.

Definition at line 234 of file signature-info.cpp.

◆ setSeqNum()

SignatureInfo & ndn::SignatureInfo::setSeqNum ( std::optional< uint64_t >  seqNum)

Append or replace SignatureSeqNum.

Passing nullopt will remove the SignatureSeqNum.

Returns
A reference to this SignatureInfo, to allow chaining.

Definition at line 279 of file signature-info.cpp.

◆ setSignatureType()

SignatureInfo & ndn::SignatureInfo::setSignatureType ( tlv::SignatureTypeValue  type)

Set the SignatureType.

Returns
A reference to this SignatureInfo, to allow chaining.

Definition at line 173 of file signature-info.cpp.

◆ setTime()

SignatureInfo & ndn::SignatureInfo::setTime ( std::optional< time::system_clock::time_point time = time::system_clock::now())

Append or replace SignatureTime.

Passing nullopt will remove the SignatureTime.

Returns
A reference to this SignatureInfo, to allow chaining.

Definition at line 256 of file signature-info.cpp.

◆ setValidityPeriod()

SignatureInfo & ndn::SignatureInfo::setValidityPeriod ( std::optional< security::ValidityPeriod validityPeriod)

Append, replace, or remove the ValidityPeriod element.

Passing nullopt will remove the ValidityPeriod element.

Returns
A reference to this SignatureInfo, to allow chaining.

Definition at line 212 of file signature-info.cpp.

◆ wireDecode()

void ndn::SignatureInfo::wireDecode ( const Block wire,
SignatureInfo::Type  type = Type::Data 
)

Decode from wire format.

Parameters
wireWire to decode from
typeWhich type of SignatureInfo block decoding should expect
Exceptions
tlv::ErrorDecode error

Definition at line 110 of file signature-info.cpp.

◆ wireEncode() [1/2]

template<encoding::Tag TAG>
size_t ndn::SignatureInfo::wireEncode ( EncodingImpl< TAG > &  encoder,
SignatureInfo::Type  type = Type::Data 
) const

Fast encoding or block size estimation.

Parameters
encoderEncodingEstimator or EncodingBuffer instance
typeWhich type of SignatureInfo block to encode

Elements are encoded in the following order: SignatureType, KeyLocator (if present), and other elements in the order they were set (changing the value of an already present element will not change that element's encoding order).

Definition at line 46 of file signature-info.cpp.

◆ wireEncode() [2/2]

const Block & ndn::SignatureInfo::wireEncode ( SignatureInfo::Type  type = Type::Data) const

Encode to wire format.

Parameters
typeWhich type of SignatureInfo block to encode

Elements are encoded in the following order: SignatureType, KeyLocator (if present), and other elements in the order they were set (changing the value of an already present element will not change that element's encoding order).

Definition at line 94 of file signature-info.cpp.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const SignatureInfo info 
)
friend

Definition at line 345 of file signature-info.cpp.

◆ operator==

bool operator== ( const SignatureInfo lhs,
const SignatureInfo rhs 
)
friend

Definition at line 338 of file signature-info.cpp.