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