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__
16 [[nodiscard
]] nsresult
Base64EncodeInputStream(nsIInputStream
* aInputStream
,
19 uint32_t aOffset
= 0);
20 [[nodiscard
]] nsresult
Base64EncodeInputStream(nsIInputStream
* aInputStream
,
23 uint32_t aOffset
= 0);
25 // Encode 8-bit data of a given length and append the Base64 encoded data to
27 [[nodiscard
]] nsresult
Base64EncodeAppend(const char* aBinary
,
30 [[nodiscard
]] nsresult
Base64EncodeAppend(const char* aBinary
,
33 [[nodiscard
]] nsresult
Base64EncodeAppend(const nsACString
& aBinary
,
35 [[nodiscard
]] nsresult
Base64EncodeAppend(const nsACString
& aBinary
,
38 [[nodiscard
]] nsresult
Base64Encode(const char* aBinary
, uint32_t aBinaryLen
,
40 [[nodiscard
]] nsresult
Base64Encode(const char* aBinary
, uint32_t aBinaryLen
,
42 [[nodiscard
]] nsresult
Base64Encode(const char* aBinary
, uint32_t aBinaryLen
,
44 [[nodiscard
]] nsresult
Base64Encode(const nsACString
& aBinary
,
46 [[nodiscard
]] nsresult
Base64Encode(const nsACString
& aBinary
,
49 // The high bits of any characters in aBinary are dropped.
50 [[nodiscard
]] nsresult
Base64Encode(const nsAString
& aBinary
,
53 [[nodiscard
]] nsresult
Base64Decode(const char* aBase64
, uint32_t aBase64Len
,
54 char** aBinary
, uint32_t* aBinaryLen
);
55 [[nodiscard
]] nsresult
Base64Decode(const nsACString
& aBase64
,
58 // The high bits of any characters in aBase64 are dropped.
59 [[nodiscard
]] nsresult
Base64Decode(const nsAString
& aBase64
,
61 [[nodiscard
]] nsresult
Base64Decode(const nsAString
& aBase64
,
64 enum class Base64URLEncodePaddingPolicy
{
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
74 [[nodiscard
]] nsresult
Base64URLEncode(
75 uint32_t aBinaryLen
, const uint8_t* aBinary
,
76 Base64URLEncodePaddingPolicy aPaddingPolicy
, nsACString
& aBase64
);
78 enum class Base64URLDecodePaddingPolicy
{
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