ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
ndn::ValidityPeriod Class Reference

Validity period. More...

#include <ndn/certificate.hpp>

Public Member Functions

 ValidityPeriod ()=default
 Default constructor.
 
Error encode (uint8_t *buf, size_t bufSize, size_t &encodedLen) const
 Encode the ValidityPeriod to TLV wire format.
 
bool isValidAt (std::string_view currentTimestamp) const
 Check if the current time is within the validity period.
 
bool equals (const ValidityPeriod &other) const
 Check equality of two validity periods.
 
NotBefore
Error setNotBefore (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
 Set the NotBefore time from date/time components.
 
Error setNotBefore (std::string_view timestamp)
 Set the NotBefore time from an ISO 8601 string.
 
const charnotBefore () const
 Get the NotBefore time as an ISO 8601 string.
 
NotAfter
Error setNotAfter (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
 Set the NotAfter time from date/time components.
 
Error setNotAfter (std::string_view timestamp)
 Set the NotAfter time from an ISO 8601 string.
 
const charnotAfter () const
 Get the NotAfter time as an ISO 8601 string.
 

Static Public Member Functions

static Result< ValidityPeriodfromStrings (std::string_view notBefore, std::string_view notAfter)
 Create a ValidityPeriod from ISO 8601 format strings.
 
static Result< ValidityPeriodfromWire (const uint8_t *buf, size_t len, size_t *bytesRead=nullptr)
 Decode a ValidityPeriod from TLV wire format.
 

Detailed Description

Validity period.

Represents a certificate's validity period. Consists of two timestamps: NotBefore and NotAfter. Timestamps are expressed in ISO 8601-1:2019 compact format (YYYYMMDDThhmmss).

vp.setNotBefore(2024, 1, 1, 0, 0, 0);
vp.setNotAfter(2025, 12, 31, 23, 59, 59);
if (vp.isValid()) {
printf("Certificate is valid now\n");
}
Validity period.
Result type template.
Definition common.hpp:147

Definition at line 43 of file certificate.hpp.

Constructor & Destructor Documentation

◆ ValidityPeriod()

ndn::ValidityPeriod::ValidityPeriod ( )
default

Default constructor.

Initialized with NotBefore=approximate current time, NotAfter=approximate 1 year later

Member Function Documentation

◆ encode()

Error ndn::ValidityPeriod::encode ( uint8_t buf,
size_t  bufSize,
size_t encodedLen 
) const

Encode the ValidityPeriod to TLV wire format.

Parameters
bufOutput buffer
bufSizeBuffer size
encodedLenStores the number of encoded bytes
Returns
Error::Success on success

Definition at line 145 of file certificate.cpp.

References ndn::tlv::NotAfter, ndn::tlv::NotBefore, ndn::TlvEncoder::size(), ndn::VALIDITY_TIMESTAMP_SIZE, ndn::tlv::ValidityPeriod, and ndn::TlvEncoder::writeTlv().

◆ equals()

bool ndn::ValidityPeriod::equals ( const ValidityPeriod other) const

Check equality of two validity periods.

Definition at line 213 of file certificate.cpp.

References ndn::VALIDITY_TIMESTAMP_SIZE.

◆ fromStrings()

Result< ValidityPeriod > ndn::ValidityPeriod::fromStrings ( std::string_view  notBefore,
std::string_view  notAfter 
)
static

Create a ValidityPeriod from ISO 8601 format strings.

Parameters
notBeforeStart time (YYYYMMDDThhmmss format)
notAfterEnd time (YYYYMMDDThhmmss format)
Returns
ValidityPeriod on success, error on failure

Definition at line 76 of file certificate.cpp.

References notAfter(), notBefore(), and ndn::VALIDITY_TIMESTAMP_SIZE.

◆ fromWire()

Result< ValidityPeriod > ndn::ValidityPeriod::fromWire ( const uint8_t buf,
size_t  len,
size_t bytesRead = nullptr 
)
static

Decode a ValidityPeriod from TLV wire format.

Parameters
bufInput buffer
lenBuffer length
bytesReadStores the number of bytes read (ignored if nullptr)
Returns
ValidityPeriod on success, error on failure

Definition at line 90 of file certificate.cpp.

References ndn::tlv::NotAfter, ndn::tlv::NotBefore, ndn::TlvDecoder::position(), ndn::TlvDecoder::readBytes(), ndn::TlvDecoder::readTlvHeader(), ndn::VALIDITY_TIMESTAMP_SIZE, and ndn::tlv::ValidityPeriod.

◆ isValidAt()

bool ndn::ValidityPeriod::isValidAt ( std::string_view  currentTimestamp) const

Check if the current time is within the validity period.

Parameters
currentTimestampCurrent time (YYYYMMDDThhmmss format)
Returns
true if within the validity period

Definition at line 204 of file certificate.cpp.

References ndn::VALIDITY_TIMESTAMP_SIZE.

Referenced by ndn::Certificate::isValidAt().

◆ notAfter()

const char * ndn::ValidityPeriod::notAfter ( ) const
inline

Get the NotAfter time as an ISO 8601 string.

Returns
15-character timestamp string (not null-terminated)

Definition at line 136 of file certificate.hpp.

Referenced by fromStrings().

◆ notBefore()

const char * ndn::ValidityPeriod::notBefore ( ) const
inline

Get the NotBefore time as an ISO 8601 string.

Returns
15-character timestamp string (not null-terminated)

Definition at line 112 of file certificate.hpp.

Referenced by fromStrings().

◆ setNotAfter() [1/2]

Error ndn::ValidityPeriod::setNotAfter ( std::string_view  timestamp)

Set the NotAfter time from an ISO 8601 string.

Parameters
timestampString in YYYYMMDDThhmmss format
Returns
Error::Success on success

Definition at line 196 of file certificate.cpp.

References ndn::VALIDITY_TIMESTAMP_SIZE.

◆ setNotAfter() [2/2]

Error ndn::ValidityPeriod::setNotAfter ( uint16_t  year,
uint8_t  month,
uint8_t  day,
uint8_t  hour,
uint8_t  minute,
uint8_t  second 
)

Set the NotAfter time from date/time components.

Definition at line 190 of file certificate.cpp.

◆ setNotBefore() [1/2]

Error ndn::ValidityPeriod::setNotBefore ( std::string_view  timestamp)

Set the NotBefore time from an ISO 8601 string.

Parameters
timestampString in YYYYMMDDThhmmss format
Returns
Error::Success on success

Definition at line 182 of file certificate.cpp.

References ndn::VALIDITY_TIMESTAMP_SIZE.

◆ setNotBefore() [2/2]

Error ndn::ValidityPeriod::setNotBefore ( uint16_t  year,
uint8_t  month,
uint8_t  day,
uint8_t  hour,
uint8_t  minute,
uint8_t  second 
)

Set the NotBefore time from date/time components.

Parameters
yearYear (e.g., 2024)
monthMonth (1-12)
dayDay (1-31)
hourHour (0-23)
minuteMinute (0-59)
secondSecond (0-59)
Returns
Error::Success on success

Definition at line 176 of file certificate.cpp.


The documentation for this class was generated from the following files: