/usr/include/modp_b85.h is in libmodpbase64-dev 3.10.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
/* vi: set expandtab shiftwidth=4 tabstop=4: */
/**
* \file
* <pre>
* High Performance Base85 Encoder / Decoder
*
* Copyright © 2006,2007 Nick Galbreath -- nickg [at] modp [dot] com
* All rights reserved.
*
* http://code.google.com/p/stringencoders/
*
* Released under bsd license. See modp_b85.c for details.
* </PRE>
*
* This provides a endian-safe base85 encode/decode operations. This
* means, the result will be the same on x86 or ibm/sparc chips.
*
* (Note: making it endian-specifc only results in a 5% savings in
* the decode operation, so why bother)
*/
#ifndef COM_MODP_STRINGENCODERS_B85
#define COM_MODP_STRINGENCODERS_B85
#ifdef __cplusplus
#define BEGIN_C extern "C" {
#define END_C }
#else
#define BEGIN_C
#define END_C
#endif
BEGIN_C
/**
* base 85 encode
*
* \param[out] dest should have at least b85fast_encode_len memory allocated
* \param[in] src input string
* \param[in] len input string length, must be a multiple of 4
* \return the strlen of the destination, or -1 if error
*/
int modp_b85_encode(char* dest, const char* src, int len);
/**
* Base 85 decode
*
* \param[out] dest -- destination locations. May equal input.
* \param[in] src -- source b85data
* \param len -- length of source
* \return -1 on decoding error, length of output otherwise
* No ending null is added
*/
int modp_b85_decode(char* dest, const char* src, int len);
/**
* Returns the amount of memory to allocate for encoding the input
* string.
*
*/
#define modp_b85_encode_len(A) ((A + 3) / 4 * 5 + 1)
/**
* Return output strlen, without a NULL
*/
#define modp_b85_encode_strlen(A) ((A + 3) / 4 * 5)
/**
* Return the amount of memory to allocate for decoding a base 85
* encoded string.
*
*/
#define modp_b85_decode_len(A) ((A + 4) / 5 * 4)
END_C
#ifdef __cplusplus
#include <cstring>
#include <string>
namespace modp {
/**
*
* \param[in] s the input data
* \param[in] len the length of input
* \return b85 encoded string
*/
inline std::string b85_encode(const char* s, size_t len)
{
std::string x(modp_b85_encode_len(len), '\0');
int d = modp_b85_encode(const_cast<char*>(x.data()), s,
static_cast<int>(len));
if (d < 0) {
x.clear();
} else {
x.erase(d, std::string::npos);
}
return x;
}
/**
* \param[in] null-terminated c-string input
* \return b85 encoded string
*/
inline std::string b85_encode(const char* s)
{
return b85_encode(s, strlen(s));
}
/**
* /param[in,out] s the string to encode
* /return a reference to the input string, empty if error
*/
inline std::string& b85_encode(std::string& s)
{
std::string x(b85_encode(s.data(), s.size()));
s.swap(x);
return s;
}
/**
* \param[in] s the input string
* \return base85 encoded string
*/
inline std::string b85_encode(const std::string& s)
{
return b85_encode(s.data(), s.size());
}
/**
* Base85 decode a string.
* This function does not allocate memory.
*
* \param s the string to decode
* \return a reference to the input string. The string is empty
* if an error occurred.
*/
inline std::string& b85_decode(std::string& s)
{
int d = modp_b85_decode(const_cast<char*>(s.data()), s.data(),
static_cast<int>(s.size()));
if (d < 0) {
s.clear();
} else {
s.erase(d, std::string::npos);
}
return s;
}
inline std::string b85_decode(const std::string& s)
{
std::string x(s);
b85_decode(x);
return x;
}
inline std::string b85_decode(const char* s, size_t len)
{
std::string x(s,len);
return b85_decode(x);
}
inline std::string b85_decode(const char* s)
{
std::string x(s);
return b85_decode(x);
}
} /* namespace modp */
#endif /* ifdef __cplusplus */
#endif /* ifndef MODP_B85 */
|