2014-06-30 19:39:45 +04: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 15:12:37 +04: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 22:08:31 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_Base64_h__
|
|
|
|
#define mozilla_Base64_h__
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
class nsIInputStream;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-06-06 05:22:14 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
2014-05-15 00:15:46 +04:00
|
|
|
Base64EncodeInputStream(nsIInputStream* aInputStream,
|
|
|
|
nsACString& aDest,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t aOffset = 0);
|
2016-06-06 05:22:14 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
2014-05-15 00:15:46 +04:00
|
|
|
Base64EncodeInputStream(nsIInputStream* aInputStream,
|
|
|
|
nsAString& aDest,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t aOffset = 0);
|
2011-06-08 22:08:31 +04:00
|
|
|
|
2016-06-06 05:22:14 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
2016-05-19 01:55:46 +03:00
|
|
|
Base64Encode(const char* aBinary, uint32_t aBinaryLen, char** aBase64);
|
2016-06-06 05:22:14 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
2016-05-19 01:53:50 +03:00
|
|
|
Base64Encode(const nsACString& aBinary, nsACString& aBase64);
|
2016-06-06 05:22:14 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
2016-05-19 01:53:50 +03:00
|
|
|
Base64Encode(const nsAString& aBinary, nsAString& aBase64);
|
2011-12-28 12:13:38 +04:00
|
|
|
|
2016-08-04 04:49:46 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
|
|
|
Base64Decode(const char* aBase64, uint32_t aBase64Len, char** aBinary,
|
|
|
|
uint32_t* aBinaryLen);
|
2016-06-06 05:22:14 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
2016-05-19 01:53:50 +03:00
|
|
|
Base64Decode(const nsACString& aBase64, nsACString& aBinary);
|
2016-06-06 05:22:14 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
2016-05-19 01:53:50 +03:00
|
|
|
Base64Decode(const nsAString& aBase64, nsAString& aBinary);
|
2011-12-28 12:13:38 +04:00
|
|
|
|
2016-04-22 17:41:58 +03:00
|
|
|
enum class Base64URLEncodePaddingPolicy {
|
|
|
|
Include,
|
|
|
|
Omit,
|
|
|
|
};
|
|
|
|
|
2015-12-15 03:28:19 +03:00
|
|
|
/**
|
2016-05-19 01:53:50 +03:00
|
|
|
* Converts |aBinary| to an unpadded, Base64 URL-encoded string per RFC 4648.
|
2016-03-22 22:09:04 +03:00
|
|
|
* Aims to encode the data in constant time. The caller retains ownership
|
2016-05-19 01:53:50 +03:00
|
|
|
* of |aBinary|.
|
2016-03-22 22:09:04 +03:00
|
|
|
*/
|
2016-06-06 05:22:14 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
2016-05-19 01:53:50 +03:00
|
|
|
Base64URLEncode(uint32_t aBinaryLen, const uint8_t* aBinary,
|
2016-04-22 17:41:58 +03:00
|
|
|
Base64URLEncodePaddingPolicy aPaddingPolicy,
|
2016-05-19 01:53:50 +03:00
|
|
|
nsACString& aBase64);
|
2016-03-22 22:09:04 +03:00
|
|
|
|
2016-04-22 17:41:58 +03:00
|
|
|
enum class Base64URLDecodePaddingPolicy {
|
|
|
|
Require,
|
|
|
|
Ignore,
|
|
|
|
Reject,
|
|
|
|
};
|
|
|
|
|
2016-03-22 22:09:04 +03:00
|
|
|
/**
|
2016-05-19 01:53:50 +03:00
|
|
|
* Decodes a Base64 URL-encoded |aBase64| into |aBinary|.
|
2015-12-15 03:28:19 +03:00
|
|
|
*/
|
2016-06-06 05:22:14 +03:00
|
|
|
MOZ_MUST_USE nsresult
|
2016-05-19 01:53:50 +03:00
|
|
|
Base64URLDecode(const nsACString& aBase64,
|
2016-04-22 17:41:58 +03:00
|
|
|
Base64URLDecodePaddingPolicy aPaddingPolicy,
|
2016-05-19 01:53:50 +03:00
|
|
|
FallibleTArray<uint8_t>& aBinary);
|
2015-12-15 03:28:19 +03:00
|
|
|
|
2011-06-08 22:08:31 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|