/src/mozilla-central/security/manager/ssl/nsNSSCertValidity.cpp
Line | Count | Source (jump to first uncovered line) |
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 |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #include "nsNSSCertValidity.h" |
6 | | |
7 | | #include "cert.h" |
8 | | #include "mozilla/Assertions.h" |
9 | | #include "nsCOMPtr.h" |
10 | | #include "nsComponentManagerUtils.h" |
11 | | #include "nsReadableUtils.h" |
12 | | |
13 | | NS_IMPL_ISUPPORTS(nsX509CertValidity, nsIX509CertValidity) |
14 | | |
15 | | using namespace mozilla; |
16 | | |
17 | | nsX509CertValidity::nsX509CertValidity(const mozilla::UniqueCERTCertificate& cert) |
18 | | : mNotBefore(0) |
19 | | , mNotAfter(0) |
20 | | , mTimesInitialized(false) |
21 | 0 | { |
22 | 0 | MOZ_ASSERT(cert); |
23 | 0 | if (!cert) { |
24 | 0 | return; |
25 | 0 | } |
26 | 0 | |
27 | 0 | if (CERT_GetCertTimes(cert.get(), &mNotBefore, &mNotAfter) == SECSuccess) { |
28 | 0 | mTimesInitialized = true; |
29 | 0 | } |
30 | 0 | } |
31 | | |
32 | | NS_IMETHODIMP |
33 | | nsX509CertValidity::GetNotBefore(PRTime* aNotBefore) |
34 | 0 | { |
35 | 0 | NS_ENSURE_ARG(aNotBefore); |
36 | 0 |
|
37 | 0 | if (!mTimesInitialized) { |
38 | 0 | return NS_ERROR_FAILURE; |
39 | 0 | } |
40 | 0 | |
41 | 0 | *aNotBefore = mNotBefore; |
42 | 0 | return NS_OK; |
43 | 0 | } |
44 | | |
45 | | nsresult |
46 | | nsX509CertValidity::FormatTime(const PRTime& aTimeDate, |
47 | | PRTimeParamFn aParamFn, |
48 | | const nsTimeFormatSelector aTimeFormatSelector, |
49 | | nsAString& aFormattedTimeDate) |
50 | 0 | { |
51 | 0 | if (!mTimesInitialized) |
52 | 0 | return NS_ERROR_FAILURE; |
53 | 0 | |
54 | 0 | PRExplodedTime explodedTime; |
55 | 0 | PR_ExplodeTime(const_cast<PRTime&>(aTimeDate), aParamFn, &explodedTime); |
56 | 0 | return mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatLong, |
57 | 0 | aTimeFormatSelector, |
58 | 0 | &explodedTime, aFormattedTimeDate); |
59 | 0 | } |
60 | | |
61 | | NS_IMETHODIMP |
62 | | nsX509CertValidity::GetNotBeforeLocalTime(nsAString& aNotBeforeLocalTime) |
63 | 0 | { |
64 | 0 | return FormatTime(mNotBefore, PR_LocalTimeParameters, |
65 | 0 | kTimeFormatSeconds, aNotBeforeLocalTime); |
66 | 0 | } |
67 | | |
68 | | NS_IMETHODIMP |
69 | | nsX509CertValidity::GetNotBeforeLocalDay(nsAString& aNotBeforeLocalDay) |
70 | 0 | { |
71 | 0 | return FormatTime(mNotBefore, PR_LocalTimeParameters, |
72 | 0 | kTimeFormatNone, aNotBeforeLocalDay); |
73 | 0 | } |
74 | | |
75 | | NS_IMETHODIMP |
76 | | nsX509CertValidity::GetNotBeforeGMT(nsAString& aNotBeforeGMT) |
77 | 0 | { |
78 | 0 | return FormatTime(mNotBefore, PR_GMTParameters, |
79 | 0 | kTimeFormatSeconds, aNotBeforeGMT); |
80 | 0 | } |
81 | | |
82 | | NS_IMETHODIMP |
83 | | nsX509CertValidity::GetNotAfter(PRTime* aNotAfter) |
84 | 0 | { |
85 | 0 | NS_ENSURE_ARG(aNotAfter); |
86 | 0 |
|
87 | 0 | if (!mTimesInitialized) { |
88 | 0 | return NS_ERROR_FAILURE; |
89 | 0 | } |
90 | 0 | |
91 | 0 | *aNotAfter = mNotAfter; |
92 | 0 | return NS_OK; |
93 | 0 | } |
94 | | |
95 | | NS_IMETHODIMP |
96 | | nsX509CertValidity::GetNotAfterLocalTime(nsAString& aNotAfterLocaltime) |
97 | 0 | { |
98 | 0 | return FormatTime(mNotAfter, PR_LocalTimeParameters, |
99 | 0 | kTimeFormatSeconds, aNotAfterLocaltime); |
100 | 0 | } |
101 | | |
102 | | NS_IMETHODIMP |
103 | | nsX509CertValidity::GetNotAfterLocalDay(nsAString& aNotAfterLocalDay) |
104 | 0 | { |
105 | 0 | return FormatTime(mNotAfter, PR_LocalTimeParameters, |
106 | 0 | kTimeFormatNone, aNotAfterLocalDay); |
107 | 0 | } |
108 | | |
109 | | NS_IMETHODIMP |
110 | | nsX509CertValidity::GetNotAfterGMT(nsAString& aNotAfterGMT) |
111 | 0 | { |
112 | 0 | return FormatTime(mNotAfter, PR_GMTParameters, |
113 | 0 | kTimeFormatSeconds, aNotAfterGMT); |
114 | 0 | } |