1 // SPDX-License-Identifier: BSD-2-Clause 2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis 3 * 4 * LibTomCrypt is a library that provides various cryptographic 5 * algorithms in a highly modular and flexible manner. 6 * 7 * The library is free for all purposes without any express 8 * guarantee it works. 9 */ 10 #include "tomcrypt_private.h" 11 12 /** 13 @file der_length_utctime.c 14 ASN.1 DER, get length of GeneralizedTime, Steffen Jaeckel 15 Based on der_length_utctime.c 16 */ 17 18 #ifdef LTC_DER 19 20 /** 21 Gets length of DER encoding of GeneralizedTime 22 @param gtime The GeneralizedTime structure to get the size of 23 @param outlen [out] The length of the DER encoding 24 @return CRYPT_OK if successful 25 */ der_length_generalizedtime(const ltc_generalizedtime * gtime,unsigned long * outlen)26int der_length_generalizedtime(const ltc_generalizedtime *gtime, unsigned long *outlen) 27 { 28 LTC_ARGCHK(outlen != NULL); 29 LTC_ARGCHK(gtime != NULL); 30 31 if (gtime->fs == 0) { 32 /* we encode as YYYYMMDDhhmmssZ */ 33 *outlen = 2 + 14 + 1; 34 } else { 35 unsigned long len = 2 + 14 + 1; 36 unsigned fs = gtime->fs; 37 do { 38 fs /= 10; 39 len++; 40 } while(fs != 0); 41 if (gtime->off_hh == 0 && gtime->off_mm == 0) { 42 /* we encode as YYYYMMDDhhmmss.fsZ */ 43 len += 1; 44 } 45 else { 46 /* we encode as YYYYMMDDhhmmss.fs{+|-}hh'mm' */ 47 len += 5; 48 } 49 *outlen = len; 50 } 51 52 return CRYPT_OK; 53 } 54 55 #endif 56 57 /* ref: $Format:%D$ */ 58 /* git commit: $Format:%H$ */ 59 /* commit time: $Format:%ai$ */ 60