dmlite 0.6
checksums.h
Go to the documentation of this file.
1/// @file include/dmlite/cpp/utils/checksums.h
2/// @brief Utility methods for checksum handling
3/// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
4#ifndef DMLITE_CPP_UTILS_CHECKSUMS_H
5#define DMLITE_CPP_UTILS_CHECKSUMS_H
6
7#include <dmlite/cpp/io.h>
8#include <string>
9
10namespace dmlite {
11 class ExtendedStat;
12
13namespace checksums {
14
15
16
17/// To be used internally by the plug-ins that need to deal
18/// with the legacy-style stored checksums.
19/// @note AD => ADLER32
20/// @note CS => CRC32
21/// @note MD => MD5 (RFC 3230)
22/// @note Any other is left as is
23std::string fullChecksumName(const std::string& cs);
24
25/// Inverse of fullChecksumName
26/// This should eventually disappear, once the backends can deal with
27/// full checksum names.
28std::string shortChecksumName(const std::string& cs);
29
30/// Tells if the given key looks like the name of a checksum
31bool isChecksumFullName(const std::string& ckey);
32
33/// Makes sure that the extended attributes contain the legacy checksum.
34/// @param xstat The stat information to be modified
35/// @return Zero if the xattrs were not modified
37
38/// Returns the MD5 checksum of the data contained on the IO handler
39/// in hexadecimal format.
40/// @param io The IO handler to be digested. The read/write possition will be moved!
41/// @param offset Where to start to digest.
42/// @param size The number of bytes to digest. 0 means the whole file.
43/// @return The MD5 checkum in base 16
44std::string md5(IOHandler* io, off_t offset = 0, off_t size = 0);
45
46/// Returns the CRC checksum of the data contained on the IO handler (as zlib crc32)
47/// in base 10 format.
48/// @param io The IO handler to be digested. The read/write possition will be moved!
49/// @param offset Where to start to digest.
50/// @param size The number of bytes to digest. 0 means the whole file.
51/// @return The CRC checkum in base 10
52std::string crc32(IOHandler* io, off_t offset = 0, off_t size = 0);
53
54/// Returns the Adler32 checksum of the data contained on the IO handler
55/// in hexadecimal format.
56/// @param io The IO handler to be digested. The read/write possition will be moved!
57/// @param offset Where to start to digest.
58/// @param size The number of bytes to digest. 0 means the whole file.
59/// @return The Adler32 checkum in base 16
60std::string adler32(IOHandler* io, off_t offset = 0, off_t size = 0);
61
62/// Returns the hexadecimal representation of the data
63/// @param data The data to dump to hexadecimal representation.
64/// @param nbytes The number of bytes in data
65std::string hexPrinter(const unsigned char* data, size_t nbytes);
66
67/// Returns the decimal representation of the data, separated by spaces
68/// (num1 num2 num3)
69/// @param data The data to dump to decimal representation.
70/// @param nbytes The number of bytes in data
71/// @note It assumes data is an array of 'unsigned long'
72std::string decPrinter(const unsigned char* data, size_t nbytes);
73
74}
75}
76
77#endif // DMLITE_CPP_UTILS_CHECKSUMS_H
File/directory metadata.
Definition inode.h:29
IO interface.
Definition io.h:26
I/O API. Abstracts how to write or read to/from a disk within a pool.
std::string crc32(IOHandler *io, off_t offset=0, off_t size=0)
std::string md5(IOHandler *io, off_t offset=0, off_t size=0)
std::string adler32(IOHandler *io, off_t offset=0, off_t size=0)
std::string shortChecksumName(const std::string &cs)
int fillChecksumInXattr(ExtendedStat &xstat)
std::string decPrinter(const unsigned char *data, size_t nbytes)
std::string hexPrinter(const unsigned char *data, size_t nbytes)
bool isChecksumFullName(const std::string &ckey)
Tells if the given key looks like the name of a checksum.
std::string fullChecksumName(const std::string &cs)
Namespace for the dmlite C++ API.
Definition authn.h:16