torrent-file: Fixing bug in wireEncode that breaks the implicit digest of the data packet
Change-Id: I3cf0e79e819c9d8c915b9ef766e9346828b00e66
Refs: #3489
diff --git a/src/torrent-file.cpp b/src/torrent-file.cpp
index 4302b53..a9797fd 100644
--- a/src/torrent-file.cpp
+++ b/src/torrent-file.cpp
@@ -227,13 +227,12 @@
this->constructLongNames();
}
-const Block&
-TorrentFile::wireEncode()
+void
+TorrentFile::finalize()
{
this->createSuffixCatalog();
this->encodeContent();
m_suffixCatalog.clear();
- return Data::wireEncode();
}
} // namespace ntorrent
diff --git a/src/torrent-file.hpp b/src/torrent-file.hpp
index 89d3173..ea095ac 100644
--- a/src/torrent-file.hpp
+++ b/src/torrent-file.hpp
@@ -111,10 +111,13 @@
wireDecode(const Block& wire);
/**
- * @brief Encode from wire format
+ * @brief Finalize .torrent-file before signing the data packet
+ *
+ * This method has to be called (every time) right before signing or encoding
+ * the .torrent-file
*/
- const Block&
- wireEncode();
+ void
+ finalize();
/**
* @brief Insert a name to the catalog of file manifest names
diff --git a/tests/unit-tests/torrent-file.t.cpp b/tests/unit-tests/torrent-file.t.cpp
index 90b9b6d..abd224a 100644
--- a/tests/unit-tests/torrent-file.t.cpp
+++ b/tests/unit-tests/torrent-file.t.cpp
@@ -146,6 +146,7 @@
{"/NTORRENT/linux15.01/file0/1A2B3C4D",
"/NTORRENT/linux15.01/file1/2A3B4C5E"});
+ file.finalize();
KeyChain keyChain;
keyChain.sign(file);
@@ -169,6 +170,7 @@
{"/NTORRENT/linux15.01/file0/1A2B3C4D",
"/NTORRENT/linux15.01/file1/2A3B4C5E"});
+ file.finalize();
KeyChain keyChain;
keyChain.sign(file);
@@ -190,6 +192,7 @@
"",
{});
+ file.finalize();
KeyChain keyChain;
keyChain.sign(file);
@@ -209,6 +212,7 @@
"/NTORRENT/linux15.01",
{});
+ file.finalize();
KeyChain keyChain;
keyChain.sign(file);
@@ -260,6 +264,7 @@
{"/NTORRENT/linux15.01/file0/1A2B3C4D",
"/NTORRENT/linux15.01/file1/2A3B4C5E"});
+ file.finalize();
KeyChain keyChain;
keyChain.sign(file);
Block wire = file.wireEncode();
@@ -270,6 +275,7 @@
file.insert("/NTORRENT/linux15.01/file3/AB34C5KA");
file.insert("/NTORRENT/linux15.01/file4/CB24C3GB");
+ file.finalize();
Block wire2 = file.wireEncode();
file2.wireDecode(wire2);