CryptoAuthLib
Microchip CryptoAuthentication Library
atcacert_date.h
Go to the documentation of this file.
1 
28 #ifndef ATCACERT_DATE_H
29 #define ATCACERT_DATE_H
30 
31 #include <stddef.h>
32 #include "atcacert.h"
33 
34 
35 
36 // Inform function naming when compiling in C++
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
52 typedef struct atcacert_tm_utc_s
53 {
54  int tm_sec; // 0 to 59
55  int tm_min; // 0 to 59
56  int tm_hour; // 0 to 23
57  int tm_mday; // 1 to 31
58  int tm_mon; // 0 to 11
59  int tm_year; // years since 1900
61 
66 {
73 
74 #define DATEFMT_ISO8601_SEP_SIZE (20)
75 #define DATEFMT_RFC5280_UTC_SIZE (13)
76 #define DATEFMT_POSIX_UINT32_BE_SIZE (4)
77 #define DATEFMT_POSIX_UINT32_LE_SIZE (4)
78 #define DATEFMT_RFC5280_GEN_SIZE (15)
79 #define DATEFMT_MAX_SIZE DATEFMT_ISO8601_SEP_SIZE
80 #define ATCACERT_DATE_FORMAT_SIZES_COUNT 5
81 
83 
96  const atcacert_tm_utc_t* timestamp,
97  uint8_t* formatted_date,
98  size_t* formatted_date_size);
99 
111  const uint8_t* formatted_date,
112  size_t formatted_date_size,
113  atcacert_tm_utc_t* timestamp);
114 
126 int atcacert_date_enc_compcert(const atcacert_tm_utc_t * issue_date,
127  uint8_t expire_years,
128  uint8_t enc_dates[3]);
129 
143 int atcacert_date_dec_compcert(const uint8_t enc_dates[3],
144  atcacert_date_format_t expire_date_format,
145  atcacert_tm_utc_t* issue_date,
146  atcacert_tm_utc_t* expire_date);
147 
157 
159  uint8_t formatted_date[DATEFMT_ISO8601_SEP_SIZE]);
160 
161 int atcacert_date_dec_iso8601_sep(const uint8_t formatted_date[DATEFMT_ISO8601_SEP_SIZE],
162  atcacert_tm_utc_t* timestamp);
163 
165  uint8_t formatted_date[DATEFMT_RFC5280_UTC_SIZE]);
166 
167 int atcacert_date_dec_rfc5280_utc(const uint8_t formatted_date[DATEFMT_RFC5280_UTC_SIZE],
168  atcacert_tm_utc_t* timestamp);
169 
171  uint8_t formatted_date[DATEFMT_RFC5280_GEN_SIZE]);
172 
173 int atcacert_date_dec_rfc5280_gen(const uint8_t formatted_date[DATEFMT_RFC5280_GEN_SIZE],
174  atcacert_tm_utc_t* timestamp);
175 
177  uint8_t formatted_date[DATEFMT_POSIX_UINT32_BE_SIZE]);
178 
179 int atcacert_date_dec_posix_uint32_be(const uint8_t formatted_date[DATEFMT_POSIX_UINT32_BE_SIZE],
180  atcacert_tm_utc_t* timestamp);
181 
183  uint8_t formatted_date[DATEFMT_POSIX_UINT32_LE_SIZE]);
184 
185 int atcacert_date_dec_posix_uint32_le(const uint8_t formatted_date[DATEFMT_POSIX_UINT32_LE_SIZE],
186  atcacert_tm_utc_t* timestamp);
187 
188 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif
RFC 5280 (X.509) 4.1.2.5.2 GeneralizedTime format YYYYMMDDhhmmssZ.
Definition: atcacert_date.h:71
int atcacert_date_enc_rfc5280_gen(const atcacert_tm_utc_t *timestamp, uint8_t formatted_date[DATEFMT_RFC5280_GEN_SIZE])
Definition: atcacert_date.c:537
ISO8601 full date YYYY-MM-DDThh:mm:ssZ.
Definition: atcacert_date.h:67
atcacert_date_format_e
Definition: atcacert_date.h:65
int tm_sec
Definition: atcacert_date.h:54
int atcacert_date_get_max_date(atcacert_date_format_t format, atcacert_tm_utc_t *timestamp)
Return the maximum date available for the given format.
Definition: atcacert_date.c:102
int atcacert_date_enc_rfc5280_utc(const atcacert_tm_utc_t *timestamp, uint8_t formatted_date[DATEFMT_RFC5280_UTC_SIZE])
Definition: atcacert_date.c:402
int atcacert_date_dec_compcert(const uint8_t enc_dates[3], atcacert_date_format_t expire_date_format, atcacert_tm_utc_t *issue_date, atcacert_tm_utc_t *expire_date)
Decode the issue and expire dates from the format used by the compressed certificate.
Definition: atcacert_date.c:1047
int atcacert_date_enc_posix_uint32_be(const atcacert_tm_utc_t *timestamp, uint8_t formatted_date[DATEFMT_POSIX_UINT32_BE_SIZE])
Definition: atcacert_date.c:873
#define DATEFMT_POSIX_UINT32_LE_SIZE
Definition: atcacert_date.h:77
int tm_hour
Definition: atcacert_date.h:56
const size_t ATCACERT_DATE_FORMAT_SIZES[ATCACERT_DATE_FORMAT_SIZES_COUNT]
Definition: atcacert_date.c:32
RFC 5280 (X.509) 4.1.2.5.1 UTCTime format YYMMDDhhmmssZ.
Definition: atcacert_date.h:68
int tm_year
Definition: atcacert_date.h:59
#define DATEFMT_POSIX_UINT32_BE_SIZE
Definition: atcacert_date.h:76
#define DATEFMT_RFC5280_GEN_SIZE
Definition: atcacert_date.h:78
int tm_mday
Definition: atcacert_date.h:57
#define DATEFMT_RFC5280_UTC_SIZE
Definition: atcacert_date.h:75
POSIX (aka UNIX) date format. Seconds since Jan 1, 1970. 32 bit unsigned integer, little endian...
Definition: atcacert_date.h:70
#define ATCACERT_DATE_FORMAT_SIZES_COUNT
Definition: atcacert_date.h:80
int atcacert_date_dec_posix_uint32_le(const uint8_t formatted_date[DATEFMT_POSIX_UINT32_LE_SIZE], atcacert_tm_utc_t *timestamp)
Definition: atcacert_date.c:972
int atcacert_date_dec_rfc5280_utc(const uint8_t formatted_date[DATEFMT_RFC5280_UTC_SIZE], atcacert_tm_utc_t *timestamp)
Definition: atcacert_date.c:464
Definition: atcacert_date.h:52
enum atcacert_date_format_e atcacert_date_format_t
int atcacert_date_enc_iso8601_sep(const atcacert_tm_utc_t *timestamp, uint8_t formatted_date[DATEFMT_ISO8601_SEP_SIZE])
Definition: atcacert_date.c:248
int atcacert_date_enc(atcacert_date_format_t format, const atcacert_tm_utc_t *timestamp, uint8_t *formatted_date, size_t *formatted_date_size)
Format a timestamp according to the format type.
Definition: atcacert_date.c:40
int atcacert_date_enc_compcert(const atcacert_tm_utc_t *issue_date, uint8_t expire_years, uint8_t enc_dates[3])
Encode the issue and expire dates in the format used by the compressed certificate.
Definition: atcacert_date.c:991
int tm_mon
Definition: atcacert_date.h:58
int tm_min
Definition: atcacert_date.h:55
POSIX (aka UNIX) date format. Seconds since Jan 1, 1970. 32 bit unsigned integer, big endian...
Definition: atcacert_date.h:69
int atcacert_date_dec_iso8601_sep(const uint8_t formatted_date[DATEFMT_ISO8601_SEP_SIZE], atcacert_tm_utc_t *timestamp)
Definition: atcacert_date.c:312
Declarations common to all atcacert code.
int atcacert_date_enc_posix_uint32_le(const atcacert_tm_utc_t *timestamp, uint8_t formatted_date[DATEFMT_POSIX_UINT32_LE_SIZE])
Definition: atcacert_date.c:947
int atcacert_date_dec_posix_uint32_be(const uint8_t formatted_date[DATEFMT_POSIX_UINT32_BE_SIZE], atcacert_tm_utc_t *timestamp)
Definition: atcacert_date.c:928
int atcacert_date_dec_rfc5280_gen(const uint8_t formatted_date[DATEFMT_RFC5280_GEN_SIZE], atcacert_tm_utc_t *timestamp)
Definition: atcacert_date.c:591
struct atcacert_tm_utc_s atcacert_tm_utc_t
int atcacert_date_dec(atcacert_date_format_t format, const uint8_t *formatted_date, size_t formatted_date_size, atcacert_tm_utc_t *timestamp)
Parse a formatted timestamp according to the specified format.
Definition: atcacert_date.c:74
#define DATEFMT_ISO8601_SEP_SIZE
Definition: atcacert_date.h:74