00001 /// @file include/dmlite/cpp/utils/checksums.h 00002 /// @brief Utility methods for checksum handling 00003 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch> 00004 #ifndef DMLITE_CPP_UTILS_CHECKSUMS_H 00005 #define DMLITE_CPP_UTILS_CHECKSUMS_H 00006 00007 #include <dmlite/cpp/io.h> 00008 #include <string> 00009 00010 namespace dmlite { 00011 namespace checksums { 00012 00013 /// To be used internally by the plug-ins that need to deal 00014 /// with the legacy-style stored checksums. 00015 /// @note AD => ADLER32 00016 /// @note CS => CRC32 00017 /// @note MD => MD5 (RFC 3230) 00018 /// @note Any other is left as is 00019 std::string fullChecksumName(const std::string& cs); 00020 00021 /// Inverse of fullChecksumName 00022 /// This should eventually disappear, once the backends can deal with 00023 /// full checksum names. 00024 std::string shortChecksumName(const std::string& cs); 00025 00026 /// Returns the MD5 checksum of the data contained on the IO handler 00027 /// in hexadecimal format. 00028 /// @param io The IO handler to be digested. The read/write possition will be moved! 00029 /// @param offset Where to start to digest. 00030 /// @param size The number of bytes to digest. 0 means the whole file. 00031 /// @return The MD5 checkum in base 16 00032 std::string md5(IOHandler* io, off_t offset = 0, off_t size = 0); 00033 00034 /// Returns the CRC checksum of the data contained on the IO handler (as zlib crc32) 00035 /// in base 10 format. 00036 /// @param io The IO handler to be digested. The read/write possition will be moved! 00037 /// @param offset Where to start to digest. 00038 /// @param size The number of bytes to digest. 0 means the whole file. 00039 /// @return The CRC checkum in base 10 00040 std::string crc32(IOHandler* io, off_t offset = 0, off_t size = 0); 00041 00042 /// Returns the Adler32 checksum of the data contained on the IO handler 00043 /// in hexadecimal format. 00044 /// @param io The IO handler to be digested. The read/write possition will be moved! 00045 /// @param offset Where to start to digest. 00046 /// @param size The number of bytes to digest. 0 means the whole file. 00047 /// @return The Adler32 checkum in base 16 00048 std::string adler32(IOHandler* io, off_t offset = 0, off_t size = 0); 00049 00050 /// Returns the hexadecimal representation of the data 00051 /// @param data The data to dump to hexadecimal representation. 00052 /// @param nbytes The number of bytes in data 00053 std::string hexPrinter(const unsigned char* data, size_t nbytes); 00054 00055 /// Returns the decimal representation of the data, separated by spaces 00056 /// (num1 num2 num3) 00057 /// @param data The data to dump to decimal representation. 00058 /// @param nbytes The number of bytes in data 00059 /// @note It assumes data is an array of 'unsigned long' 00060 std::string decPrinter(const unsigned char* data, size_t nbytes); 00061 00062 } 00063 } 00064 00065 #endif // DMLITE_CPP_UTILS_CHECKSUMS_H