Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MD5Shortener: use an explicit buffer for the hash.

  • Loading branch information...
commit 2b000654ef771940f449eecebf8ad9e622f715f7 1 parent a07cbff
@mschuerig authored
Showing with 11 additions and 8 deletions.
  1. +9 −6 src/MD5Shortener.cpp
  2. +2 −2 src/dirmeta.cpp
View
15 src/MD5Shortener.cpp
@@ -1,17 +1,20 @@
#include "MD5Shortener.h"
-#include <stdio.h>
-#include <string.h>
#include <openssl/md5.h>
+#include <string>
+#include <vector>
using namespace std;
string
MD5Shortener::shorten(const std::string& longName) {
- unsigned char* hash = MD5(reinterpret_cast<const unsigned char*>(longName.c_str()),
- longName.size(), NULL);
-
+ vector<unsigned char> hash(MD5_DIGEST_LENGTH);
+
+ MD5(reinterpret_cast<const unsigned char*>(longName.c_str()),
+ longName.size(),
+ &hash[0]);
+
string shortName(2 * MD5_DIGEST_LENGTH, 'x');
string::iterator k = shortName.begin();
@@ -19,6 +22,6 @@ MD5Shortener::shorten(const std::string& longName) {
*k++ = "0123456789abcdef"[hash[i] >> 4];
*k++ = "0123456789abcdef"[hash[i] & 0x0f];
}
-
+
return shortName;
}
View
4 src/dirmeta.cpp
@@ -15,8 +15,8 @@ main( int argc, char* argv[] ) {
DirectoryMetadata::fromMetadataFile(".", argv[2]) :
DirectoryMetadata::fromMetadataFile(".");
} else {
-// MD5Shortener shortener;
- TruncatingShortener shortener(5);
+ MD5Shortener shortener;
+// TruncatingShortener shortener(5);
md = DirectoryMetadata::fromFilesystem(".", shortener);
}
Please sign in to comment.
Something went wrong with that request. Please try again.