aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/asn1/asn1.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/asn1/asn1.c')
-rw-r--r--src/libstrongswan/asn1/asn1.c59
1 files changed, 23 insertions, 36 deletions
diff --git a/src/libstrongswan/asn1/asn1.c b/src/libstrongswan/asn1/asn1.c
index 2b811cccf..3692d67a6 100644
--- a/src/libstrongswan/asn1/asn1.c
+++ b/src/libstrongswan/asn1/asn1.c
@@ -311,16 +311,31 @@ time_t asn1totime(const chunk_t *utctime, asn1_t type)
}
/**
- * Initializes the internal context of the ASN.1 parser
+ * Convert a date into ASN.1 UTCTIME or GENERALIZEDTIME format
*/
-void asn1_init(asn1_ctx_t *ctx, chunk_t blob, u_int level0,
- bool implicit, bool private)
+chunk_t timetoasn1(const time_t *time, asn1_t type)
{
- ctx->blobs[0] = blob;
- ctx->level0 = level0;
- ctx->implicit = implicit;
- ctx->private = private;
- memset(ctx->loopAddr, '\0', sizeof(ctx->loopAddr));
+ int offset;
+ const char *format;
+ char buf[BUF_LEN];
+ chunk_t formatted_time;
+ struct tm *t = gmtime(time);
+
+ if (type == ASN1_GENERALIZEDTIME)
+ {
+ format = "%04d%02d%02d%02d%02d%02dZ";
+ offset = 1900;
+ }
+ else /* ASN1_UTCTIME */
+ {
+ format = "%02d%02d%02d%02d%02d%02dZ";
+ offset = (t->tm_year < 100)? 0 : -100;
+ }
+ snprintf(buf, sizeof(buf), format, t->tm_year + offset,
+ t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
+ formatted_time.ptr = buf;
+ formatted_time.len = strlen(buf);
+ return asn1_simple_object(type, formatted_time);
}
/**
@@ -737,34 +752,6 @@ chunk_t asn1_integer_from_mpz(const mpz_t value)
}
/**
- * convert a date into ASN.1 UTCTIME or GENERALIZEDTIME format
- */
-chunk_t timetoasn1(const time_t *time, asn1_t type)
-{
- int offset;
- const char *format;
- char buf[32];
- chunk_t formatted_time;
- struct tm *t = gmtime(time);
-
- if (type == ASN1_GENERALIZEDTIME)
- {
- format = "%04d%02d%02d%02d%02d%02dZ";
- offset = 1900;
- }
- else /* ASN1_UTCTIME */
- {
- format = "%02d%02d%02d%02d%02d%02dZ";
- offset = (t->tm_year < 100)? 0 : -100;
- }
- snprintf(buf, sizeof(buf), format, t->tm_year + offset,
- t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
- formatted_time.ptr = buf;
- formatted_time.len = strlen(buf);
- return asn1_simple_object(type, formatted_time);
-}
-
-/**
* ASN.1 definition of time
*/
static const asn1Object_t timeObjects[] = {