Bug 1935611 - Fix libyuv/libpng link failed for loongarch64. r=glandium,tnikkel,ng
[gecko.git] / security / manager / ssl / nsNSSCertHelper.cpp
blobc0f0cb5910085b6fa6cc0e741b275cdcc9e2694a
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/. */
5 #include "nsNSSCertHelper.h"
7 #include <algorithm>
9 #include "ScopedNSSTypes.h"
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Casting.h"
12 #include "mozilla/NotNull.h"
13 #include "mozilla/Sprintf.h"
14 #include "mozilla/UniquePtr.h"
15 #include "mozilla/Utf8.h"
16 #include "mozilla/net/DNS.h"
17 #include "nsCOMPtr.h"
18 #include "nsIStringBundle.h"
19 #include "nsNSSCertificate.h"
20 #include "nsReadableUtils.h"
21 #include "nsServiceManagerUtils.h"
22 #include "nsThreadUtils.h"
23 #include "prerror.h"
24 #include "prnetdb.h"
25 #include "secder.h"
27 using namespace mozilla;
29 static nsresult GetPIPNSSBundle(nsIStringBundle** pipnssBundle) {
30 nsCOMPtr<nsIStringBundleService> bundleService(
31 do_GetService(NS_STRINGBUNDLE_CONTRACTID));
32 if (!bundleService) {
33 return NS_ERROR_NOT_AVAILABLE;
35 return bundleService->CreateBundle("chrome://pipnss/locale/pipnss.properties",
36 pipnssBundle);
39 nsresult GetPIPNSSBundleString(const char* stringName, nsAString& result) {
40 MOZ_ASSERT(NS_IsMainThread());
41 if (!NS_IsMainThread()) {
42 return NS_ERROR_NOT_SAME_THREAD;
44 MOZ_ASSERT(stringName);
45 if (!stringName) {
46 return NS_ERROR_INVALID_ARG;
48 nsCOMPtr<nsIStringBundle> pipnssBundle;
49 nsresult rv = GetPIPNSSBundle(getter_AddRefs(pipnssBundle));
50 if (NS_FAILED(rv)) {
51 return rv;
53 result.Truncate();
54 return pipnssBundle->GetStringFromName(stringName, result);
57 nsresult GetPIPNSSBundleString(const char* stringName, nsACString& result) {
58 nsAutoString tmp;
59 nsresult rv = GetPIPNSSBundleString(stringName, tmp);
60 if (NS_FAILED(rv)) {
61 return rv;
63 result.Assign(NS_ConvertUTF16toUTF8(tmp));
64 return NS_OK;
67 nsresult PIPBundleFormatStringFromName(const char* stringName,
68 const nsTArray<nsString>& params,
69 nsAString& result) {
70 MOZ_ASSERT(stringName);
71 MOZ_ASSERT(!params.IsEmpty());
72 if (!stringName || params.IsEmpty()) {
73 return NS_ERROR_INVALID_ARG;
75 nsCOMPtr<nsIStringBundle> pipnssBundle;
76 nsresult rv = GetPIPNSSBundle(getter_AddRefs(pipnssBundle));
77 if (NS_FAILED(rv)) {
78 return rv;
80 result.Truncate();
81 return pipnssBundle->FormatStringFromName(stringName, params, result);
84 void LossyUTF8ToUTF16(const char* str, uint32_t len,
85 /*out*/ nsAString& result) {
86 auto span = Span(str, len);
87 if (IsUtf8(span)) {
88 CopyUTF8toUTF16(span, result);
89 } else {
90 // Actually Latin1 despite ASCII in the legacy name
91 CopyASCIItoUTF16(span, result);