diff options
Diffstat (limited to 'src/libstrongswan')
-rw-r--r-- | src/libstrongswan/asn1/asn1.c | 24 | ||||
-rw-r--r-- | src/libstrongswan/asn1/asn1.h | 1 | ||||
-rw-r--r-- | src/libstrongswan/types.c | 40 | ||||
-rw-r--r-- | src/libstrongswan/types.h | 12 |
4 files changed, 53 insertions, 24 deletions
diff --git a/src/libstrongswan/asn1/asn1.c b/src/libstrongswan/asn1/asn1.c index c52fb2dce..bde6ab22e 100644 --- a/src/libstrongswan/asn1/asn1.c +++ b/src/libstrongswan/asn1/asn1.c @@ -17,16 +17,11 @@ #include <string.h> #include <time.h> +#include "types.h" #include "asn1.h" #include <utils/logger_manager.h> -/* Names of the months */ -static const char* months[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" -}; - /* some common prefabricated ASN.1 constants */ static u_char ASN1_INTEGER_0_str[] = { 0x02, 0x00 }; static u_char ASN1_INTEGER_1_str[] = { 0x02, 0x01, 0x01 }; @@ -215,23 +210,6 @@ bool is_printablestring(chunk_t str) } /** - * Display a date either in local or UTC time - */ -void timetoa(char *buf, size_t buflen, const time_t *time, bool utc) -{ - if (*time == 0) - snprintf(buf, buflen, "--- -- --:--:--%s----", (utc)?" UTC ":" "); - else - { - struct tm *t = (utc)? gmtime(time) : localtime(time); - - snprintf(buf, buflen, "%s %02d %02d:%02d:%02d%s%04d", - months[t->tm_mon], t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, - (utc)?" UTC ":" ", t->tm_year + 1900); - } -} - -/** * Converts ASN.1 UTCTIME or GENERALIZEDTIME into calender time */ time_t asn1totime(const chunk_t *utctime, asn1_t type) diff --git a/src/libstrongswan/asn1/asn1.h b/src/libstrongswan/asn1/asn1.h index ee905be4d..041e8fa59 100644 --- a/src/libstrongswan/asn1/asn1.h +++ b/src/libstrongswan/asn1/asn1.h @@ -133,6 +133,5 @@ extern u_char* build_asn1_object(chunk_t *object, asn1_t type, size_t datalen); extern chunk_t asn1_integer_from_mpz(const mpz_t value); extern chunk_t asn1_simple_object(asn1_t tag, chunk_t content); extern chunk_t asn1_wrap(asn1_t type, const char *mode, ...); -extern chunk_t timetoasn1(const time_t *time, asn1_t type); #endif /* _ASN1_H */ diff --git a/src/libstrongswan/types.c b/src/libstrongswan/types.c index 228a71d26..5b9245cf9 100644 --- a/src/libstrongswan/types.c +++ b/src/libstrongswan/types.c @@ -21,6 +21,7 @@ */ #include <string.h> +#include <time.h> #include "types.h" @@ -44,6 +45,19 @@ 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. */ @@ -138,3 +152,29 @@ void *clalloc(void * pointer, size_t size) return (data); } + +/* + * Names of the months used by timetoa() + */ +static const char* months[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +/* + * Described in header file + */ +void timetoa(char *buf, size_t buflen, const time_t *time, bool utc) +{ + if (*time == UNDEFINED_TIME) + snprintf(buf, buflen, "--- -- --:--:--%s----", (utc)?" UTC ":" "); + else + { + struct tm *t = (utc)? gmtime(time) : localtime(time); + + snprintf(buf, buflen, "%s %02d %02d:%02d:%02d%s%04d", + months[t->tm_mon], t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, + (utc)?" UTC ":" ", t->tm_year + 1900); + } +} + diff --git a/src/libstrongswan/types.h b/src/libstrongswan/types.h index ba59b225a..7be418b6d 100644 --- a/src/libstrongswan/types.h +++ b/src/libstrongswan/types.h @@ -193,5 +193,17 @@ void chunk_to_hex(char *buf, size_t buflen, chunk_t chunk); */ void *clalloc(void *pointer, size_t size); +#define UNDEFINED_TIME 0 + +/** + * @brief Display a date either in local or UTC time + * + * @param buf buffer where displayed time will be written to + * @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); #endif /*TYPES_H_*/ |