Coverage Report

Created: 2026-05-07 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libsass/src/b64/encode.h
Line
Count
Source
1
// :mode=c++:
2
/*
3
encode.h - c++ wrapper for a base64 encoding algorithm
4
5
This is part of the libb64 project, and has been placed in the public domain.
6
For details, see http://sourceforge.net/projects/libb64
7
*/
8
#ifndef BASE64_ENCODE_H
9
#define BASE64_ENCODE_H
10
11
#include <iostream>
12
13
namespace base64
14
{
15
  extern "C"
16
  {
17
    #include "cencode.h"
18
  }
19
20
  struct encoder
21
  {
22
    base64_encodestate _state;
23
    int _buffersize;
24
25
    encoder(int buffersize_in = BUFFERSIZE)
26
0
    : _buffersize(buffersize_in)
27
0
    {
28
0
      base64_init_encodestate(&_state);
29
0
    }
30
31
    int encode(char value_in)
32
0
    {
33
0
      return base64_encode_value(value_in);
34
0
    }
35
36
    int encode(const char* code_in, const int length_in, char* plaintext_out)
37
0
    {
38
0
      return base64_encode_block(code_in, length_in, plaintext_out, &_state);
39
0
    }
40
41
    int encode_end(char* plaintext_out)
42
0
    {
43
0
      return base64_encode_blockend(plaintext_out, &_state);
44
0
    }
45
46
    void encode(std::istream& istream_in, std::ostream& ostream_in)
47
0
    {
48
0
      base64_init_encodestate(&_state);
49
      //
50
0
      const int N = _buffersize;
51
0
      char* plaintext = new char[N];
52
0
      char* code = new char[2*N];
53
0
      int plainlength;
54
0
      int codelength;
55
56
0
      do
57
0
      {
58
0
        istream_in.read(plaintext, N);
59
0
        plainlength = static_cast<int>(istream_in.gcount());
60
        //
61
0
        codelength = encode(plaintext, plainlength, code);
62
0
        ostream_in.write(code, codelength);
63
0
      }
64
0
      while (istream_in.good() && plainlength > 0);
65
66
0
      codelength = encode_end(code);
67
0
      ostream_in.write(code, codelength);
68
      //
69
0
      base64_init_encodestate(&_state);
70
71
0
      delete [] code;
72
0
      delete [] plaintext;
73
0
    }
74
  };
75
76
} // namespace base64
77
78
#endif // BASE64_ENCODE_H
79