Browse Source

2010-02-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Destroyed digest context after getting calculated hash.
	* src/Piece.cc
	* src/Piece.h
Tatsuhiro Tsujikawa 15 năm trước cách đây
mục cha
commit
4354c674ab
3 tập tin đã thay đổi với 13 bổ sung4 xóa
  1. 6 0
      ChangeLog
  2. 3 2
      src/Piece.cc
  3. 4 2
      src/Piece.h

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2010-02-11  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Destroyed digest context after getting calculated hash.
+	* src/Piece.cc
+	* src/Piece.h
+
 2010-02-11  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Removed BitfieldManFactory class.

+ 3 - 2
src/Piece.cc

@@ -250,13 +250,14 @@ bool Piece::isHashCalculated() const
   return !_mdctx.isNull() && _nextBegin == length;
 }
 
-// TODO should be getHashString()
 std::string Piece::getHashString()
 {
   if(_mdctx.isNull()) {
     return A2STR::NIL;
   } else {
-    return util::toHex(_mdctx->digestFinal());
+    std::string hash = util::toHex(_mdctx->digestFinal());
+    destroyHashContext();
+    return hash;
   }
 }
 

+ 4 - 2
src/Piece.h

@@ -164,8 +164,10 @@ public:
 
   bool isHashCalculated() const;
 
-  // Returns hash value in ASCII hexadecimal form.
-  // WARN: This function must be called only once.
+  // Returns hash value in ASCII hexadecimal form, which is calculated
+  // by updateHash().  Please note that this function returns hash
+  // value only once. Second invocation without updateHash() returns
+  // empty string.
   std::string getHashString();
 
   void destroyHashContext();