• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkBase64_DEFINED
9 #define SkBase64_DEFINED
10 
11 #include "include/core/SkTypes.h"
12 
13 #include <cstddef>
14 
15 struct SkBase64 {
16 public:
17     enum Error {
18         kNoError,
19         kPadError,
20         kBadCharError
21     };
22 
23     /**
24        Base64 encodes src into dst.
25 
26        Normally this is called once with 'dst' nullptr to get the required size, then again with an
27        allocated 'dst' pointer to do the actual encoding.
28 
29        @param dst nullptr or a pointer to a buffer large enough to receive the result
30 
31        @param encode nullptr for default encoding or a pointer to at least 65 chars.
32                      encode[64] will be used as the pad character.
33                      Encodings other than the default encoding cannot be decoded.
34 
35        @return the required length of dst for encoding.
36     */
37     static size_t Encode(const void* src, size_t length, void* dst, const char* encode = nullptr);
38 
39     /**
40        Base64 decodes src into dst.
41 
42        Normally this is called once with 'dst' nullptr to get the required size, then again with an
43        allocated 'dst' pointer to do the actual encoding.
44 
45        @param dst nullptr or a pointer to a buffer large enough to receive the result
46 
47        @param dstLength assigned the length dst is required to be. Must not be nullptr.
48     */
49     static Error SK_WARN_UNUSED_RESULT Decode(const void* src, size_t  srcLength,
50                                                     void* dst, size_t* dstLength);
51 };
52 
53 #endif // SkBase64_DEFINED
54