shared
This commit is contained in:
parent
60e9949663
commit
ca1de6237f
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
|
|
||||||
#define PUT_BIT_LE(i, cp, value) do { \
|
#define PUT_BIT_LE(i, cp, value) do { \
|
||||||
(cp)[i] = (uint8_t)(((value) >> 8 * i) & 0xFF); \
|
(cp)[i] = (uint8_t)(((value) >> 8 * i) & 0xFF); \
|
||||||
@ -76,15 +76,15 @@ MD5Init(MD5_CTX *ctx)
|
|||||||
void
|
void
|
||||||
MD5Update(MD5_CTX *ctx, const void *inputptr, size_t len)
|
MD5Update(MD5_CTX *ctx, const void *inputptr, size_t len)
|
||||||
{
|
{
|
||||||
const uint8_t *input = (const uint8_t *)inputptr;
|
auto input = static_cast<const uint8_t *>(inputptr);
|
||||||
size_t have, need;
|
size_t have, need;
|
||||||
|
|
||||||
/* Check how many bytes we already have and how many more we need. */
|
/* Check how many bytes we already have and how many more we need. */
|
||||||
have = (size_t)((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1));
|
have = static_cast<size_t>((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1));
|
||||||
need = MD5_BLOCK_LENGTH - have;
|
need = MD5_BLOCK_LENGTH - have;
|
||||||
|
|
||||||
/* Update bitcount */
|
/* Update bitcount */
|
||||||
ctx->count += (uint64_t)len << 3;
|
ctx->count += static_cast<uint64_t>(len) << 3;
|
||||||
|
|
||||||
if (len >= need) {
|
if (len >= need) {
|
||||||
if (have != 0) {
|
if (have != 0) {
|
||||||
@ -273,7 +273,7 @@ string& MD5HexPrint(const string& digest, string &out)
|
|||||||
out.erase();
|
out.erase();
|
||||||
out.reserve(33);
|
out.reserve(33);
|
||||||
static const char hex[]="0123456789abcdef";
|
static const char hex[]="0123456789abcdef";
|
||||||
const unsigned char *hash = (const unsigned char *)digest.c_str();
|
auto hash = (const unsigned char *)digest.c_str();
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
out.append(1, hex[hash[i] >> 4]);
|
out.append(1, hex[hash[i] >> 4]);
|
||||||
out.append(1, hex[hash[i] & 0x0f]);
|
out.append(1, hex[hash[i] & 0x0f]);
|
||||||
|
|||||||
@ -1156,6 +1156,22 @@ secondelt:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string hexprint(const std::string& in, char separ)
|
||||||
|
{
|
||||||
|
string out;
|
||||||
|
out.reserve(separ ? (3 *in.size()) : (2 * in.size()));
|
||||||
|
static const char hex[]="0123456789abcdef";
|
||||||
|
auto cp = (const unsigned char *)in.c_str();
|
||||||
|
for (unsigned int i = 0; i < in.size(); i++) {
|
||||||
|
out.append(1, hex[cp[i] >> 4]);
|
||||||
|
out.append(1, hex[cp[i] & 0x0f]);
|
||||||
|
if (separ && i != in.size() - 1)
|
||||||
|
out.append(1, separ);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// We'd like these static, but then, as only one is used, this
|
// We'd like these static, but then, as only one is used, this
|
||||||
// triggers a 'defined but not used' warning.
|
// triggers a 'defined but not used' warning.
|
||||||
char *_check_strerror_r(int, char *errbuf)
|
char *_check_strerror_r(int, char *errbuf)
|
||||||
|
|||||||
@ -205,6 +205,10 @@ inline void leftzeropad(std::string& s, unsigned len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print binary string in hexa, separate bytes with character separ if not zero
|
||||||
|
// (e.g. ac:23:0c:4f:46:fd)
|
||||||
|
extern std::string hexprint(const std::string& in, char separ= 0);
|
||||||
|
|
||||||
// A class to solve platorm/compiler issues for simple regex
|
// A class to solve platorm/compiler issues for simple regex
|
||||||
// matches. Uses the appropriate native lib under the hood.
|
// matches. Uses the appropriate native lib under the hood.
|
||||||
// This always uses extended regexp syntax.
|
// This always uses extended regexp syntax.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user