mirror of
https://github.com/aria2/aria2.git
synced 2026-04-02 10:55:00 +00:00
Replaced MessageDigestContext with MessageDigest. Cleaned up unnecessary functions in MessageDigestHelper. * src/BtPieceMessage.cc * src/Checksum.h * src/DHTTokenTracker.cc * src/DownloadCommand.cc * src/DownloadCommand.h * src/HashFuncEntry.h * src/IteratableChecksumValidator.cc * src/IteratableChecksumValidator.h * src/IteratableChunkChecksumValidator.cc * src/IteratableChunkChecksumValidator.h * src/LibgcryptMessageDigestImpl.cc * src/LibgcryptMessageDigestImpl.h * src/LibsslMessageDigestImpl.cc * src/LibsslMessageDigestImpl.h * src/MSEHandshake.cc * src/MSEHandshake.h * src/Makefile.am * src/MessageDigest.cc * src/MessageDigest.h * src/MessageDigestHelper.cc * src/MessageDigestHelper.h * src/MessageDigestImpl.h * src/MetalinkParserController.cc * src/Piece.cc * src/Piece.h * src/UTMetadataDataExtensionMessage.cc * src/bittorrent_helper.cc * src/messageDigest.cc: Removed * src/messageDigest.h: Removed * src/util.cc * src/version_usage.cc * test/BittorrentHelperTest.cc * test/GZipDecoderTest.cc * test/GZipDecodingStreamFilterTest.cc * test/IteratableChecksumValidatorTest.cc * test/IteratableChunkChecksumValidatorTest.cc * test/Makefile.am * test/MessageDigestHelperTest.cc * test/MessageDigestTest.cc * test/Metalink2RequestGroupTest.cc * test/MetalinkProcessorTest.cc * test/PieceTest.cc * test/TestUtil.cc * test/TestUtil.h * test/UTMetadataDataExtensionMessageTest.cc * test/UTMetadataPostDownloadHandlerTest.cc
89 lines
2.1 KiB
C++
89 lines
2.1 KiB
C++
#include "TestUtil.h"
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <cerrno>
|
|
#include <cstring>
|
|
#include <sstream>
|
|
#include <fstream>
|
|
|
|
#include "a2io.h"
|
|
#include "File.h"
|
|
#include "StringFormat.h"
|
|
#include "FatalException.h"
|
|
#include "Cookie.h"
|
|
#include "DefaultDiskWriter.h"
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
# include "MessageDigestHelper.h"
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
namespace aria2 {
|
|
|
|
void createFile(const std::string& path, size_t length)
|
|
{
|
|
File(File(path).getDirname()).mkdirs();
|
|
int fd = creat(path.c_str(), OPEN_MODE);
|
|
if(fd == -1) {
|
|
throw FATAL_EXCEPTION(StringFormat("Could not create file=%s. cause:%s",
|
|
path.c_str(), strerror(errno)).str());
|
|
}
|
|
if(-1 == ftruncate(fd, length)) {
|
|
throw FATAL_EXCEPTION(StringFormat("ftruncate failed. cause:%s",
|
|
strerror(errno)).str());
|
|
}
|
|
close(fd);
|
|
}
|
|
|
|
std::string readFile(const std::string& path)
|
|
{
|
|
std::stringstream ss;
|
|
std::ifstream in(path.c_str(), std::ios::binary);
|
|
char buf[4096];
|
|
while(1) {
|
|
in.read(buf, sizeof(buf));
|
|
ss.write(buf, in.gcount());
|
|
if(in.gcount() != sizeof(buf)) {
|
|
break;
|
|
}
|
|
}
|
|
return ss.str();
|
|
}
|
|
|
|
Cookie createCookie
|
|
(const std::string& name,
|
|
const std::string& value,
|
|
const std::string& domain,
|
|
bool hostOnly,
|
|
const std::string& path,
|
|
bool secure)
|
|
{
|
|
return Cookie
|
|
(name, value, 0, false, domain, hostOnly, path, secure, false, 0);
|
|
}
|
|
|
|
Cookie createCookie
|
|
(const std::string& name,
|
|
const std::string& value,
|
|
time_t expiryTime,
|
|
const std::string& domain,
|
|
bool hostOnly,
|
|
const std::string& path,
|
|
bool secure)
|
|
{
|
|
return Cookie
|
|
(name, value, expiryTime, true, domain, hostOnly, path, secure, false, 0);
|
|
}
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
std::string fileHexDigest
|
|
(const SharedHandle<MessageDigest>& ctx, const std::string& filename)
|
|
{
|
|
SharedHandle<DiskWriter> writer(new DefaultDiskWriter(filename));
|
|
writer->openExistingFile();
|
|
return MessageDigestHelper::hexDigest(ctx, writer, 0, writer->size());
|
|
}
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
} // namespace aria2
|