Back to index

nordugrid-arc-nox  1.1.0~rc6
Static Public Member Functions | Static Private Attributes
FileCacheHash Class Reference

FileCacheHash provides methods to make hashes from strings. More...

#include <FileCacheHash.h>

List of all members.

Static Public Member Functions

static std::string getHash (std::string url)
 Return a hash of the given URL, according to the current hash scheme.
static int maxLength ()
 Return the maximum length of a hash string.

Static Private Attributes

static int MAX_MD5_LENGTH = 32
 Maximum length of an md5 hash.
static int MAX_SHA1_LENGTH = 40
 Maximum length of a sha1 hash.

Detailed Description

FileCacheHash provides methods to make hashes from strings.

Currently the md5 hash from the openssl library is used.

Definition at line 12 of file FileCacheHash.h.


Member Function Documentation

std::string FileCacheHash::getHash ( std::string  url) [static]

Return a hash of the given URL, according to the current hash scheme.

Definition at line 17 of file FileCacheHash.cpp.

                                              {

  /*
   * example borrowed from http://www.openssl.org/docs/crypto/EVP_DigestInit.html
   */
  EVP_MD_CTX mdctx;
  const EVP_MD *md = EVP_sha1(); // change to EVP_md5() for md5 hashes
  char *mess1 = (char*)url.c_str();
  unsigned char md_value[EVP_MAX_MD_SIZE];
  unsigned int md_len, i;

  OpenSSL_add_all_digests();

  EVP_MD_CTX_init(&mdctx);
  EVP_DigestInit_ex(&mdctx, md, NULL);
  EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
  EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
  EVP_MD_CTX_cleanup(&mdctx);

  char result[3];
  std::string res("");
  for (i = 0; i < md_len; i++) {
    snprintf(result, 3, "%02x", md_value[i]);
    res.append(result);
  }
  return res;
}

Here is the caller graph for this function:

static int FileCacheHash::maxLength ( ) [inline, static]

Return the maximum length of a hash string.

Definition at line 32 of file FileCacheHash.h.

                         {
    return MAX_SHA1_LENGTH;
  }

Member Data Documentation

int FileCacheHash::MAX_MD5_LENGTH = 32 [static, private]

Maximum length of an md5 hash.

Definition at line 18 of file FileCacheHash.h.

int FileCacheHash::MAX_SHA1_LENGTH = 40 [static, private]

Maximum length of a sha1 hash.

Definition at line 22 of file FileCacheHash.h.


The documentation for this class was generated from the following files: