Commit 3c576c35 authored by Michael Davis's avatar Michael Davis
Browse files

[checksum] Fixes some bugs

- Type of checksumBlob in cta.proto should be bytes not string
- ADLER32 passed into blob as uint32_t not string (conversion to
  bytearray is now handled inside the ChecksumBlob class)
parent 5abd8cf2
......@@ -720,18 +720,6 @@ uint32_t getAdler32(const uint8_t *buf, const uint32_t len)
return adler32(checksum, (const Bytef*)buf, len);
}
//------------------------------------------------------------------------------
// getAdler32String
//------------------------------------------------------------------------------
std::string getAdler32String(const uint8_t *buf, const uint32_t len)
{
const uint32_t checksum = adler32(0L, Z_NULL, 0);
std::stringstream ret;
ret << "0X" << std::noshowbase << std::hex << std::setw(8) << std::setfill('0') << std::uppercase
<< adler32(checksum, (const Bytef*)buf, len);
return ret.str();
}
//------------------------------------------------------------------------------
// getShortHostname
//------------------------------------------------------------------------------
......
......@@ -325,16 +325,6 @@ namespace utils {
*/
uint32_t getAdler32(const uint8_t *buf, const uint32_t len);
/**
* Returns the alder32 checksum of the specified buffer in string format,
* CTA style that is with leading 0x, 8 digits with leading 0 and uppercase.
*
* @param buf The buffer.
* @param len The length of the buffer in bytes.
* @return the alder32 checksum of the specified buffer.
*/
std::string getAdler32String(const uint8_t *buf, const uint32_t len);
/**
* Returns true if the attributes of the current process indicate that it will
* produce a core dump if it receives a signal whose behaviour is to produce a
......
......@@ -181,7 +181,7 @@ message TapeFile {
required uint64 creationtime = 9125;
//required string checksumtype = 9126; DEPRECATED
//required string checksumvalue = 9127; DEPRECATED
required string checksumblob = 9128;
required bytes checksumblob = 9128;
}
message DiskFileInfo {
......@@ -201,7 +201,7 @@ message ArchiveFile {
required DiskFileInfo diskfileinfo= 4355;
//required string checksumtype = 4356; DEPRECATED
//required string checksumvalue = 4357; DEPRECATED
required string checksumblob = 4362;
required bytes checksumblob = 4362;
required uint64 creationtime = 4358;
repeated TapeFile tapefiles = 4359;
required uint64 reconciliationtime = 4360;
......@@ -327,7 +327,7 @@ message ArchiveRequest {
required MountPolicy mountpolicy = 8995;
//required string checksumtype = 9000; DEPRECATED
//required string checksumvalue = 9010; DEPRECATED
required string checksumblob = 9011;
required bytes checksumblob = 9011;
required uint64 creationtime = 9015;
required uint64 reconcilationtime = 9017;
required DiskFileInfo diskfileinfo = 9040;
......
......@@ -437,7 +437,7 @@ TEST_P(DataTransferSessionTest, DataTransferSessionGooddayRecall) {
// Create file entry in the archive namespace
tapeFileWritten.archiveFileId=fseq;
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::utils::getAdler32String(data, archiveFileSize));
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::utils::getAdler32(data, archiveFileSize));
tapeFileWritten.vid=volInfo.vid;
tapeFileWritten.size=archiveFileSize;
tapeFileWritten.fSeq=fseq;
......@@ -616,7 +616,7 @@ TEST_P(DataTransferSessionTest, DataTransferSessionWrongRecall) {
std::set<cta::catalogue::TapeItemWrittenPointer> tapeFileWrittenSet;
tapeFileWrittenSet.insert(tapeFileWrittenUP.release());
tapeFileWritten.archiveFileId=666;
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, "0xDEADBEEF");
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::checksum::ChecksumBlob::HexToByteArray("0xDEADBEEF"));
tapeFileWritten.vid=volInfo.vid;
tapeFileWritten.size=archiveFileSize;
tapeFileWritten.fSeq=fseq;
......@@ -639,7 +639,7 @@ TEST_P(DataTransferSessionTest, DataTransferSessionWrongRecall) {
std::set<cta::catalogue::TapeItemWrittenPointer> tapeFileWrittenSet;
tapeFileWrittenSet.insert(tapeFileWrittenUP.release());
tapeFileWritten.archiveFileId=1000 + fseq;
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::utils::getAdler32String(data, archiveFileSize));
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::utils::getAdler32(data, archiveFileSize));
tapeFileWritten.vid=volInfo.vid;
tapeFileWritten.size=archiveFileSize;
tapeFileWritten.fSeq=fseq + 1;
......@@ -814,7 +814,7 @@ TEST_P(DataTransferSessionTest, DataTransferSessionRAORecall) {
// Create file entry in the archive namespace
tapeFileWritten.archiveFileId=fseq;
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::utils::getAdler32String(data, archiveFileSize));
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::utils::getAdler32(data, archiveFileSize));
tapeFileWritten.vid=volInfo.vid;
tapeFileWritten.size=archiveFileSize;
tapeFileWritten.fSeq=fseq;
......@@ -1023,7 +1023,7 @@ TEST_P(DataTransferSessionTest, DataTransferSessionNoSuchDrive) {
// Create file entry in the archive namespace
tapeFileWritten.archiveFileId=fseq;
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::utils::getAdler32String(data, archiveFileSize));
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::utils::getAdler32(data, archiveFileSize));
tapeFileWritten.vid=volInfo.vid;
tapeFileWritten.size=archiveFileSize;
tapeFileWritten.fSeq=fseq;
......@@ -1169,7 +1169,7 @@ TEST_P(DataTransferSessionTest, DataTransferSessionFailtoMount) {
// Create file entry in the archive namespace
tapeFileWritten.archiveFileId=fseq;
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::utils::getAdler32String(data, archiveFileSize));
tapeFileWritten.checksumBlob.insert(cta::checksum::ADLER32, cta::utils::getAdler32(data, archiveFileSize));
tapeFileWritten.vid=volInfo.vid;
tapeFileWritten.size=archiveFileSize;
tapeFileWritten.fSeq=fseq;
......
......@@ -57,14 +57,14 @@ void TempFile::randomFill(size_t size) {
out.write(buff.get(), size);
}
std::string TempFile::adler32() {
uint32_t TempFile::adler32() {
struct ::stat fileStat;
cta::exception::Errnum::throwOnMinusOne(::stat(m_path.c_str(), &fileStat),
"In TempFile::adler32(): failed to stat file.");
std::unique_ptr<char[] > buff(new char[fileStat.st_size]);
std::ifstream in(m_path, std::ios::in | std::ios::binary);
in.read(buff.get(), fileStat.st_size);
return cta::utils::getAdler32String((uint8_t*)buff.get(), fileStat.st_size);
return cta::utils::getAdler32((uint8_t*)buff.get(), fileStat.st_size);
}
void TempFile::stringFill(const std::string& string) {
......@@ -77,4 +77,4 @@ void TempFile::stringAppend(const std::string& string) {
out << string;
}
}
\ No newline at end of file
}
......@@ -31,11 +31,11 @@ public:
TempFile(const std::string& path);
std::string path();
void randomFill(size_t size);
std::string adler32();
uint32_t adler32();
void stringFill(const std::string &string);
void stringAppend(const std::string &string);
~TempFile();
private:
std::string m_path;
};
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment