summaryrefslogtreecommitdiff
path: root/src/MessageDigestHelper.h
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-08-08 14:40:11 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-08-08 14:40:11 +0000
commite85f9ccfd64b52419d47bd8f76c4b08eb2e0c422 (patch)
tree89fa75c665af0d1866d5f001677c95215622ff7c /src/MessageDigestHelper.h
parent45f949c713d38e6e2141703cd9cb069c321a991f (diff)
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use of message digest. Removed repeated code. The message digest algorithm is now specified by string, like "sha1", "md5". * src/messageDigest.{h, cc} * src/MessageDigestHelper.{h, cc}: New class. * src/DefaultPieceStorage.cc * src/DefaultBtContext.{h, cc} (computeFastSet): New function. (setInfoHash): Added for unit testing. (setNumPieces): Added for unit testing. * src/DefaultBtInteractive.cc * src/BtPieceMessage.cc * src/Peer.cc * src/Checksum.h * src/message.h * src/IteratableChecksumValidator.h * src/ChunkChecksumValidator.{h, cc}: Use IteratableChecksumValidator inside it. * src/SegmentMan.{h, cc} (checkIntegrity): Removed. * src/IteratableChunkChecksumValidator.{h, cc} * src/Util.h (sha1Sum): Removed. (simpleMessageDigest): Removed. (fileChecksum): Removed. (computeFastSet): Removed. * src/ShaVisitor.cc * src/ChunkChecksum.h * src/DownloadCommand.cc Removed messageDigest virtual functions. * src/MultiDiskAdaptor.{h, cc} * src/DiskAdaptor.h * src/ByteArrayDiskWriter.h * src/DiskWriter.h * src/DiskAdaptorWriter.h * src/AbstractSingleDiskAdaptor.{h, cc} * src/AbstractDiskWriter.{h, cc} Fixed comilation error when message digest is disabled. * src/MetalinkEntry.{h, cc} * src/MetalinkRequestInfo.cc Removed srandom and random. * src/SimpleRandomizer.h Added size() virtual function to DiskAdaptor * src/MultiDiskAdaptor.h Fixed the bug that causes that files are not opened correctly in multi-file torrent. * src/TorrentRequestInfo.cc * src/MultiDiskAdaptor.cc Added SHA256 support * src/messageDigest.cc * src/Xml2MetalinkProcessor.cc Show supported message digest algorithms * src/main.cc Updated contact info. * src/main.cc
Diffstat (limited to 'src/MessageDigestHelper.h')
-rw-r--r--src/MessageDigestHelper.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/MessageDigestHelper.h b/src/MessageDigestHelper.h
new file mode 100644
index 00000000..21e4a215
--- /dev/null
+++ b/src/MessageDigestHelper.h
@@ -0,0 +1,77 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2006 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef _D_MESSAGE_DIGEST_HELPER_H_
+#define _D_MESSAGE_DIGEST_HELPER_H_
+
+#include "common.h"
+#include "DiskWriter.h"
+
+class MessageDigestHelper {
+public:
+ /**
+ * Returns message digest in hexadecimal notation.
+ * Digest algorithm is specified by algo.
+ */
+ static string digest(const string& algo, DiskWriterHandle diskWriter, int64_t offset, int64_t length);
+
+ /**
+ * Calculates message digest of file opened by diskWriter.
+ */
+ static string digest(const string& algo, DiskWriterHandle diskWriter)
+ {
+ return digest(algo, diskWriter, 0, diskWriter->size());
+ }
+
+ /**
+ * Calculates message digest of file denoted by filename.
+ */
+ static string digest(const string& algo, const string& filename);
+
+ static string digest(const string& algo, const void* data, int32_t length);
+
+ static string digestString(const string& algo, const string& data)
+ {
+ return digest(algo, data.c_str(), data.size());
+ }
+
+ /**
+ * Stores *raw* message digest into md.
+ * Throws exception when mdLength is less than the size of message digest.
+ */
+ static void digest(unsigned char* md, int32_t mdLength,
+ const string& algo, const void* data, int32_t length);
+};
+
+#endif // _D_MESSAGE_DIGEST_HELPER_H_