diff options
-rw-r--r-- | src/libstrongswan/types.c | 31 | ||||
-rw-r--r-- | src/libstrongswan/types.h | 38 |
2 files changed, 43 insertions, 26 deletions
diff --git a/src/libstrongswan/types.c b/src/libstrongswan/types.c index 5b9245cf9..d61ed8bd5 100644 --- a/src/libstrongswan/types.c +++ b/src/libstrongswan/types.c @@ -45,23 +45,10 @@ mapping_t status_m[] = { {MAPPING_END, NULL} }; -#define UNDEFINED_TIME 0 - -/** - * @brief Display a date either in local or UTC time - * - * @param buf buffer where displayed time will be written - * @param buflen buffer length - * @param time time to be displayed - * @param utc UTC (TRUE) or local time (FALSE) - * - */ -void timetoa(char *buf, size_t buflen, const time_t *time, bool utc); - /** * Empty chunk. */ -chunk_t CHUNK_INITIALIZER = {NULL,0}; +chunk_t CHUNK_INITIALIZER = { NULL, 0 }; /** * Described in header. @@ -106,10 +93,18 @@ chunk_t chunk_alloc(size_t bytes) */ bool chunk_equals(chunk_t a, chunk_t b) { - return a.len == b.len && - a.ptr != NULL && - b.ptr != NULL && - memcmp(a.ptr, b.ptr, a.len) == 0; + return a.ptr != NULL && b.ptr != NULL && + a.len == b.len && memeq(a.ptr, b.ptr, a.len); +} + +/** + * Described in header. + */ +bool chunk_equals_or_null(chunk_t a, chunk_t b) +{ + if (a.ptr == NULL || b.ptr == NULL) + return TRUE; + return a.len == b.len && memeq(a.ptr, b.ptr, a.len); } /** diff --git a/src/libstrongswan/types.h b/src/libstrongswan/types.h index 74f0cbf7a..ed67913cf 100644 --- a/src/libstrongswan/types.h +++ b/src/libstrongswan/types.h @@ -123,6 +123,23 @@ typedef enum certpolicy { } certpolicy_t; /** + * RFC 2459 CRL reason codes + */ + +/* TODO extern enum_names crl_reason_names; */ + +typedef enum { + REASON_UNSPECIFIED = 0, + REASON_KEY_COMPROMISE = 1, + REASON_CA_COMPROMISE = 2, + REASON_AFFILIATION_CHANGED = 3, + REASON_SUPERSEDED = 4, + REASON_CESSATION_OF_OPERATON = 5, + REASON_CERTIFICATE_HOLD = 6, + REASON_REMOVE_FROM_CRL = 8 +} crl_reason_t; + +/** * String mappings for type status_t. */ extern mapping_t status_m[]; @@ -154,17 +171,16 @@ struct chunk_t { /** * Pointer to start of data */ - u_char *ptr; - - /** - * Length of data in bytes - */ - size_t len; + u_char *ptr; + + /** + * Length of data in bytes + */ + size_t len; }; /** - * {NULL, 0}-chunk, handy for initialization - * of chunks. + * used to initialize a chunk to { NULL, 0 }. */ extern chunk_t CHUNK_INITIALIZER; @@ -195,6 +211,12 @@ chunk_t chunk_alloc(size_t bytes); bool chunk_equals(chunk_t a, chunk_t b); /** + * Compare two chunks for equality, + * NULL chunks are always equal. + */ +bool chunk_equals_or_null(chunk_t a, chunk_t b); + +/** * Print a chunk in hexadecimal form * with each byte separated by a colon */ |