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 
10 namespace dmlite {
11 namespace checksums {
12 
13 /// To be used internally by the plug-ins that need to deal
14 /// with the legacy-style stored checksums.
15 /// @note AD => ADLER32
16 /// @note CS => CRC32
17 /// @note MD => MD5 (RFC 3230)
18 /// @note Any other is left as is
19 std::string fullChecksumName(const std::string& cs);
20 
21 /// Inverse of fullChecksumName
22 /// This should eventually disappear, once the backends can deal with
23 /// full checksum names.
24 std::string shortChecksumName(const std::string& cs);
25 
26 /// Returns the MD5 checksum of the data contained on the IO handler
27 /// in hexadecimal format.
28 /// @param io The IO handler to be digested. The read/write possition will be moved!
29 /// @param offset Where to start to digest.
30 /// @param size The number of bytes to digest. 0 means the whole file.
31 /// @return The MD5 checkum in base 16
32 std::string md5(IOHandler* io, off_t offset = 0, off_t size = 0);
33 
34 /// Returns the CRC checksum of the data contained on the IO handler (as zlib crc32)
35 /// in base 10 format.
36 /// @param io The IO handler to be digested. The read/write possition will be moved!
37 /// @param offset Where to start to digest.
38 /// @param size The number of bytes to digest. 0 means the whole file.
39 /// @return The CRC checkum in base 10
40 std::string crc32(IOHandler* io, off_t offset = 0, off_t size = 0);
41 
42 /// Returns the Adler32 checksum of the data contained on the IO handler
43 /// in hexadecimal format.
44 /// @param io The IO handler to be digested. The read/write possition will be moved!
45 /// @param offset Where to start to digest.
46 /// @param size The number of bytes to digest. 0 means the whole file.
47 /// @return The Adler32 checkum in base 16
48 std::string adler32(IOHandler* io, off_t offset = 0, off_t size = 0);
49 
50 /// Returns the hexadecimal representation of the data
51 /// @param data The data to dump to hexadecimal representation.
52 /// @param nbytes The number of bytes in data
53 std::string hexPrinter(const unsigned char* data, size_t nbytes);
54 
55 /// Returns the decimal representation of the data, separated by spaces
56 /// (num1 num2 num3)
57 /// @param data The data to dump to decimal representation.
58 /// @param nbytes The number of bytes in data
59 /// @note It assumes data is an array of 'unsigned long'
60 std::string decPrinter(const unsigned char* data, size_t nbytes);
61 
62 }
63 }
64 
65 #endif // DMLITE_CPP_UTILS_CHECKSUMS_H