1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_BASE64URL_H_
6 #define BASE_BASE64URL_H_
10 #include "base/base_export.h"
11 #include "base/compiler_specific.h"
12 #include "base/macros.h"
13 #include "base/strings/string_piece.h"
17 enum class Base64UrlEncodePolicy {
18 // Include the trailing padding in the output, when necessary.
21 // Remove the trailing padding from the output.
25 // Encodes the |input| string in base64url, defined in RFC 4648:
26 // https://tools.ietf.org/html/rfc4648#section-5
28 // The |policy| defines whether padding should be included or omitted from the
29 // encoded |*output|. |input| and |*output| may reference the same storage.
30 BASE_EXPORT void Base64UrlEncode(const StringPiece& input,
31 Base64UrlEncodePolicy policy,
34 enum class Base64UrlDecodePolicy {
35 // Require inputs contain trailing padding if non-aligned.
38 // Accept inputs regardless of whether or not they have the correct padding.
41 // Reject inputs if they contain any trailing padding.
45 // Decodes the |input| string in base64url, defined in RFC 4648:
46 // https://tools.ietf.org/html/rfc4648#section-5
48 // The |policy| defines whether padding will be required, ignored or disallowed
49 // altogether. |input| and |*output| may reference the same storage.
50 BASE_EXPORT bool Base64UrlDecode(const StringPiece& input,
51 Base64UrlDecodePolicy policy,
52 std::string* output) WARN_UNUSED_RESULT;
56 #endif // BASE_BASE64URL_H_