Lolly 1.4.27
Loading...
Searching...
No Matches
md5.cpp
Go to the documentation of this file.
1
2/******************************************************************************
3 * MODULE : md5.cpp
4 * DESCRIPTION: md5 digest
5 * COPYRIGHT : (C) 2023 Darcy Shen
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12#include "md5.hpp"
13#include "analyze.hpp"
14#include "file.hpp"
16
17#include <tbox/tbox.h>
18
19namespace lolly {
20namespace hash {
21string
23 if (!is_local_and_single (u)) {
24 return string ("");
25 }
26 string name= as_string (u);
27 const char* path= as_charp (name);
28 if (!tb_file_access (path, TB_FILE_MODE_RO)) {
29 return string ("");
30 }
32 if (file == tb_null) {
33 return string ("");
34 }
36 if (i_size == 0) {
37 return "d41d8cd98f00b204e9800998ecf8427e";
38 }
39 tb_file_sync (file); // lock file
42 bool read_sz_equ= (real_size == i_size);
43 bool exit_suc = tb_file_exit (file); // exit file
44 if (read_sz_equ && exit_suc) {
47 if (o_size != 16) {
48 return string ("");
49 }
50
51 string md5_hex= string ();
52 for (int i= 0; i < 16; ++i) {
54 }
55 return md5_hex;
56 }
57 else {
58 return string ("");
59 }
60}
61} // namespace hash
62} // namespace lolly
int hash(pointer ptr)
Computes a hash value for a pointer.
Definition basic.cpp:17
The list class represents a linked list.
Definition list.hpp:48
Definition url.hpp:37
bool is_local_and_single(url u)
Definition file.cpp:22
string to_padded_hex(uint8_t i)
Converts an 8-bit unsigned integer to a fixed-length (2) hex string.
Definition numeral.cpp:153
string md5_hexdigest(url u)
Definition md5.cpp:22
char * as_charp(string s)
Definition string.cpp:294
string as_string(int16_t i)
Definition string.cpp:310