mirror of https://github.com/dnomd343/md5sum.git
6 changed files with 81 additions and 72 deletions
@ -0,0 +1,6 @@ |
|||||
|
cmake_minimum_required(VERSION 3.5) |
||||
|
project(md5sum LANGUAGES CXX) |
||||
|
|
||||
|
set(CMAKE_CXX_STANDARD 11) |
||||
|
|
||||
|
add_library(md5sum STATIC md5.cc md5_impl.cc) |
@ -1,10 +0,0 @@ |
|||||
#include <iostream> |
|
||||
#include "md5sum.h" |
|
||||
|
|
||||
int main() { |
|
||||
auto ret = md5sum("dnomd343"); |
|
||||
std::cout << ret << std::endl; |
|
||||
|
|
||||
auto val = md5file("/Users/jucong.lin/klotski/third_party/md5sum/343.txt"); |
|
||||
std::cout << val << std::endl; |
|
||||
} |
|
@ -1,50 +1,54 @@ |
|||||
#include "md5sum.h" |
#include "md5sum.h" |
||||
#include "md5def.h" |
#include "md5def.h" |
||||
|
|
||||
static char hb2hex(uint8_t hb) { |
namespace md5 { |
||||
hb &= 0xF; |
|
||||
return hb < 10 ? '0' + hb : hb - 10 + 'a'; |
static char hb2hex(uint8_t hb) { |
||||
} |
hb &= 0xF; |
||||
|
return char(hb < 10 ? hb + '0' : hb - 10 + 'a'); |
||||
std::string md5sum(const std::string &dat) { |
} |
||||
return md5sum(dat.c_str(), dat.length()); |
|
||||
} |
std::string md5sum(const std::string &dat) { |
||||
|
return md5sum(dat.c_str(), dat.length()); |
||||
std::string md5sum(const void *dat, size_t len) { |
} |
||||
uint8_t out[16]; |
|
||||
md5_bin(dat, len, out); |
std::string md5sum(const void *dat, size_t len) { |
||||
|
uint8_t out[16]; |
||||
std::string res; |
md5_bin(dat, len, out); |
||||
for (auto x : out) { |
|
||||
res.push_back(hb2hex(x >> 4)); |
std::string res; |
||||
res.push_back(hb2hex(x)); |
for (auto x : out) { |
||||
} |
res.push_back(hb2hex(x >> 4)); |
||||
return res; |
res.push_back(hb2hex(x)); |
||||
} |
} |
||||
|
return res; |
||||
std::string md5file(const char *filename) { |
} |
||||
std::FILE *file = std::fopen(filename, "rb"); |
|
||||
std::string res = md5file(file); |
std::string md5file(const char *filename) { |
||||
std::fclose(file); |
std::FILE *file = std::fopen(filename, "rb"); |
||||
return res; |
std::string res = md5file(file); |
||||
} |
std::fclose(file); |
||||
|
return res; |
||||
std::string md5file(std::FILE *file) { |
} |
||||
MD5_CTX c; |
|
||||
md5_init(&c); |
std::string md5file(std::FILE *file) { |
||||
|
MD5_CTX c; |
||||
uint8_t out[16]; |
md5_init(&c); |
||||
size_t len = 0; |
|
||||
char buff[BUFSIZ]; |
size_t len; |
||||
while ((len = std::fread(buff, sizeof(char), BUFSIZ, file)) > 0) { |
uint8_t out[16]; |
||||
md5_update(&c, buff, len); |
char buff[BUFSIZ]; |
||||
} |
while ((len = std::fread(buff, sizeof(char), BUFSIZ, file)) > 0) { |
||||
md5_final(out, &c); |
md5_update(&c, buff, len); |
||||
|
} |
||||
std::string res; |
md5_final(out, &c); |
||||
for (auto x : out) { |
|
||||
res.push_back(hb2hex(x >> 4)); |
std::string res; |
||||
res.push_back(hb2hex(x)); |
for (auto x : out) { |
||||
} |
res.push_back(hb2hex(x >> 4)); |
||||
return res; |
res.push_back(hb2hex(x)); |
||||
} |
} |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
} // namespace md5
|
||||
|
@ -1,12 +1,13 @@ |
|||||
#ifndef MD5_H |
#pragma once |
||||
#define MD5_H |
|
||||
|
#include <string> |
||||
#include <string> |
|
||||
|
namespace md5 { |
||||
std::string md5sum(const std::string &dat); |
|
||||
std::string md5sum(const void *dat, size_t len); |
std::string md5sum(const std::string &dat); |
||||
|
std::string md5sum(const void *dat, size_t len); |
||||
std::string md5file(std::FILE *file); |
|
||||
std::string md5file(const char *filename); |
std::string md5file(std::FILE *file); |
||||
|
std::string md5file(const char *filename); |
||||
#endif // end of MD5_H
|
|
||||
|
} // namespace md5
|
||||
|
Loading…
Reference in new issue