GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: base64.h Lines: 6 6 100.0 %
Date: 2022-10-23 04:21:34 Branches: 3 4 75.0 %

Line Branch Exec Source
1
#ifndef SRC_BASE64_H_
2
#define SRC_BASE64_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "util.h"
7
8
#include <cmath>
9
#include <cstddef>
10
#include <cstdint>
11
12
namespace node {
13
//// Base 64 ////
14
15
enum class Base64Mode {
16
  NORMAL,
17
  URL
18
};
19
20
16596
static inline constexpr size_t base64_encoded_size(
21
    size_t size,
22
    Base64Mode mode = Base64Mode::NORMAL) {
23
16596
  return mode == Base64Mode::NORMAL ? ((size + 2) / 3 * 4)
24
11011
                                    : static_cast<size_t>(std::ceil(
25
16596
                                          static_cast<double>(size * 4) / 3));
26
}
27
28
// Doesn't check for padding at the end.  Can be 1-2 bytes over.
29
7315
static inline constexpr size_t base64_decoded_size_fast(size_t size) {
30
  // 1-byte input cannot be decoded
31
7315
  return size > 1 ? (size / 4) * 3 + (size % 4 + 1) / 2 : 0;
32
}
33
34
inline uint32_t ReadUint32BE(const unsigned char* p);
35
36
template <typename TypeName>
37
size_t base64_decoded_size(const TypeName* src, size_t size);
38
39
template <typename TypeName>
40
size_t base64_decode(char* const dst, const size_t dstlen,
41
                     const TypeName* const src, const size_t srclen);
42
43
inline size_t base64_encode(const char* src,
44
                            size_t slen,
45
                            char* dst,
46
                            size_t dlen,
47
                            Base64Mode mode = Base64Mode::NORMAL);
48
}  // namespace node
49
50
51
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
52
53
#endif  // SRC_BASE64_H_