summaryrefslogtreecommitdiff
path: root/src/MultiDiskWriter.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-08-14 13:48:31 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-08-14 13:48:31 +0000
commit2f14fec78dfc96b88a905621d35f1d726df0791d (patch)
tree8eb4dc9cf94f021ccbdf77dca88924c2c9bf4cea /src/MultiDiskWriter.cc
parent43dae4fd916bb35bf7fd8554fc86ce34c3e7a31b (diff)
parent7ca1b43eddd1aba1c71a38dfb46b5ac5685b43d0 (diff)
Tagging 0.7.0 release of aria2release-0.7.0
Diffstat (limited to 'src/MultiDiskWriter.cc')
-rw-r--r--src/MultiDiskWriter.cc27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/MultiDiskWriter.cc b/src/MultiDiskWriter.cc
index f40f6da0..d0a13776 100644
--- a/src/MultiDiskWriter.cc
+++ b/src/MultiDiskWriter.cc
@@ -25,18 +25,15 @@
#include "message.h"
#include <errno.h>
-MultiDiskWriter::MultiDiskWriter(int pieceLength):pieceLength(pieceLength) {
-#ifdef ENABLE_MESSAGE_DIGEST
- ctx.setAlgo(MessageDigestContext::ALGO_SHA1);
- digestInit(ctx);
-#endif // ENABLE_MESSAGE_DIGEST
+MultiDiskWriter::MultiDiskWriter(int pieceLength):
+ pieceLength(pieceLength),
+ ctx(DIGEST_ALGO_SHA1) {
+ ctx.digestInit();
}
MultiDiskWriter::~MultiDiskWriter() {
clearEntries();
-#ifdef ENABLE_MESSAGE_DIGEST
- digestFree(ctx);
-#endif // ENABLE_MESSAGE_DIGEST
+ ctx.digestFree();
}
void MultiDiskWriter::clearEntries() {
@@ -143,7 +140,6 @@ int MultiDiskWriter::readData(char* data, int len, long long int offset) {
return totalReadLength;
}
-#ifdef ENABLE_MESSAGE_DIGEST
void MultiDiskWriter::hashUpdate(DiskWriterEntry* entry, long long int offset, long long int length) {
int BUFSIZE = 16*1024;
char buf[BUFSIZE];
@@ -151,7 +147,7 @@ void MultiDiskWriter::hashUpdate(DiskWriterEntry* entry, long long int offset, l
if(BUFSIZE != entry->diskWriter->readData(buf, BUFSIZE, offset)) {
throw string("error");
}
- digestUpdate(ctx, buf, BUFSIZE);
+ ctx.digestUpdate(buf, BUFSIZE);
offset += BUFSIZE;
}
int r = length%BUFSIZE;
@@ -159,17 +155,15 @@ void MultiDiskWriter::hashUpdate(DiskWriterEntry* entry, long long int offset, l
if(r != entry->diskWriter->readData(buf, r, offset)) {
throw string("error");
}
- digestUpdate(ctx, buf, r);
+ ctx.digestUpdate(buf, r);
}
}
-#endif // ENABLE_MESSAGE_DIGEST
string MultiDiskWriter::sha1Sum(long long int offset, long long int length) {
-#ifdef ENABLE_MESSAGE_DIGEST
long long int fileOffset = offset;
bool reading = false;
int rem = length;
- digestReset(ctx);
+ ctx.digestReset();
try {
for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
itr != diskWriterEntries.end() && rem != 0; itr++) {
@@ -187,13 +181,10 @@ string MultiDiskWriter::sha1Sum(long long int offset, long long int length) {
throw new DlAbortEx(EX_FILE_OFFSET_OUT_OF_RANGE, offset);
}
unsigned char hashValue[20];
- digestFinal(ctx, hashValue);
+ ctx.digestFinal(hashValue);
return Util::toHex(hashValue, 20);
} catch(string ex) {
throw new DlAbortEx(EX_FILE_SHA1SUM, "", strerror(errno));
}
-#else
- return "";
-#endif // ENABLE_MESSAGE_DIGEST
}