FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* Set Date validity from now until now + daysValid
 * return size in bytes written to output, 0 on error */
Set Date validity from now until now + daysValid
return size in bytes written to output, 0 on error
Set Date validity from now until now + daysValid return size in bytes written to output 0 on error
static int SetValidity(byte* output, int daysValid)
{
    byte before[MAX_DATE_SIZE];
    byte  after[MAX_DATE_SIZE];
    int beforeSz;
    int afterSz;
    int seqSz;
    time_t now;
    time_t then;
    struct tm* tmpTime;
    struct tm* expandedTime;
    struct tm localTime;
#if defined(NEED_TMP_TIME)
    struct tm tmpTimeStorage;
    tmpTime = &tmpTimeStorage;
#else
    tmpTime = NULL;
#endif
    (void)tmpTime;
    now = XTIME(0);
    before[0] = ASN_GENERALIZED_TIME;
    beforeSz = SetLength(ASN_GEN_TIME_SZ, before + 1) + 1;  
    then = now - 86400;
    expandedTime = XGMTIME(&then, tmpTime);
    if (expandedTime == NULL) {
        WOLFSSL_MSG("XGMTIME failed");
        return 0;   
    }
    localTime = *expandedTime;
    localTime.tm_year += 1900;
    localTime.tm_mon +=    1;
    SetTime(&localTime, before + beforeSz);
    beforeSz += ASN_GEN_TIME_SZ;
    after[0] = ASN_GENERALIZED_TIME;
    afterSz  = SetLength(ASN_GEN_TIME_SZ, after + 1) + 1;  
    then = now + (daysValid * (time_t)86400);
    expandedTime = XGMTIME(&then, tmpTime);
    if (expandedTime == NULL) {
        WOLFSSL_MSG("XGMTIME failed");
        return 0;   
    }
    localTime = *expandedTime;
    localTime.tm_year += 1900;
    localTime.tm_mon  +=    1;
    SetTime(&localTime, after + afterSz);
    afterSz += ASN_GEN_TIME_SZ;
    seqSz = SetSequence(beforeSz + afterSz, output);
    XMEMCPY(output + seqSz, before, beforeSz);
    XMEMCPY(output + seqSz + beforeSz, after, afterSz);
    return seqSz + beforeSz + afterSz;
}
static int SetValidity ( byte * output , int daysValid ) { byte before [ MAX_DATE_SIZE ] ; byte after [ MAX_DATE_SIZE ] ; int beforeSz ; int afterSz ; int seqSz ; time_t now ; time_t then ; struct tm * tmpTime ; struct tm * expandedTime ; struct tm localTime ; #if defined ( NEED_TMP_TIME ) struct tm tmpTimeStorage ; tmpTime = & tmpTimeStorage ; #else tmpTime = NULL ; #endif ( void ) tmpTime ; now = XTIME ( 0 ) ; before [ 0 ] = ASN_GENERALIZED_TIME ; beforeSz = SetLength ( ASN_GEN_TIME_SZ , before + 1 ) + 1 ; then = now - 86400 ; expandedTime = XGMTIME ( & then , tmpTime ) ; if ( expandedTime == NULL ) { WOLFSSL_MSG ( " " ) ; return 0 ; } localTime = * expandedTime ; localTime . tm_year += 1900 ; localTime . tm_mon += 1 ; SetTime ( & localTime , before + beforeSz ) ; beforeSz += ASN_GEN_TIME_SZ ; after [ 0 ] = ASN_GENERALIZED_TIME ; afterSz = SetLength ( ASN_GEN_TIME_SZ , after + 1 ) + 1 ; then = now + ( daysValid * ( time_t ) 86400 ) ; expandedTime = XGMTIME ( & then , tmpTime ) ; if ( expandedTime == NULL ) { WOLFSSL_MSG ( " " ) ; return 0 ; } localTime = * expandedTime ; localTime . tm_year += 1900 ; localTime . tm_mon += 1 ; SetTime ( & localTime , after + afterSz ) ; afterSz += ASN_GEN_TIME_SZ ; seqSz = SetSequence ( beforeSz + afterSz , output ) ; XMEMCPY ( output + seqSz , before , beforeSz ) ; XMEMCPY ( output + seqSz + beforeSz , after , afterSz ) ; return seqSz + beforeSz + afterSz ; }
Set Date validity from now until now + daysValid
 return size in bytes written to output, 0 on error
Set Date validity from now until now + daysValid return size in bytes written to output 0 on error
/* for use with gmtime_r */ /* before now */ /* gen tag */ /* subtract 1 day of seconds for more compliance */ /* error */ /* adjust */ /* gen tag */ /* add daysValid of seconds */ /* error */ /* adjust */ /* headers and output */