1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkBase64_DEFINED
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkBase64_DEFINED
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypes.h"
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkBase64 {
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum Error {
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kNoError,
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPadError,
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kBadCharError
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBase64();
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Error decode(const char* src, size_t length);
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    char* getData() { return fData; }
24af5bbf24498634142f4227eed2b120169a08156bbungeman@google.com    /**
25af5bbf24498634142f4227eed2b120169a08156bbungeman@google.com       Base64 encodes src into dst. encode is a pointer to at least 65 chars.
26af5bbf24498634142f4227eed2b120169a08156bbungeman@google.com       encode[64] will be used as the pad character. Encodings other than the
27af5bbf24498634142f4227eed2b120169a08156bbungeman@google.com       default encoding cannot be decoded.
28af5bbf24498634142f4227eed2b120169a08156bbungeman@google.com    */
29af5bbf24498634142f4227eed2b120169a08156bbungeman@google.com    static size_t Encode(const void* src, size_t length, void* dest, const char* encode = NULL);
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Error decode(const void* srcPtr, size_t length, bool writeDestination);
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    size_t fLength;
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    char* fData;
36bdae027bd86b7900d1874ad77f0ec9e31f6cbcabreed@google.com    friend class SkImageBaseBitmap;
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif // SkBase64_DEFINED
40