Bug 1927094 - optimize lineScrollAmount so it doesn't iterate over all tabs, r=mconley
[gecko.git] / xpcom / io / Base64.h
blob0a9b3a030502100d4ff5ff4d34612bcb8d5a65c1
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_Base64_h__
8 #define mozilla_Base64_h__
10 #include "nsString.h"
12 class nsIInputStream;
14 namespace mozilla {
16 [[nodiscard]] nsresult Base64EncodeInputStream(nsIInputStream* aInputStream,
17 nsACString& aDest,
18 uint32_t aCount,
19 uint32_t aOffset = 0);
20 [[nodiscard]] nsresult Base64EncodeInputStream(nsIInputStream* aInputStream,
21 nsAString& aDest,
22 uint32_t aCount,
23 uint32_t aOffset = 0);
25 // Encode 8-bit data of a given length and append the Base64 encoded data to
26 // aBase64.
27 [[nodiscard]] nsresult Base64EncodeAppend(const char* aBinary,
28 uint32_t aBinaryLen,
29 nsAString& aBase64);
30 [[nodiscard]] nsresult Base64EncodeAppend(const char* aBinary,
31 uint32_t aBinaryLen,
32 nsACString& aBase64);
33 [[nodiscard]] nsresult Base64EncodeAppend(const nsACString& aBinary,
34 nsACString& aBase64);
35 [[nodiscard]] nsresult Base64EncodeAppend(const nsACString& aBinary,
36 nsAString& aBase64);
38 [[nodiscard]] nsresult Base64Encode(const char* aBinary, uint32_t aBinaryLen,
39 char** aBase64);
40 [[nodiscard]] nsresult Base64Encode(const char* aBinary, uint32_t aBinaryLen,
41 nsACString& aBase64);
42 [[nodiscard]] nsresult Base64Encode(const char* aBinary, uint32_t aBinaryLen,
43 nsAString& aBase64);
44 [[nodiscard]] nsresult Base64Encode(const nsACString& aBinary,
45 nsACString& aBase64);
46 [[nodiscard]] nsresult Base64Encode(const nsACString& aBinary,
47 nsAString& aBase64);
49 // The high bits of any characters in aBinary are dropped.
50 [[nodiscard]] nsresult Base64Encode(const nsAString& aBinary,
51 nsAString& aBase64);
53 [[nodiscard]] nsresult Base64Decode(const char* aBase64, uint32_t aBase64Len,
54 char** aBinary, uint32_t* aBinaryLen);
55 [[nodiscard]] nsresult Base64Decode(const nsACString& aBase64,
56 nsACString& aBinary);
58 // The high bits of any characters in aBase64 are dropped.
59 [[nodiscard]] nsresult Base64Decode(const nsAString& aBase64,
60 nsAString& aBinary);
61 [[nodiscard]] nsresult Base64Decode(const nsAString& aBase64,
62 nsACString& aBinary);
64 enum class Base64URLEncodePaddingPolicy {
65 Include,
66 Omit,
69 /**
70 * Converts |aBinary| to an unpadded, Base64 URL-encoded string per RFC 4648.
71 * Aims to encode the data in constant time. The caller retains ownership
72 * of |aBinary|.
74 [[nodiscard]] nsresult Base64URLEncode(
75 uint32_t aBinaryLen, const uint8_t* aBinary,
76 Base64URLEncodePaddingPolicy aPaddingPolicy, nsACString& aBase64);
78 enum class Base64URLDecodePaddingPolicy {
79 Require,
80 Ignore,
81 Reject,
84 /**
85 * Decodes a Base64 URL-encoded |aBase64| into |aBinary|.
87 [[nodiscard]] nsresult Base64URLDecode(
88 const nsACString& aBase64, Base64URLDecodePaddingPolicy aPaddingPolicy,
89 FallibleTArray<uint8_t>& aBinary);
91 } // namespace mozilla
93 #endif