mirror of
https://github.com/aria2/aria2.git
synced 2025-04-06 14:07:37 +03:00
Renamed MessageDigestHelper as message_digest_helper
Static member variables in MessageDigestHelper class are now functions under message_digest namespace.
This commit is contained in:
parent
38202a5565
commit
2666bc8170
18 changed files with 90 additions and 100 deletions
|
@ -42,7 +42,7 @@
|
|||
#include "util.h"
|
||||
#include "message.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "MessageDigestHelper.h"
|
||||
#include "message_digest_helper.h"
|
||||
#include "DiskAdaptor.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
|
@ -223,7 +223,7 @@ bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
|
|||
} else {
|
||||
off_t offset = (off_t)piece->getIndex()*downloadContext_->getPieceLength();
|
||||
|
||||
return MessageDigestHelper::staticSHA1DigestHexDigest
|
||||
return message_digest::staticSHA1DigestHexDigest
|
||||
(getPieceStorage()->getDiskAdaptor(), offset, piece->getLength())
|
||||
== downloadContext_->getPieceHash(piece->getIndex());
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include "DlAbortEx.h"
|
||||
#include "DHTConstants.h"
|
||||
#include "MessageDigest.h"
|
||||
#include "MessageDigestHelper.h"
|
||||
#include "message_digest_helper.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
@ -76,7 +76,7 @@ std::string DHTTokenTracker::generateToken
|
|||
memcpy(src, infoHash, DHT_ID_LENGTH);
|
||||
memcpy(src+DHT_ID_LENGTH+COMPACT_LEN_IPV6, secret, SECRET_SIZE);
|
||||
unsigned char md[20];
|
||||
MessageDigestHelper::digest(md, sizeof(md), MessageDigest::sha1(),
|
||||
message_digest::digest(md, sizeof(md), MessageDigest::sha1(),
|
||||
src, sizeof(src));
|
||||
return std::string(&md[0], &md[sizeof(md)]);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
#include "SocketRecvBuffer.h"
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
# include "MessageDigest.h"
|
||||
# include "MessageDigestHelper.h"
|
||||
# include "message_digest_helper.h"
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
# include "bittorrent_helper.h"
|
||||
|
@ -236,7 +236,7 @@ bool DownloadCommand::executeInternal() {
|
|||
messageDigest_->reset();
|
||||
validatePieceHash
|
||||
(segment, expectedPieceHash,
|
||||
MessageDigestHelper::hexDigest
|
||||
message_digest::hexDigest
|
||||
(messageDigest_,
|
||||
getPieceStorage()->getDiskAdaptor(),
|
||||
segment->getPosition(),
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
|
||||
#include "util.h"
|
||||
#include "message.h"
|
||||
#include "MessageDigestHelper.h"
|
||||
#include "DiskAdaptor.h"
|
||||
#include "FileEntry.h"
|
||||
#include "RecoverableException.h"
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
#include "ARC4Encryptor.h"
|
||||
#include "ARC4Decryptor.h"
|
||||
#include "MessageDigest.h"
|
||||
#include "MessageDigestHelper.h"
|
||||
#include "message_digest_helper.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
#include "util.h"
|
||||
#include "DownloadContext.h"
|
||||
|
@ -192,7 +192,7 @@ void MSEHandshake::initCipher(const unsigned char* infoHash)
|
|||
|
||||
unsigned char localCipherKey[20];
|
||||
sha1_->reset();
|
||||
MessageDigestHelper::digest(localCipherKey, sizeof(localCipherKey),
|
||||
message_digest::digest(localCipherKey, sizeof(localCipherKey),
|
||||
sha1_, s, sizeof(s));
|
||||
encryptor_.reset(new ARC4Encryptor());
|
||||
encryptor_->init(localCipherKey, sizeof(localCipherKey));
|
||||
|
@ -200,7 +200,7 @@ void MSEHandshake::initCipher(const unsigned char* infoHash)
|
|||
unsigned char peerCipherKey[20];
|
||||
memcpy(s, initiator_?"keyB":"keyA", 4);
|
||||
sha1_->reset();
|
||||
MessageDigestHelper::digest(peerCipherKey, sizeof(peerCipherKey),
|
||||
message_digest::digest(peerCipherKey, sizeof(peerCipherKey),
|
||||
sha1_, s, sizeof(s));
|
||||
decryptor_.reset(new ARC4Decryptor());
|
||||
decryptor_->init(peerCipherKey, sizeof(peerCipherKey));
|
||||
|
@ -241,7 +241,7 @@ void MSEHandshake::createReq1Hash(unsigned char* md) const
|
|||
memcpy(buffer, "req1", 4);
|
||||
memcpy(buffer+4, secret_, KEY_LENGTH);
|
||||
sha1_->reset();
|
||||
MessageDigestHelper::digest(md, 20, sha1_, buffer, 4+KEY_LENGTH);
|
||||
message_digest::digest(md, 20, sha1_, buffer, 4+KEY_LENGTH);
|
||||
}
|
||||
|
||||
void MSEHandshake::createReq23Hash(unsigned char* md, const unsigned char* infoHash) const
|
||||
|
@ -251,14 +251,14 @@ void MSEHandshake::createReq23Hash(unsigned char* md, const unsigned char* infoH
|
|||
memcpy(x+4, infoHash, INFO_HASH_LENGTH);
|
||||
unsigned char xh[20];
|
||||
sha1_->reset();
|
||||
MessageDigestHelper::digest(xh, sizeof(xh), sha1_, x, sizeof(x));
|
||||
message_digest::digest(xh, sizeof(xh), sha1_, x, sizeof(x));
|
||||
|
||||
unsigned char y[4+96];
|
||||
memcpy(y, "req3", 4);
|
||||
memcpy(y+4, secret_, KEY_LENGTH);
|
||||
unsigned char yh[20];
|
||||
sha1_->reset();
|
||||
MessageDigestHelper::digest(yh, sizeof(yh), sha1_, y, sizeof(y));
|
||||
message_digest::digest(yh, sizeof(yh), sha1_, y, sizeof(y));
|
||||
|
||||
for(size_t i = 0; i < 20; ++i) {
|
||||
md[i] = xh[i]^yh[i];
|
||||
|
|
|
@ -291,7 +291,7 @@ SRCS += IteratableChunkChecksumValidator.cc IteratableChunkChecksumValidator.h\
|
|||
CheckIntegrityDispatcherCommand.cc CheckIntegrityDispatcherCommand.h\
|
||||
CheckIntegrityCommand.cc CheckIntegrityCommand.h\
|
||||
ChecksumCheckIntegrityEntry.cc ChecksumCheckIntegrityEntry.h\
|
||||
MessageDigestHelper.cc MessageDigestHelper.h\
|
||||
message_digest_helper.cc message_digest_helper.h\
|
||||
Checksum.cc Checksum.h\
|
||||
ChunkChecksum.cc ChunkChecksum.h\
|
||||
MessageDigest.cc MessageDigest.h\
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include "PieceStorage.h"
|
||||
#include "BtConstants.h"
|
||||
#include "MessageDigest.h"
|
||||
#include "MessageDigestHelper.h"
|
||||
#include "message_digest_helper.h"
|
||||
#include "bittorrent_helper.h"
|
||||
#include "DiskAdaptor.h"
|
||||
#include "Piece.h"
|
||||
|
@ -87,7 +87,7 @@ void UTMetadataDataExtensionMessage::doReceivedAction()
|
|||
if(pieceStorage_->downloadFinished()) {
|
||||
std::string metadata = util::toString(pieceStorage_->getDiskAdaptor());
|
||||
unsigned char infoHash[INFO_HASH_LENGTH];
|
||||
MessageDigestHelper::digest(infoHash, INFO_HASH_LENGTH,
|
||||
message_digest::digest(infoHash, INFO_HASH_LENGTH,
|
||||
MessageDigest::sha1(),
|
||||
metadata.data(), metadata.size());
|
||||
if(memcmp(infoHash, bittorrent::getInfoHash(dctx_),
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
#include "fmt.h"
|
||||
#include "BtConstants.h"
|
||||
#include "MessageDigest.h"
|
||||
#include "MessageDigestHelper.h"
|
||||
#include "message_digest_helper.h"
|
||||
#include "a2netcompat.h"
|
||||
#include "BtConstants.h"
|
||||
#include "bitfield.h"
|
||||
|
@ -415,7 +415,7 @@ void processRootDictionary
|
|||
// retrieve infoHash
|
||||
std::string encodedInfoDict = bencode2::encode(infoDict);
|
||||
unsigned char infoHash[INFO_HASH_LENGTH];
|
||||
MessageDigestHelper::digest(infoHash, INFO_HASH_LENGTH,
|
||||
message_digest::digest(infoHash, INFO_HASH_LENGTH,
|
||||
MessageDigest::sha1(),
|
||||
encodedInfoDict.data(),
|
||||
encodedInfoDict.size());
|
||||
|
@ -679,7 +679,7 @@ void computeFastSet
|
|||
memcpy(tx+4, infoHash, 20);
|
||||
unsigned char x[20];
|
||||
SharedHandle<MessageDigest> sha1 = MessageDigest::sha1();
|
||||
MessageDigestHelper::digest(x, sizeof(x), sha1, tx, 24);
|
||||
message_digest::digest(x, sizeof(x), sha1, tx, 24);
|
||||
while(fastSet.size() < fastSetSize) {
|
||||
for(size_t i = 0; i < 5 && fastSet.size() < fastSetSize; ++i) {
|
||||
size_t j = i*4;
|
||||
|
@ -693,7 +693,7 @@ void computeFastSet
|
|||
}
|
||||
unsigned char temp[20];
|
||||
sha1->reset();
|
||||
MessageDigestHelper::digest(temp, sizeof(temp), sha1, x, sizeof(x));
|
||||
message_digest::digest(temp, sizeof(temp), sha1, x, sizeof(x));
|
||||
memcpy(x, temp, sizeof(x));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
# include "MetalinkEntry.h"
|
||||
#endif // ENABLE_METALINK
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
# include "MessageDigestHelper.h"
|
||||
# include "message_digest_helper.h"
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
||||
extern char* optarg;
|
||||
|
@ -196,7 +196,7 @@ error_code::Value main(int argc, char* argv[])
|
|||
A2_LOG_INFO(MSG_LOGGING_STARTED);
|
||||
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
MessageDigestHelper::staticSHA1DigestInit();
|
||||
message_digest::staticSHA1DigestInit();
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
||||
if(op->getAsBool(PREF_DISABLE_IPV6)) {
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "MessageDigestHelper.h"
|
||||
#include "message_digest_helper.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
@ -46,27 +46,33 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
SharedHandle<MessageDigest> MessageDigestHelper::sha1Ctx_;
|
||||
namespace message_digest {
|
||||
|
||||
void MessageDigestHelper::staticSHA1DigestInit()
|
||||
namespace {
|
||||
|
||||
SharedHandle<MessageDigest> sha1Ctx_;
|
||||
|
||||
} // namespace
|
||||
|
||||
void staticSHA1DigestInit()
|
||||
{
|
||||
staticSHA1DigestFree();
|
||||
sha1Ctx_ = MessageDigest::sha1();
|
||||
}
|
||||
|
||||
void MessageDigestHelper::staticSHA1DigestFree()
|
||||
void staticSHA1DigestFree()
|
||||
{
|
||||
sha1Ctx_.reset();
|
||||
}
|
||||
|
||||
std::string MessageDigestHelper::staticSHA1DigestHexDigest
|
||||
std::string staticSHA1DigestHexDigest
|
||||
(const BinaryStreamHandle& bs, off_t offset, uint64_t length)
|
||||
{
|
||||
sha1Ctx_->reset();
|
||||
return hexDigest(sha1Ctx_, bs, offset, length);
|
||||
}
|
||||
|
||||
std::string MessageDigestHelper::hexDigest
|
||||
std::string hexDigest
|
||||
(const SharedHandle<MessageDigest>& ctx,
|
||||
const SharedHandle<BinaryStream>& bs,
|
||||
off_t offset, uint64_t length)
|
||||
|
@ -94,7 +100,7 @@ std::string MessageDigestHelper::hexDigest
|
|||
return ctx->hexDigest();
|
||||
}
|
||||
|
||||
void MessageDigestHelper::digest
|
||||
void digest
|
||||
(unsigned char* md, size_t mdLength,
|
||||
const SharedHandle<MessageDigest>& ctx, const void* data, size_t length)
|
||||
{
|
||||
|
@ -110,4 +116,6 @@ void MessageDigestHelper::digest
|
|||
ctx->digest(md);
|
||||
}
|
||||
|
||||
} // namespace message_digest
|
||||
|
||||
} // namespace aria2
|
|
@ -46,12 +46,8 @@ namespace aria2 {
|
|||
class BinaryStream;
|
||||
class MessageDigest;
|
||||
|
||||
class MessageDigestHelper {
|
||||
private:
|
||||
static SharedHandle<MessageDigest> sha1Ctx_;
|
||||
namespace message_digest {
|
||||
|
||||
MessageDigestHelper();
|
||||
public:
|
||||
/**
|
||||
* staticSHA1DigestInit(), staticSHA1DigestFree(), staticSHA1Digest()
|
||||
* use statically declared MessageDigest sha1Ctx_.
|
||||
|
@ -59,21 +55,21 @@ public:
|
|||
/**
|
||||
* Initializes sha1Ctx_
|
||||
*/
|
||||
static void staticSHA1DigestInit();
|
||||
void staticSHA1DigestInit();
|
||||
|
||||
/**
|
||||
* Frees allocated resources for sha1Ctx_
|
||||
*/
|
||||
static void staticSHA1DigestFree();
|
||||
void staticSHA1DigestFree();
|
||||
|
||||
static std::string staticSHA1DigestHexDigest
|
||||
std::string staticSHA1DigestHexDigest
|
||||
(const SharedHandle<BinaryStream>& bs, off_t offset, uint64_t length);
|
||||
|
||||
/**
|
||||
* ctx must be initialized or reseted before calling this function.
|
||||
* Returns hex digest string, not *raw* digest
|
||||
*/
|
||||
static std::string hexDigest
|
||||
std::string hexDigest
|
||||
(const SharedHandle<MessageDigest>& ctx,
|
||||
const SharedHandle<BinaryStream>& bs,
|
||||
off_t offset, uint64_t length);
|
||||
|
@ -82,11 +78,12 @@ public:
|
|||
* Stores *raw* message digest into md.
|
||||
* Throws exception when mdLength is less than the size of message digest.
|
||||
*/
|
||||
static void digest
|
||||
void digest
|
||||
(unsigned char* md, size_t mdLength,
|
||||
const SharedHandle<MessageDigest>& ctx,
|
||||
const void* data, size_t length);
|
||||
};
|
||||
|
||||
} // namespace message_digest
|
||||
|
||||
} // namespace aria2
|
||||
|
|
@ -84,7 +84,7 @@
|
|||
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
# include "MessageDigest.h"
|
||||
# include "MessageDigestHelper.h"
|
||||
# include "message_digest_helper.h"
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
||||
// For libc6 which doesn't define ULLONG_MAX properly because of broken limits.h
|
||||
|
@ -1324,8 +1324,7 @@ void generateRandomKey(unsigned char* key)
|
|||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
unsigned char bytes[40];
|
||||
generateRandomData(bytes, sizeof(bytes));
|
||||
MessageDigestHelper::digest
|
||||
(key, 20, MessageDigest::sha1(), bytes, sizeof(bytes));
|
||||
message_digest::digest(key, 20, MessageDigest::sha1(), bytes, sizeof(bytes));
|
||||
#else // !ENABLE_MESSAGE_DIGEST
|
||||
generateRandomData(key, 20);
|
||||
#endif // !ENABLE_MESSAGE_DIGEST
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "util.h"
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
# include "MessageDigest.h"
|
||||
# include "MessageDigestHelper.h"
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
||||
namespace aria2 {
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "MockSegment.h"
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
# include "MessageDigest.h"
|
||||
# include "MessageDigestHelper.h"
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
||||
namespace aria2 {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "MessageDigestHelper.h"
|
||||
#include "message_digest_helper.h"
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
@ -12,7 +12,6 @@ class MessageDigestHelperTest:public CppUnit::TestFixture {
|
|||
|
||||
CPPUNIT_TEST_SUITE(MessageDigestHelperTest);
|
||||
CPPUNIT_TEST(testHexDigestDiskWriter);
|
||||
CPPUNIT_TEST(testDigest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
|
@ -21,7 +20,6 @@ public:
|
|||
}
|
||||
|
||||
void testHexDigestDiskWriter();
|
||||
void testDigest();
|
||||
};
|
||||
|
||||
|
||||
|
@ -33,21 +31,12 @@ void MessageDigestHelperTest::testHexDigestDiskWriter() {
|
|||
diskio->enableReadOnly();
|
||||
diskio->openExistingFile();
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("608cabc0f2fa18c260cafd974516865c772363d5"),
|
||||
MessageDigestHelper::hexDigest
|
||||
message_digest::hexDigest
|
||||
(MessageDigest::sha1(), diskio, 0, 4096));
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("7a4a9ae537ebbbb826b1060e704490ad0f365ead"),
|
||||
MessageDigestHelper::hexDigest
|
||||
message_digest::hexDigest
|
||||
(MessageDigest::sha1(), diskio, 5, 100));
|
||||
}
|
||||
|
||||
void MessageDigestHelperTest::testDigest()
|
||||
{
|
||||
std::string data = "aria2";
|
||||
SharedHandle<MessageDigest> sha1 = MessageDigest::sha1();
|
||||
sha1->update(data.data(), data.size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("f36003f22b462ffa184390533c500d8989e9f681"),
|
||||
sha1->hexDigest());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "DefaultDiskWriter.h"
|
||||
#include "fmt.h"
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
# include "MessageDigestHelper.h"
|
||||
# include "message_digest_helper.h"
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
||||
namespace aria2 {
|
||||
|
@ -81,7 +81,7 @@ std::string fileHexDigest
|
|||
{
|
||||
SharedHandle<DiskWriter> writer(new DefaultDiskWriter(filename));
|
||||
writer->openExistingFile();
|
||||
return MessageDigestHelper::hexDigest(ctx, writer, 0, writer->size());
|
||||
return message_digest::hexDigest(ctx, writer, 0, writer->size());
|
||||
}
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "UTMetadataRequestTracker.h"
|
||||
#include "bittorrent_helper.h"
|
||||
#include "MessageDigest.h"
|
||||
#include "MessageDigestHelper.h"
|
||||
#include "message_digest_helper.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -80,7 +80,7 @@ void UTMetadataDataExtensionMessageTest::testDoReceivedAction()
|
|||
std::string metadata = piece0+piece1;
|
||||
|
||||
unsigned char infoHash[INFO_HASH_LENGTH];
|
||||
MessageDigestHelper::digest(infoHash, INFO_HASH_LENGTH,
|
||||
message_digest::digest(infoHash, INFO_HASH_LENGTH,
|
||||
MessageDigest::sha1(),
|
||||
metadata.data(), metadata.size());
|
||||
attrs->infoHash = std::string(&infoHash[0], &infoHash[20]);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "DiskAdaptor.h"
|
||||
#include "util.h"
|
||||
#include "MessageDigest.h"
|
||||
#include "MessageDigestHelper.h"
|
||||
#include "message_digest_helper.h"
|
||||
#include "prefs.h"
|
||||
#include "RecoverableException.h"
|
||||
|
||||
|
@ -73,7 +73,7 @@ void UTMetadataPostDownloadHandlerTest::testGetNextRequestGroups()
|
|||
"d6:lengthi384e4:name19:aria2-0.8.2.tar.bz212:piece lengthi128e"
|
||||
"6:pieces60:AAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCe";
|
||||
unsigned char infoHash[20];
|
||||
MessageDigestHelper::digest
|
||||
message_digest::digest
|
||||
(infoHash, sizeof(infoHash), MessageDigest::sha1(),
|
||||
reinterpret_cast<const unsigned char*>(metadata.data()), metadata.size());
|
||||
dctx_->getFirstFileEntry()->setLength(metadata.size());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue