aboutsummaryrefslogtreecommitdiff
path: root/butl/base64
blob: 7a0e999e5133cfb8aecd6f5689c738993bd3e0cf (plain)
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
// file      : butl/base64 -*- C++ -*-
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BUTL_BASE64
#define BUTL_BASE64

#include <iosfwd>
#include <string>
#include <vector>

namespace butl
{
  // Base64-encode a stream or a buffer. Split the output into 76 char-long
  // lines (new line is the 77th). If reading from a stream, check if it has
  // badbit, failbit, or eofbit set and throw invalid_argument if that's the
  // case. Otherwise, set eofbit on completion. If writing to a stream, check
  // if it has badbit, failbit, or eofbit set and throw invalid_argument if
  // that's the case. Otherwise set badbit if the write operation fails.
  //
  void
  base64_encode (std::ostream&, std::istream&);

  std::string
  base64_encode (std::istream&);

  std::string
  base64_encode (const std::vector<char>&);

  // Base64-decode a stream or a string. Throw invalid_argument if the input
  // is not a valid base64 representation. If reading from a stream, check if
  // it has badbit, failbit, or eofbit set and throw invalid_argument if
  // that's the case. Otherwise, set eofbit on completion. If writing to a
  // stream, check if it has badbit, failbit, or eofbit set and throw
  // invalid_argument if that's the case. Otherwise set badbit if the write
  // operation fails.
  //
  void
  base64_decode (std::ostream&, std::istream&);

  void
  base64_decode (std::ostream&, const std::string&);

  std::vector<char>
  base64_decode (const std::string&);
};

#endif // BUTL_BASE64