aboutsummaryrefslogtreecommitdiffstats
path: root/fsa/src/vespa/fsa/base64.h
blob: 3251bb2177d8176efb8143862c08da6190e4055d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * @author  Peter Boros
 * @date    2004/08/20
 * @version $Id$
 * @file    base64.h
 * @brief   Definition of Base64 class
 *
 */

#pragma once

#include <string>

namespace fsa {

/**
 * @class Base64
 * @brief Base64 encoding and decoding.
 *
 * Encode and decode arbitrary binary strings to %Base64.
 */
class Base64 {
private:
  /** Encoing table */
  static const unsigned char _table[];
  /** Padding character */
  static const unsigned char _padding;

  /** Decode one symbol */
  static inline int b2n(int b);
  /** Encode one symbol */
  static inline int n2b(int n);

public:

  /**
   * @brief Decode a %Base64 encoded string.
   *
   * @param src Source %Base64 encoded string.
   * @param dest Destination to hold the decoded string.
   * @return Size of destination string.
   */
  static int decode(const std::string &src, std::string &dest);

  /**
   * @brief Decode a %Base64 encoded string.
   *
   * @param src Source string.
   * @param dest Destination to hold %Base64 encoded string.
   * @return Size of destination string.
   */
  static int encode(const std::string &src, std::string &dest);

};

} // namespace fsa