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