Giter Club home page Giter Club logo

b64's Introduction

b64

b64 is a very small and simple standalone C-language library that provides Base-64 encoding and decoding.

Table of Contents

  1. Introduction
  2. Installation
  3. Components
  4. Examples
  5. Project Information

Introduction

b64 is a C-language library

b64 is a very small and simple standalone C-language library that provides Base-64 encoding and decoding. It also provides a header-only C++ wrapper.

The b64 core library is a pure standalone component:

  • It has zero dependencies on any other libraries;
  • It has zero dependencies on any part of the C standard library, except in debug builds (where it depends on strchr() and assert());
  • It has zero dependencies on any host operating system facilities;
  • It does not allocate any memory;
  • It is released under the BSD license, which basically means its free for any use, but you can't claim it's yours.

Base-64 conversion of binary regions, using b64, is available as part of the distribution of Pantheios, a high-performance C++ diagnostic logging API library.

(Note: the C++ wrapper depends on the STLSoft libraries;)

Installation

T.B.C.

Components

C API / core library

enum B64_RC
{
        B64_RC_OK                   =   0   /* Operation was successful. */
    ,   B64_RC_INSUFFICIENT_BUFFER  =   1   /* The given translation buffer was not of sufficient size. */
    ,   B64_RC_TRUNCATED_INPUT      =   2   /* The input did not represent a fully formed stream of octet couplings. */
    ,   B64_RC_DATA_ERROR           =   3   /* Invalid data. */
};

enum B64_FLAGS
{
        B64_F_LINE_LEN_USE_PARAM    =   0x0000  /* Uses the lineLen parameter to b64_encode2(). Ignored by b64_decode2(). */
    ,   B64_F_LINE_LEN_INFINITE     =   0x0001  /* Ignores the lineLen parameter to b64_encode2(). Line length is infinite. Ignored by b64_decode2(). */
    ,   B64_F_LINE_LEN_64           =   0x0002  /* Ignores the lineLen parameter to b64_encode2(). Line length is 64. Ignored by b64_decode2(). */
    ,   B64_F_LINE_LEN_76           =   0x0003  /* Ignores the lineLen parameter to b64_encode2(). Line length is 76. Ignored by b64_decode2(). */
    ,   B64_F_LINE_LEN_MASK         =   0x000f  /* Mask for testing line length flags to b64_encode2(). Ignored by b64_encode2(). */
    ,   B64_F_STOP_ON_NOTHING       =   0x0000  /* Decoding ignores all invalid characters in the input data. Ignored by b64_encode2(). */
    ,   B64_F_STOP_ON_UNKNOWN_CHAR  =   0x0100  /* Causes decoding to break if any non-Base-64 [a-zA-Z0-9=+/], non-whitespace character is encountered. Ignored by b64_encode2(). */
    ,   B64_F_STOP_ON_UNEXPECTED_WS =   0x0200  /* Causes decoding to break if any unexpected whitespace is encountered. Ignored by b64_encode2(). */
    ,   B64_F_STOP_ON_BAD_CHAR      =   0x0300  /* Causes decoding to break if any non-Base-64 [a-zA-Z0-9=+/] character is encountered. Ignored by b64_encode2(). */
};


size_t
b64_encode(
    void const* src
,   size_t      srcSize
,   b64_char_t* dest
,   size_t      destLen
);

size_t
b64_decode(
    b64_char_t const*   src
,   size_t              srcLen
,   void*               dest
,   size_t              destSize
);

size_t
b64_encode2(
    void const* src
,   size_t      srcSize
,   b64_char_t* dest
,   size_t      destLen
,   unsigned    flags
,   int         lineLen    /* = 0 */
,   B64_RC*     rc         /* = NULL */
);

size_t
b64_decode2(
    b64_char_t const*   src
,   size_t              srcLen
,   void*               dest
,   size_t              destSize
,   unsigned            flags
,   b64_char_t const**  badChar    /* = NULL */
,   B64_RC*             rc         /* = NULL */
);

char const*
b64_getStatusCodeString(
    B64_RC  code
);

size_t
b64_getStatusCodeStringLength(
    B64_RC  code
);

C++ API

typedef std::basic_string<b64_char_t>   string_t;
typedef std::vector<byte_t_>            blob_t;

class coding_exception;


string_t encode(void const* src, size_t srcSize, int flags, int lineLen = 0, B64_RC* rc = NULL);

string_t encode(void const* src, size_t srcSize);

template <typename T, size_t N>
string_t encode(T (&ar)[N]);

string_t encode(blob_t const &blob, int flags, int lineLen = 0, B64_RC* rc = NULL);

string_t encode(blob_t const &blob);


blob_t decode(b64_char_t const* src, size_t srcLen, int flags, b64_char_t const** badChar = NULL, B64_RC* rc = NULL);

blob_t decode(b64_char_t const* src, size_t srcLen);

template <class S>
blob_t decode(S const &str);

template <class S>
blob_t decode(int flags, S const &str);

blob_t decode(string_t const &str, int flags = B64_F_STOP_ON_BAD_CHAR);

blob_t decode(string_t const &str, int flags, b64_char_t const** badChar, B64_RC* rc = NULL);

Examples

Examples are provided in the examples directory, along with a markdown description for each.

Project Information

Where to get help

GitHub Page

Contribution guidelines

Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/b64.

Dependencies

STLSoft (C++ API-only)

The C API has no non-standard dependencies. The C++ API depends on the STLSoft libraries, version 1.9.111 (or later). Version 1.10.1 beta21 (or later) is recommended.

xTests (unit-tests only)

The unit-test projects depend on the xTests project

Related projects

Projects in which b64 is used include:

License

b64 is released under the 3-clause BSD license. See LICENSE for details.

b64's People

Contributors

synesissoftware avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.