X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=sha1.cc;h=c7b71126daf03bc17d123e834f320938aea6ffd2;hb=87c6a5ed4ec515c2e154f98529c1d2f077d2a7e4;hp=1fc4ad7da406156d2b65c509b92f2b17fe1a1dab;hpb=948051f02c9bc3285ce1ea187dbae27120dbf7aa;p=cumulus.git diff --git a/sha1.cc b/sha1.cc index 1fc4ad7..c7b7112 100644 --- a/sha1.cc +++ b/sha1.cc @@ -33,6 +33,10 @@ #include #include +#include + +using std::string; + /* SWAP does an endian swap on architectures that are little-endian, as SHA1 needs some data in a big-endian form. */ #define SWAP(n) htonl(n) @@ -339,7 +343,7 @@ SHA1Checksum::~SHA1Checksum() { } -void SHA1Checksum::process(void *data, size_t len) +void SHA1Checksum::process(const void *data, size_t len) { sha1_process_bytes(data, len, &ctx); } @@ -349,3 +353,19 @@ const uint8_t *SHA1Checksum::checksum() sha1_finish_ctx(&ctx, resbuf); return (const uint8_t *)resbuf; } + +string SHA1Checksum::checksum_str() +{ + uint8_t resbuf[20]; + char hexbuf[4]; + string result = "sha1="; + + sha1_finish_ctx(&ctx, resbuf); + + for (int i = 0; i < 20; i++) { + sprintf(hexbuf, "%02x", resbuf[i]); + result += hexbuf; + } + + return result; +}