|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "nsCertificatePrincipal.h" |
|
7 |
|
8 NS_IMPL_ISUPPORTS(nsCertificatePrincipal, nsICertificatePrincipal) |
|
9 |
|
10 NS_IMETHODIMP |
|
11 nsCertificatePrincipal::GetFingerprint(nsACString& aFingerprint) |
|
12 { |
|
13 aFingerprint = mFingerprint; |
|
14 return NS_OK; |
|
15 } |
|
16 |
|
17 NS_IMETHODIMP |
|
18 nsCertificatePrincipal::GetSubjectName(nsACString& aSubjectName) |
|
19 { |
|
20 aSubjectName = mSubjectName; |
|
21 return NS_OK; |
|
22 } |
|
23 |
|
24 NS_IMETHODIMP |
|
25 nsCertificatePrincipal::GetPrettyName(nsACString& aPrettyName) |
|
26 { |
|
27 aPrettyName = mPrettyName; |
|
28 return NS_OK; |
|
29 } |
|
30 |
|
31 NS_IMETHODIMP |
|
32 nsCertificatePrincipal::GetCertificate(nsISupports** aCert) |
|
33 { |
|
34 nsCOMPtr<nsISupports> cert = mCert; |
|
35 cert.forget(aCert); |
|
36 return NS_OK; |
|
37 } |
|
38 |
|
39 NS_IMETHODIMP |
|
40 nsCertificatePrincipal::GetHasCertificate(bool* rv) |
|
41 { |
|
42 *rv = true; |
|
43 return NS_OK; |
|
44 } |
|
45 |
|
46 NS_IMETHODIMP |
|
47 nsCertificatePrincipal::Equals(nsICertificatePrincipal* aOther, bool* rv) |
|
48 { |
|
49 nsAutoCString str; |
|
50 aOther->GetFingerprint(str); |
|
51 if (!str.Equals(mFingerprint)) { |
|
52 *rv = false; |
|
53 return NS_OK; |
|
54 } |
|
55 |
|
56 // If either subject name is empty, just let the result stand, but if they're |
|
57 // both non-empty, only claim equality if they're equal. |
|
58 if (!mSubjectName.IsEmpty()) { |
|
59 // Check the other principal's subject name |
|
60 aOther->GetSubjectName(str); |
|
61 *rv = str.Equals(mSubjectName) || str.IsEmpty(); |
|
62 return NS_OK; |
|
63 } |
|
64 |
|
65 *rv = true; |
|
66 return NS_OK; |
|
67 } |