Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
sectime.c File Reference
#include "prlong.h"
#include "prtime.h"
#include "secder.h"
#include "cert.h"
#include "secitem.h"
#include "secerr.h"

Go to the source code of this file.

Functions

static char * DecodeUTCTime2FormattedAscii (SECItem *utcTimeDER, char *format)
static char * DecodeGeneralizedTime2FormattedAscii (SECItem *generalizedTimeDER, char *format)
char * DER_UTCTimeToAscii (SECItem *utcTime)
char * DER_UTCDayToAscii (SECItem *utctime)
char * DER_GeneralizedDayToAscii (SECItem *gentime)
char * DER_TimeChoiceDayToAscii (SECItem *timechoice)
CERTValidity * CERT_CreateValidity (int64 notBefore, int64 notAfter)
SECStatus CERT_CopyValidity (PRArenaPool *arena, CERTValidity *to, CERTValidity *from)
void CERT_DestroyValidity (CERTValidity *v)
char * CERT_UTCTime2FormattedAscii (int64 utcTime, char *format)
char * CERT_GenTime2FormattedAscii (int64 genTime, char *format)
SECStatus DER_DecodeTimeChoice (PRTime *output, const SECItem *input)
SECStatus DER_EncodeTimeChoice (PRArenaPool *arena, SECItem *output, PRTime input)

Variables

static const PRTime January1st2050 = LL_INIT(0x0008f81e, 0x1b098000)
const SEC_ASN1Template CERT_TimeChoiceTemplate []
const SEC_ASN1Template CERT_ValidityTemplate []

Function Documentation

SECStatus CERT_CopyValidity ( PRArenaPool arena,
CERTValidity *  to,
CERTValidity *  from 
)

Definition at line 145 of file sectime.c.

{
    SECStatus rv;

    CERT_DestroyValidity(to);
    to->arena = arena;
    
    rv = SECITEM_CopyItem(arena, &to->notBefore, &from->notBefore);
    if (rv) return rv;
    rv = SECITEM_CopyItem(arena, &to->notAfter, &from->notAfter);
    return rv;
}
CERTValidity* CERT_CreateValidity ( int64  notBefore,
int64  notAfter 
)

Definition at line 113 of file sectime.c.

{
    CERTValidity *v;
    int rv;
    PRArenaPool *arena;

    if (notBefore > notAfter) {
       PORT_SetError(SEC_ERROR_INVALID_ARGS);
       return NULL;
    }
    arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
    
    if ( !arena ) {
       return(0);
    }
    
    v = (CERTValidity*) PORT_ArenaZAlloc(arena, sizeof(CERTValidity));
    if (v) {
       v->arena = arena;
       rv = DER_EncodeTimeChoice(arena, &v->notBefore, notBefore);
       if (rv) goto loser;
       rv = DER_EncodeTimeChoice(arena, &v->notAfter, notAfter);
       if (rv) goto loser;
    }
    return v;

  loser:
    CERT_DestroyValidity(v);
    return 0;
}
void CERT_DestroyValidity ( CERTValidity *  v)

Definition at line 159 of file sectime.c.

{
    if (v && v->arena) {
       PORT_FreeArena(v->arena, PR_FALSE);
    }
    return;
}
char* CERT_GenTime2FormattedAscii ( int64  genTime,
char *  format 
)

Definition at line 185 of file sectime.c.

{
    PRExplodedTime printableTime; 
    char *timeString;
   
    /* Decompose time into components */
    PR_ExplodeTime(genTime, PR_GMTParameters, &printableTime);
    
    timeString = (char *)PORT_Alloc(100);

    if ( timeString ) {
        PR_FormatTime( timeString, 100, format, &printableTime );
    }
    
    return (timeString);
}
char* CERT_UTCTime2FormattedAscii ( int64  utcTime,
char *  format 
)

Definition at line 168 of file sectime.c.

{
    PRExplodedTime printableTime; 
    char *timeString;
   
    /* Converse time to local time and decompose it into components */
    PR_ExplodeTime(utcTime, PR_LocalTimeParameters, &printableTime);
    
    timeString = (char *)PORT_Alloc(100);

    if ( timeString ) {
        PR_FormatTime( timeString, 100, format, &printableTime );
    }
    
    return (timeString);
}
static char * DecodeGeneralizedTime2FormattedAscii ( SECItem *  generalizedTimeDER,
char *  format 
) [static]

Definition at line 223 of file sectime.c.

{
    PRTime generalizedTime;
    int rv;
   
    rv = DER_GeneralizedTimeToTime(&generalizedTime, generalizedTimeDER);
    if (rv) {
        return(NULL);
    }
    return (CERT_GeneralizedTime2FormattedAscii (generalizedTime, format));
}

Here is the call graph for this function:

static char * DecodeUTCTime2FormattedAscii ( SECItem *  utcTimeDER,
char *  format 
) [static]

Definition at line 207 of file sectime.c.

{
    int64 utcTime;
    int rv;
   
    rv = DER_UTCTimeToTime(&utcTime, utcTimeDER);
    if (rv) {
        return(NULL);
    }
    return (CERT_UTCTime2FormattedAscii (utcTime, format));
}

Here is the call graph for this function:

SECStatus DER_DecodeTimeChoice ( PRTime output,
const SECItem *  input 
)

Definition at line 238 of file sectime.c.

{
    switch (input->type) {
        case siGeneralizedTime:
            return DER_GeneralizedTimeToTime(output, input);

        case siUTCTime:
            return DER_UTCTimeToTime(output, input);

        default:
            PORT_SetError(SEC_ERROR_INVALID_ARGS);
            PORT_Assert(0);
            return SECFailure;
    }
}
SECStatus DER_EncodeTimeChoice ( PRArenaPool arena,
SECItem *  output,
PRTime  input 
)

Definition at line 257 of file sectime.c.

{
    if (LL_CMP(input, >, January1st2050)) {
        return DER_TimeToGeneralizedTimeArena(arena, output, input);
    } else {
        return DER_TimeToUTCTimeArena(arena, output, input);
    }
}
char* DER_GeneralizedDayToAscii ( SECItem *  gentime)

Definition at line 85 of file sectime.c.

{
    return (DecodeGeneralizedTime2FormattedAscii (gentime, "%a %b %d, %Y"));
}
char* DER_TimeChoiceDayToAscii ( SECItem *  timechoice)

Definition at line 93 of file sectime.c.

{
    switch (timechoice->type) {

    case siUTCTime:
        return DER_UTCDayToAscii(timechoice);

    case siGeneralizedTime:
        return DER_GeneralizedDayToAscii(timechoice);

    default:
        PORT_Assert(0);
        PORT_SetError(SEC_ERROR_INVALID_ARGS);
        return NULL;
    }
}
char* DER_UTCDayToAscii ( SECItem *  utctime)

Definition at line 77 of file sectime.c.

{
    return (DecodeUTCTime2FormattedAscii (utctime, "%a %b %d, %Y"));
}
char* DER_UTCTimeToAscii ( SECItem *  utcTime)

Definition at line 70 of file sectime.c.

{
    return (DecodeUTCTime2FormattedAscii (utcTime, "%a %b %d %H:%M:%S %Y"));
}

Variable Documentation

Initial value:
 {
  { SEC_ASN1_CHOICE, offsetof(SECItem, type), 0, sizeof(SECItem) },
  { SEC_ASN1_UTC_TIME, 0, 0, siUTCTime },
  { SEC_ASN1_GENERALIZED_TIME, 0, 0, siGeneralizedTime },
  { 0 }
}

Definition at line 46 of file sectime.c.

Initial value:
 {
    { SEC_ASN1_SEQUENCE,
         0, NULL, sizeof(CERTValidity) },
    { SEC_ASN1_INLINE,
         offsetof(CERTValidity,notBefore), CERT_TimeChoiceTemplate, 0 },
    { SEC_ASN1_INLINE,
         offsetof(CERTValidity,notAfter), CERT_TimeChoiceTemplate, 0 },
    { 0 }
}

Definition at line 55 of file sectime.c.

const PRTime January1st2050 = LL_INIT(0x0008f81e, 0x1b098000) [static]

Definition at line 44 of file sectime.c.