moved timetoa() from asn1.c to types.c
[strongswan.git] / src / libstrongswan / asn1 / asn1.c
index 662f7fc..bde6ab2 100644 (file)
 #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,26 +210,6 @@ bool is_printablestring(chunk_t str)
 }
 
 /**
- * Display a date either in local or UTC time
- * TODO: Does not seem to be thread safe
- */
-char* timetoa(const time_t *time, bool utc)
-{
-       static char buf[30];
-
-       if (*time == 0)
-               sprintf(buf, "--- -- --:--:--%s----", (utc)?" UTC ":" ");
-       else
-       {
-               struct tm *t = (utc)? gmtime(time) : localtime(time);
-               sprintf(buf, "%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);
-       }
-       return buf;
-}
-
-/**
  * Converts ASN.1 UTCTIME or GENERALIZEDTIME into calender time
  */
 time_t asn1totime(const chunk_t *utctime, asn1_t type)
@@ -349,8 +324,13 @@ static void debug_asn1_simple_object(chunk_t object, asn1_t type)
                        return;
                case ASN1_UTCTIME:
                case ASN1_GENERALIZEDTIME:
-                       time = asn1totime(&object, type);
-                       logger->log(logger, CONTROL|LEVEL1, "  '%s'", timetoa(&time, TRUE));
+                       {
+                               char buf[TIMETOA_BUF];
+                               time_t time = asn1totime(&object, type);
+
+                               timetoa(buf, TIMETOA_BUF, &time, TRUE);
+                               logger->log(logger, CONTROL|LEVEL1, "  '%s'", buf);
+                       }
                        return;
                default:
                        break;