QSC Post Quantum Cryptographic Library 1.1.0.2 (B2)
A post quantum secure library written in Ansi C
Loading...
Searching...
No Matches
x509time.h File Reference

X.509 time decoding, parsing, comparison, and validity helpers. More...

#include "qsccommon.h"
#include "x509types.h"

Go to the source code of this file.

Typedefs

typedef qsc_asn1_time qsc_x509_time
 Alias for the normalized ASN.1 time representation used by X.509 helpers.

Functions

QSC_EXPORT_API bool qsc_x509_time_decode (qsc_x509_time *out, const qsc_encoding_ber_element *elem)
 Decode an ASN.1 X.509 time element.
QSC_EXPORT_API bool qsc_x509_time_parse_utctime (const char *s, size_t len, qsc_x509_time *out)
 Parse a UTCTime string.
QSC_EXPORT_API bool qsc_x509_time_parse_generalizedtime (const char *s, size_t len, qsc_x509_time *out)
 Parse a GeneralizedTime string.
QSC_EXPORT_API qsc_asn1_status qsc_x509_validity_decode (qsc_x509_validity *validity, const qsc_encoding_ber_element *elem)
 Decode a certificate Validity sequence.
QSC_EXPORT_API int32_t qsc_x509_time_compare (const qsc_x509_time *a, const qsc_x509_time *b)
 Compare two X.509 time values.
QSC_EXPORT_API bool qsc_x509_time_is_valid (const qsc_x509_time *time)
 Test whether a normalized X.509 time value is structurally valid.
QSC_EXPORT_API bool qsc_x509_validity_is_valid (const qsc_x509_validity *validity, const qsc_x509_time *tnow)
 Test whether a validity interval is current at a supplied time.

Detailed Description

X.509 time decoding, parsing, comparison, and validity helpers.

This header defines the public interface used to decode and manipulate X.509 time values and certificate validity intervals. The X.509 time alias is mapped directly to the ASN.1 time representation used by the underlying encoding layer.

The interface supports decoding of ASN.1 Time elements, parsing of UTCTime and GeneralizedTime text forms, comparison of normalized time values, basic structural validity checks, and evaluation of whether a certificate validity interval is current at a supplied reference time.

Typedef Documentation

◆ qsc_x509_time

Alias for the normalized ASN.1 time representation used by X.509 helpers.

The X.509 time type is defined as a direct alias of qsc_asn1_time so that X.509 validity processing and ASN.1 time parsing operate on the same canonical structure.

Function Documentation

◆ qsc_x509_time_compare()

QSC_EXPORT_API int32_t qsc_x509_time_compare ( const qsc_x509_time * a,
const qsc_x509_time * b )

Compare two X.509 time values.

Performs an ordered comparison of two normalized time values.

Parameters
a[const][struct] The first time value.
b[const][struct] The second time value.
Returns
Returns a negative value if a is earlier than b, zero if the values are equal, or a positive value if a is later than b.

◆ qsc_x509_time_decode()

QSC_EXPORT_API bool qsc_x509_time_decode ( qsc_x509_time * out,
const qsc_encoding_ber_element * elem )

Decode an ASN.1 X.509 time element.

Decodes an ASN.1 time element and normalizes the result into the supplied X.509 time object. The input element may represent either a UTCTime or a GeneralizedTime value.

Parameters
out[struct] The destination decoded time object.
elem[const][struct] The ASN.1 element containing the encoded time value.
Returns
Returns true if decoding completed successfully; otherwise returns false.

◆ qsc_x509_time_is_valid()

QSC_EXPORT_API bool qsc_x509_time_is_valid ( const qsc_x509_time * time)

Test whether a normalized X.509 time value is structurally valid.

Checks that the supplied time object contains a valid normalized calendar and clock representation suitable for X.509 validity evaluation.

Parameters
time[const][struct] The time object to validate.
Returns
Returns true if the time object is valid; otherwise returns false.

◆ qsc_x509_time_parse_generalizedtime()

QSC_EXPORT_API bool qsc_x509_time_parse_generalizedtime ( const char * s,
size_t len,
qsc_x509_time * out )

Parse a GeneralizedTime string.

Parses a character string encoded in ASN.1 GeneralizedTime textual form and writes the normalized result to the supplied X.509 time object. The accepted form is exactly YYYYMMDDHHMMSSZ as required by DER.

Parameters
s[const] The input GeneralizedTime character buffer.
lenThe length of the input buffer in bytes.
out[struct] The destination parsed time object.
Returns
Returns true if parsing completed successfully; otherwise returns false.

◆ qsc_x509_time_parse_utctime()

QSC_EXPORT_API bool qsc_x509_time_parse_utctime ( const char * s,
size_t len,
qsc_x509_time * out )

Parse a UTCTime string.

Parses a character string encoded in ASN.1 UTCTime textual form and writes the normalized result to the supplied X.509 time object. The accepted form is exactly YYMMDDHHMMSSZ as required by DER.

Parameters
s[const] The input UTCTime character buffer.
lenThe length of the input buffer in bytes.
out[struct] The destination parsed time object.
Returns
Returns true if parsing completed successfully; otherwise returns false.

◆ qsc_x509_validity_decode()

QSC_EXPORT_API qsc_asn1_status qsc_x509_validity_decode ( qsc_x509_validity * validity,
const qsc_encoding_ber_element * elem )

Decode a certificate Validity sequence.

Decodes an ASN.1 Validity sequence and writes the notBefore and notAfter values to the supplied X.509 validity structure. The function accepts only a two-element DER Validity sequence and rejects intervals where notBefore is later than notAfter.

Parameters
validity[struct] The destination validity object.
elem[const][struct] The ASN.1 element containing the encoded Validity sequence.
Returns
[enum] Returns a qsc_asn1_status code.

◆ qsc_x509_validity_is_valid()

QSC_EXPORT_API bool qsc_x509_validity_is_valid ( const qsc_x509_validity * validity,
const qsc_x509_time * tnow )

Test whether a validity interval is current at a supplied time.

Evaluates whether the supplied reference time falls within the certificate validity interval described by the notBefore and notAfter fields.

Parameters
validity[const][struct] The certificate validity interval.
tnow[const][struct] The reference time used for evaluation.
Returns
Returns true if the reference time is within the validity interval; otherwise returns false.