Bug 803692 - Make SHA1Sum::update() take a void* instead of a uint8_t*. r=waldo

This commit is contained in:
Justin Lebar 2012-10-22 16:32:34 -04:00
parent a3ef93cf41
commit 9de35188e7
2 changed files with 9 additions and 7 deletions

View File

@ -99,10 +99,12 @@ SHA1Sum::SHA1Sum()
* SHA: Add data to context.
*/
void
SHA1Sum::update(const uint8_t* dataIn, uint32_t len)
SHA1Sum::update(const void* dataIn, uint32_t len)
{
MOZ_ASSERT(!mDone, "SHA1Sum can only be used to compute a single hash.");
const uint8_t* data = static_cast<const uint8_t*>(dataIn);
if (len == 0)
return;
@ -117,9 +119,9 @@ SHA1Sum::update(const uint8_t* dataIn, uint32_t len)
togo = 64U - lenB;
if (len < togo)
togo = len;
memcpy(u.b + lenB, dataIn, togo);
memcpy(u.b + lenB, data, togo);
len -= togo;
dataIn += togo;
data += togo;
lenB = (lenB + togo) & 63U;
if (!lenB)
shaCompress(&H[H2X], u.w);
@ -127,12 +129,12 @@ SHA1Sum::update(const uint8_t* dataIn, uint32_t len)
while (len >= 64U) {
len -= 64U;
shaCompress(&H[H2X], reinterpret_cast<const uint32_t*>(dataIn));
dataIn += 64U;
shaCompress(&H[H2X], reinterpret_cast<const uint32_t*>(data));
data += 64U;
}
if (len > 0)
memcpy(u.b, dataIn, len);
memcpy(u.b, data, len);
}

View File

@ -49,7 +49,7 @@ class SHA1Sum
typedef uint8_t Hash[HashSize];
/* Add len bytes of dataIn to the data sequence being hashed. */
void update(const uint8_t* dataIn, uint32_t len);
void update(const void* dataIn, uint32_t len);
/* Compute the final hash of all data into hashOut. */
void finish(SHA1Sum::Hash& hashOut);