2014-06-30 15:39:45 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-06-08 18:08:31 +00:00
|
|
|
|
|
|
|
#ifndef mozilla_Base64_h__
|
|
|
|
#define mozilla_Base64_h__
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
class nsIInputStream;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2020-03-27 17:21:48 +00:00
|
|
|
[[nodiscard]] nsresult Base64EncodeInputStream(nsIInputStream* aInputStream,
|
|
|
|
nsACString& aDest,
|
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t aOffset = 0);
|
|
|
|
[[nodiscard]] nsresult Base64EncodeInputStream(nsIInputStream* aInputStream,
|
|
|
|
nsAString& aDest,
|
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t aOffset = 0);
|
2011-06-08 18:08:31 +00:00
|
|
|
|
2020-08-19 08:11:42 +00:00
|
|
|
// Encode 8-bit data of a given length and append the Base64 encoded data to
|
|
|
|
// aBase64.
|
|
|
|
[[nodiscard]] nsresult Base64EncodeAppend(const char* aBinary,
|
|
|
|
uint32_t aBinaryLen,
|
|
|
|
nsAString& aBase64);
|
2020-08-19 17:45:16 +00:00
|
|
|
[[nodiscard]] nsresult Base64EncodeAppend(const char* aBinary,
|
|
|
|
uint32_t aBinaryLen,
|
|
|
|
nsACString& aBase64);
|
|
|
|
[[nodiscard]] nsresult Base64EncodeAppend(const nsACString& aBinary,
|
|
|
|
nsACString& aBase64);
|
|
|
|
[[nodiscard]] nsresult Base64EncodeAppend(const nsACString& aBinary,
|
|
|
|
nsAString& aBase64);
|
|
|
|
|
2020-03-27 17:21:48 +00:00
|
|
|
[[nodiscard]] nsresult Base64Encode(const char* aBinary, uint32_t aBinaryLen,
|
|
|
|
char** aBase64);
|
2020-08-19 17:45:16 +00:00
|
|
|
[[nodiscard]] nsresult Base64Encode(const char* aBinary, uint32_t aBinaryLen,
|
|
|
|
nsACString& aBase64);
|
|
|
|
[[nodiscard]] nsresult Base64Encode(const char* aBinary, uint32_t aBinaryLen,
|
|
|
|
nsAString& aBase64);
|
2020-03-27 17:21:48 +00:00
|
|
|
[[nodiscard]] nsresult Base64Encode(const nsACString& aBinary,
|
|
|
|
nsACString& aBase64);
|
2020-08-19 17:45:16 +00:00
|
|
|
[[nodiscard]] nsresult Base64Encode(const nsACString& aBinary,
|
|
|
|
nsAString& aBase64);
|
2017-09-06 20:58:37 +00:00
|
|
|
|
|
|
|
// The high bits of any characters in aBinary are dropped.
|
2020-03-27 17:21:48 +00:00
|
|
|
[[nodiscard]] nsresult Base64Encode(const nsAString& aBinary,
|
|
|
|
nsAString& aBase64);
|
2011-12-28 08:13:38 +00:00
|
|
|
|
2020-03-27 17:21:48 +00:00
|
|
|
[[nodiscard]] nsresult Base64Decode(const char* aBase64, uint32_t aBase64Len,
|
|
|
|
char** aBinary, uint32_t* aBinaryLen);
|
|
|
|
[[nodiscard]] nsresult Base64Decode(const nsACString& aBase64,
|
|
|
|
nsACString& aBinary);
|
2017-09-06 20:58:37 +00:00
|
|
|
|
|
|
|
// The high bits of any characters in aBase64 are dropped.
|
2020-03-27 17:21:48 +00:00
|
|
|
[[nodiscard]] nsresult Base64Decode(const nsAString& aBase64,
|
|
|
|
nsAString& aBinary);
|
2022-02-18 10:42:10 +00:00
|
|
|
[[nodiscard]] nsresult Base64Decode(const nsAString& aBase64,
|
|
|
|
nsACString& aBinary);
|
2011-12-28 08:13:38 +00:00
|
|
|
|
2016-04-22 14:41:58 +00:00
|
|
|
enum class Base64URLEncodePaddingPolicy {
|
|
|
|
Include,
|
|
|
|
Omit,
|
|
|
|
};
|
|
|
|
|
2015-12-15 00:28:19 +00:00
|
|
|
/**
|
2016-05-18 22:53:50 +00:00
|
|
|
* Converts |aBinary| to an unpadded, Base64 URL-encoded string per RFC 4648.
|
2016-03-22 19:09:04 +00:00
|
|
|
* Aims to encode the data in constant time. The caller retains ownership
|
2016-05-18 22:53:50 +00:00
|
|
|
* of |aBinary|.
|
2016-03-22 19:09:04 +00:00
|
|
|
*/
|
2020-03-27 17:21:48 +00:00
|
|
|
[[nodiscard]] nsresult Base64URLEncode(
|
2016-05-18 22:53:50 +00:00
|
|
|
uint32_t aBinaryLen, const uint8_t* aBinary,
|
2016-04-22 14:41:58 +00:00
|
|
|
Base64URLEncodePaddingPolicy aPaddingPolicy, nsACString& aBase64);
|
2016-03-22 19:09:04 +00:00
|
|
|
|
2016-04-22 14:41:58 +00:00
|
|
|
enum class Base64URLDecodePaddingPolicy {
|
|
|
|
Require,
|
|
|
|
Ignore,
|
|
|
|
Reject,
|
|
|
|
};
|
|
|
|
|
2016-03-22 19:09:04 +00:00
|
|
|
/**
|
2016-05-18 22:53:50 +00:00
|
|
|
* Decodes a Base64 URL-encoded |aBase64| into |aBinary|.
|
2015-12-15 00:28:19 +00:00
|
|
|
*/
|
2020-03-27 17:21:48 +00:00
|
|
|
[[nodiscard]] nsresult Base64URLDecode(
|
2016-04-22 14:41:58 +00:00
|
|
|
const nsACString& aBase64, Base64URLDecodePaddingPolicy aPaddingPolicy,
|
2016-05-18 22:53:50 +00:00
|
|
|
FallibleTArray<uint8_t>& aBinary);
|
2015-12-15 00:28:19 +00:00
|
|
|
|
2011-06-08 18:08:31 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|