From 1015d1fd053e4bcc792bb41eca225ef3ccc10fc4 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Mon, 8 Jun 2015 11:57:21 +0200 Subject: simplified asn1_get_time_der --- lib/decoding.c | 47 ++++++++++++++++++++++++++++++----------------- lib/libtasn1.h | 2 +- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/lib/decoding.c b/lib/decoding.c index 55a9b00..bb5f68b 100644 --- a/lib/decoding.c +++ b/lib/decoding.c @@ -275,22 +275,13 @@ asn1_get_octet_der (const unsigned char *der, int der_len, return ASN1_SUCCESS; } -/** - * asn1_get_time_der: - * @type: %ASN1_ETYPE_GENERALIZED_TIME or %ASN1_ETYPE_UTC_TIME - * @der: DER data to decode containing the time - * @der_len: Length of DER data to decode. - * @ret_len: Output variable containing the length of the DER data. - * @str: Pre-allocated output buffer to put the textual time in. - * @str_size: Length of pre-allocated output buffer. - * @flags: Zero or %ASN1_DECODE_FLAG_STRICT_DER - * - * Converts a DER encoded time object to its textual form. + +/* As with asn1_get_time_der(). * - * Returns: %ASN1_SUCCESS on success, or an error. - **/ -int -asn1_get_time_der (unsigned type, const unsigned char *der, int der_len, int *ret_len, + * @flags: Zero or %ASN1_DECODE_FLAG_STRICT_DER + */ +static int +_asn1_get_time_der (unsigned type, const unsigned char *der, int der_len, int *ret_len, char *str, int str_size, unsigned flags) { int len_len, str_len; @@ -340,7 +331,7 @@ asn1_get_time_der (unsigned type, const unsigned char *der, int der_len, int *re } warn(); - return ASN1_DER_ERROR; + return ASN1_DER_ERROR; } } @@ -357,6 +348,28 @@ asn1_get_time_der (unsigned type, const unsigned char *der, int der_len, int *re return ASN1_SUCCESS; } +/** + * asn1_get_time_der: + * @type: %ASN1_ETYPE_GENERALIZED_TIME or %ASN1_ETYPE_UTC_TIME + * @der: DER data to decode containing the time + * @der_len: Length of DER data to decode. + * @ret_len: Output variable containing the length of the DER data. + * @str: Pre-allocated output buffer to put the textual time in. + * @str_size: Length of pre-allocated output buffer. + * + * Performs basic checks in the DER encoded time object and returns its textual form. + * The textual form will be in the YYYYMMDD000000Z format for GeneralizedTime + * and YYMMDD000000Z for UTCTime. + * + * Returns: %ASN1_SUCCESS on success, or an error. + **/ +int +asn1_get_time_der (unsigned type, const unsigned char *der, int der_len, int *ret_len, + char *str, int str_size) +{ + return _asn1_get_time_der(type, der, der_len, ret_len, str, str_size, ASN1_DECODE_FLAG_STRICT_DER); +} + /** * asn1_get_objectid_der: * @der: DER data to decode containing the OBJECT IDENTIFIER @@ -1267,7 +1280,7 @@ asn1_der_decoding2 (asn1_node *element, const void *ider, int *max_ider_len, case ASN1_ETYPE_GENERALIZED_TIME: case ASN1_ETYPE_UTC_TIME: result = - asn1_get_time_der (type_field (p->type), der + counter, ider_len, &len2, temp, + _asn1_get_time_der (type_field (p->type), der + counter, ider_len, &len2, temp, sizeof (temp) - 1, flags); if (result != ASN1_SUCCESS) { diff --git a/lib/libtasn1.h b/lib/libtasn1.h index 364ce4e..6dcccc6 100644 --- a/lib/libtasn1.h +++ b/lib/libtasn1.h @@ -381,7 +381,7 @@ extern "C" extern ASN1_API int asn1_get_time_der (unsigned type, const unsigned char *der, int der_len, int *ret_len, - char *str, int str_size, unsigned flags); + char *str, int str_size); /* Compatibility types */ -- cgit v1.2.1