OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 #include "prtime.h" | 5 #include "prtime.h" |
6 #include "secder.h" | 6 #include "secder.h" |
7 #include "secitem.h" | 7 #include "secitem.h" |
8 #include "secerr.h" | 8 #include "secerr.h" |
9 | 9 |
10 static char *DecodeUTCTime2FormattedAscii (SECItem *utcTimeDER, char *format); | 10 static char *DecodeUTCTime2FormattedAscii (SECItem *utcTimeDER, char *format); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return DER_GeneralizedDayToAscii(timechoice); | 46 return DER_GeneralizedDayToAscii(timechoice); |
47 | 47 |
48 default: | 48 default: |
49 PORT_Assert(0); | 49 PORT_Assert(0); |
50 PORT_SetError(SEC_ERROR_INVALID_ARGS); | 50 PORT_SetError(SEC_ERROR_INVALID_ARGS); |
51 return NULL; | 51 return NULL; |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 char * | 55 char * |
56 CERT_UTCTime2FormattedAscii (int64 utcTime, char *format) | 56 CERT_UTCTime2FormattedAscii(PRTime utcTime, char *format) |
57 { | 57 { |
58 PRExplodedTime printableTime; | 58 PRExplodedTime printableTime; |
59 char *timeString; | 59 char *timeString; |
60 | 60 |
61 /* Converse time to local time and decompose it into components */ | 61 /* Converse time to local time and decompose it into components */ |
62 PR_ExplodeTime(utcTime, PR_LocalTimeParameters, &printableTime); | 62 PR_ExplodeTime(utcTime, PR_LocalTimeParameters, &printableTime); |
63 | 63 |
64 timeString = (char *)PORT_Alloc(256); | 64 timeString = (char *)PORT_Alloc(256); |
65 | 65 |
66 if ( timeString ) { | 66 if ( timeString ) { |
67 if ( ! PR_FormatTime( timeString, 256, format, &printableTime )) { | 67 if ( ! PR_FormatTime( timeString, 256, format, &printableTime )) { |
68 PORT_Free(timeString); | 68 PORT_Free(timeString); |
69 timeString = NULL; | 69 timeString = NULL; |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 return (timeString); | 73 return (timeString); |
74 } | 74 } |
75 | 75 |
76 char *CERT_GenTime2FormattedAscii (int64 genTime, char *format) | 76 char *CERT_GenTime2FormattedAscii(PRTime genTime, char *format) |
77 { | 77 { |
78 PRExplodedTime printableTime; | 78 PRExplodedTime printableTime; |
79 char *timeString; | 79 char *timeString; |
80 | 80 |
81 /* Decompose time into components */ | 81 /* Decompose time into components */ |
82 PR_ExplodeTime(genTime, PR_GMTParameters, &printableTime); | 82 PR_ExplodeTime(genTime, PR_GMTParameters, &printableTime); |
83 | 83 |
84 timeString = (char *)PORT_Alloc(256); | 84 timeString = (char *)PORT_Alloc(256); |
85 | 85 |
86 if ( timeString ) { | 86 if ( timeString ) { |
87 if ( ! PR_FormatTime( timeString, 256, format, &printableTime )) { | 87 if ( ! PR_FormatTime( timeString, 256, format, &printableTime )) { |
88 PORT_Free(timeString); | 88 PORT_Free(timeString); |
89 timeString = NULL; | 89 timeString = NULL; |
90 PORT_SetError(SEC_ERROR_OUTPUT_LEN); | 90 PORT_SetError(SEC_ERROR_OUTPUT_LEN); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 return (timeString); | 94 return (timeString); |
95 } | 95 } |
96 | 96 |
97 | 97 |
98 /* convert DER utc time to ascii time string, The format of the time string | 98 /* convert DER utc time to ascii time string, The format of the time string |
99 depends on the input "format" | 99 depends on the input "format" |
100 */ | 100 */ |
101 static char * | 101 static char * |
102 DecodeUTCTime2FormattedAscii (SECItem *utcTimeDER, char *format) | 102 DecodeUTCTime2FormattedAscii (SECItem *utcTimeDER, char *format) |
103 { | 103 { |
104 int64 utcTime; | 104 PRTime utcTime; |
105 int rv; | 105 int rv; |
106 | 106 |
107 rv = DER_UTCTimeToTime(&utcTime, utcTimeDER); | 107 rv = DER_UTCTimeToTime(&utcTime, utcTimeDER); |
108 if (rv) { | 108 if (rv) { |
109 return(NULL); | 109 return(NULL); |
110 } | 110 } |
111 return (CERT_UTCTime2FormattedAscii (utcTime, format)); | 111 return (CERT_UTCTime2FormattedAscii (utcTime, format)); |
112 } | 112 } |
113 | 113 |
114 /* convert DER utc time to ascii time string, The format of the time string | 114 /* convert DER utc time to ascii time string, The format of the time string |
(...skipping 27 matching lines...) Expand all Loading... |
142 default: | 142 default: |
143 PORT_SetError(SEC_ERROR_INVALID_ARGS); | 143 PORT_SetError(SEC_ERROR_INVALID_ARGS); |
144 PORT_Assert(0); | 144 PORT_Assert(0); |
145 return SECFailure; | 145 return SECFailure; |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 /* encode a PRTime to an ASN.1 DER SECItem containing either a | 149 /* encode a PRTime to an ASN.1 DER SECItem containing either a |
150 SEC_ASN1_GENERALIZED_TIME or a SEC_ASN1_UTC_TIME */ | 150 SEC_ASN1_GENERALIZED_TIME or a SEC_ASN1_UTC_TIME */ |
151 | 151 |
152 SECStatus DER_EncodeTimeChoice(PRArenaPool* arena, SECItem* output, PRTime input
) | 152 SECStatus DER_EncodeTimeChoice(PLArenaPool* arena, SECItem* output, PRTime input
) |
153 { | 153 { |
154 SECStatus rv; | 154 SECStatus rv; |
155 | 155 |
156 rv = DER_TimeToUTCTimeArena(arena, output, input); | 156 rv = DER_TimeToUTCTimeArena(arena, output, input); |
157 if (rv == SECSuccess || PORT_GetError() != SEC_ERROR_INVALID_ARGS) { | 157 if (rv == SECSuccess || PORT_GetError() != SEC_ERROR_INVALID_ARGS) { |
158 return rv; | 158 return rv; |
159 } | 159 } |
160 return DER_TimeToGeneralizedTimeArena(arena, output, input); | 160 return DER_TimeToGeneralizedTimeArena(arena, output, input); |
161 } | 161 } |
OLD | NEW |