Bug 452390 Tracemonkey will crash if the compiler doesn't have FASTCALL r=danderson
[wine-gecko.git] / security / manager / ssl / src / nsNSSCertValidity.cpp
blob7ae2caa24132d0e791b2cc6c4151ecbf57760c72
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Ian McGreer <mcgreer@netscape.com>
23 * Javier Delgadillo <javi@netscape.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsNSSCertValidity.h"
40 #include "nsNSSCertHeader.h"
41 #include "nsCOMPtr.h"
42 #include "nsIDateTimeFormat.h"
43 #include "nsDateTimeFormatCID.h"
44 #include "nsComponentManagerUtils.h"
45 #include "nsReadableUtils.h"
46 #include "nsNSSShutDown.h"
48 /* Implementation file */
49 NS_IMPL_THREADSAFE_ISUPPORTS1(nsX509CertValidity, nsIX509CertValidity)
51 nsX509CertValidity::nsX509CertValidity() : mTimesInitialized(PR_FALSE)
53 /* member initializers and constructor code */
56 nsX509CertValidity::nsX509CertValidity(CERTCertificate *cert) :
57 mTimesInitialized(PR_FALSE)
59 nsNSSShutDownPreventionLock locker;
60 if (cert) {
61 SECStatus rv = CERT_GetCertTimes(cert, &mNotBefore, &mNotAfter);
62 if (rv == SECSuccess)
63 mTimesInitialized = PR_TRUE;
67 nsX509CertValidity::~nsX509CertValidity()
69 /* destructor code */
72 /* readonly attribute PRTime notBefore; */
73 NS_IMETHODIMP nsX509CertValidity::GetNotBefore(PRTime *aNotBefore)
75 NS_ENSURE_ARG(aNotBefore);
77 nsresult rv = NS_ERROR_FAILURE;
78 if (mTimesInitialized) {
79 *aNotBefore = mNotBefore;
80 rv = NS_OK;
82 return rv;
85 NS_IMETHODIMP nsX509CertValidity::GetNotBeforeLocalTime(nsAString &aNotBeforeLocalTime)
87 if (!mTimesInitialized)
88 return NS_ERROR_FAILURE;
90 nsresult rv;
91 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
92 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
93 if (NS_FAILED(rv)) return rv;
95 nsAutoString date;
96 PRExplodedTime explodedTime;
97 PR_ExplodeTime(mNotBefore, PR_LocalTimeParameters, &explodedTime);
98 dateFormatter->FormatPRExplodedTime(nsnull, kDateFormatShort, kTimeFormatSecondsForce24Hour,
99 &explodedTime, date);
100 aNotBeforeLocalTime = date;
101 return NS_OK;
104 NS_IMETHODIMP nsX509CertValidity::GetNotBeforeLocalDay(nsAString &aNotBeforeLocalDay)
106 if (!mTimesInitialized)
107 return NS_ERROR_FAILURE;
109 nsresult rv;
110 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
111 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
112 if (NS_FAILED(rv)) return rv;
114 nsAutoString date;
115 PRExplodedTime explodedTime;
116 PR_ExplodeTime(mNotBefore, PR_LocalTimeParameters, &explodedTime);
117 dateFormatter->FormatPRExplodedTime(nsnull, kDateFormatShort, kTimeFormatNone,
118 &explodedTime, date);
119 aNotBeforeLocalDay = date;
120 return NS_OK;
124 NS_IMETHODIMP nsX509CertValidity::GetNotBeforeGMT(nsAString &aNotBeforeGMT)
126 if (!mTimesInitialized)
127 return NS_ERROR_FAILURE;
129 nsresult rv;
130 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
131 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
132 if (NS_FAILED(rv)) return rv;
134 nsAutoString date;
135 PRExplodedTime explodedTime;
136 PR_ExplodeTime(mNotBefore, PR_GMTParameters, &explodedTime);
137 dateFormatter->FormatPRExplodedTime(nsnull, kDateFormatShort, kTimeFormatSecondsForce24Hour,
138 &explodedTime, date);
139 aNotBeforeGMT = date;
140 return NS_OK;
143 /* readonly attribute PRTime notAfter; */
144 NS_IMETHODIMP nsX509CertValidity::GetNotAfter(PRTime *aNotAfter)
146 NS_ENSURE_ARG(aNotAfter);
148 nsresult rv = NS_ERROR_FAILURE;
149 if (mTimesInitialized) {
150 *aNotAfter = mNotAfter;
151 rv = NS_OK;
153 return rv;
156 NS_IMETHODIMP nsX509CertValidity::GetNotAfterLocalTime(nsAString &aNotAfterLocaltime)
158 if (!mTimesInitialized)
159 return NS_ERROR_FAILURE;
161 nsresult rv;
162 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
163 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
164 if (NS_FAILED(rv)) return rv;
166 nsAutoString date;
167 PRExplodedTime explodedTime;
168 PR_ExplodeTime(mNotAfter, PR_LocalTimeParameters, &explodedTime);
169 dateFormatter->FormatPRExplodedTime(nsnull, kDateFormatShort, kTimeFormatSecondsForce24Hour,
170 &explodedTime, date);
171 aNotAfterLocaltime = date;
172 return NS_OK;
175 NS_IMETHODIMP nsX509CertValidity::GetNotAfterLocalDay(nsAString &aNotAfterLocalDay)
177 if (!mTimesInitialized)
178 return NS_ERROR_FAILURE;
180 nsresult rv;
181 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
182 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
183 if (NS_FAILED(rv)) return rv;
185 nsAutoString date;
186 PRExplodedTime explodedTime;
187 PR_ExplodeTime(mNotAfter, PR_LocalTimeParameters, &explodedTime);
188 dateFormatter->FormatPRExplodedTime(nsnull, kDateFormatShort, kTimeFormatNone,
189 &explodedTime, date);
190 aNotAfterLocalDay = date;
191 return NS_OK;
194 NS_IMETHODIMP nsX509CertValidity::GetNotAfterGMT(nsAString &aNotAfterGMT)
196 if (!mTimesInitialized)
197 return NS_ERROR_FAILURE;
199 nsresult rv;
200 nsCOMPtr<nsIDateTimeFormat> dateFormatter =
201 do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
202 if (NS_FAILED(rv)) return rv;
204 nsAutoString date;
205 PRExplodedTime explodedTime;
206 PR_ExplodeTime(mNotAfter, PR_GMTParameters, &explodedTime);
207 dateFormatter->FormatPRExplodedTime(nsnull, kDateFormatShort, kTimeFormatSecondsForce24Hour,
208 &explodedTime, date);
209 aNotAfterGMT = date;
210 return NS_OK;