1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */ 2 /* SPDX-License-Identifier: Unlicense */ 3 #include "tomcrypt_private.h" 4 5 /** 6 @file der_length_utctime.c 7 ASN.1 DER, get length of GeneralizedTime, Steffen Jaeckel 8 Based on der_length_utctime.c 9 */ 10 11 #ifdef LTC_DER 12 13 /** 14 Gets length of DER encoding of GeneralizedTime 15 @param gtime The GeneralizedTime structure to get the size of 16 @param outlen [out] The length of the DER encoding 17 @return CRYPT_OK if successful 18 */ der_length_generalizedtime(const ltc_generalizedtime * gtime,unsigned long * outlen)19int der_length_generalizedtime(const ltc_generalizedtime *gtime, unsigned long *outlen) 20 { 21 LTC_ARGCHK(outlen != NULL); 22 LTC_ARGCHK(gtime != NULL); 23 24 if (gtime->fs == 0) { 25 /* we encode as YYYYMMDDhhmmssZ */ 26 *outlen = 2 + 14 + 1; 27 } else { 28 unsigned long len = 2 + 14 + 1; 29 unsigned fs = gtime->fs; 30 do { 31 fs /= 10; 32 len++; 33 } while(fs != 0); 34 if (gtime->off_hh == 0 && gtime->off_mm == 0) { 35 /* we encode as YYYYMMDDhhmmss.fsZ */ 36 len += 1; 37 } 38 else { 39 /* we encode as YYYYMMDDhhmmss.fs{+|-}hh'mm' */ 40 len += 5; 41 } 42 *outlen = len; 43 } 44 45 return CRYPT_OK; 46 } 47 48 #endif 49