Changeset 32568 in vbox for trunk/src/VBox/Runtime/common/checksum
- Timestamp:
- Sep 16, 2010 3:26:13 PM (14 years ago)
- Location:
- trunk/src/VBox/Runtime/common/checksum
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/checksum/RTSha1Digest.cpp
r30080 r32568 41 41 42 42 43 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest, PFNRTPROGRESS pfnProgressCallback, void *pvUser) 43 RTR3DECL(int) RTSha1Digest(void* pvBuf, size_t cbBuf, char **ppszDigest, FNRTPROGRESS pfnProgressCallback, void *pvUser) 44 { 45 /* Validate input */ 46 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER); 47 AssertPtrReturn(ppszDigest, VERR_INVALID_POINTER); 48 AssertPtrNullReturn(pfnProgressCallback, VERR_INVALID_PARAMETER); 49 50 int rc = VINF_SUCCESS; 51 *ppszDigest = NULL; 52 53 /* Initialize OpenSSL. */ 54 SHA_CTX ctx; 55 if (!SHA1_Init(&ctx)) 56 return VERR_INTERNAL_ERROR; 57 58 /* Buffer size for progress callback */ 59 double rdMulti = 100.0 / cbBuf; 60 61 /* Working buffer */ 62 char *pvTmp = (char*)pvBuf; 63 64 /* Process the memory in blocks */ 65 size_t cbRead; 66 size_t cbReadTotal = 0; 67 for (;;) 68 { 69 cbRead = RT_MIN(cbBuf - cbReadTotal, _1M); 70 if(!SHA1_Update(&ctx, pvTmp, cbRead)) 71 { 72 rc = VERR_INTERNAL_ERROR; 73 break; 74 } 75 cbReadTotal += cbRead; 76 pvTmp += cbRead; 77 78 /* Call the progress callback if one is defined */ 79 if (pfnProgressCallback) 80 { 81 rc = pfnProgressCallback((unsigned)(cbReadTotal * rdMulti), pvUser); 82 if (RT_FAILURE(rc)) 83 break; /* canceled */ 84 } 85 /* Finished? */ 86 if (cbReadTotal == cbBuf) 87 break; 88 } 89 if (RT_SUCCESS(rc)) 90 { 91 /* Finally calculate & format the SHA1 sum */ 92 unsigned char auchDig[RTSHA1_HASH_SIZE]; 93 if (!SHA1_Final(auchDig, &ctx)) 94 return VERR_INTERNAL_ERROR; 95 96 char *pszDigest; 97 rc = RTStrAllocEx(&pszDigest, RTSHA1_DIGEST_LEN + 1); 98 if (RT_SUCCESS(rc)) 99 { 100 rc = RTSha1ToString(auchDig, pszDigest, RTSHA1_DIGEST_LEN + 1); 101 if (RT_SUCCESS(rc)) 102 *ppszDigest = pszDigest; 103 else 104 RTStrFree(pszDigest); 105 } 106 } 107 108 return rc; 109 } 110 111 RTR3DECL(int) RTSha1DigestFromFile(const char *pszFile, char **ppszDigest, PFNRTPROGRESS pfnProgressCallback, void *pvUser) 44 112 { 45 113 /* Validate input */ -
trunk/src/VBox/Runtime/common/checksum/manifest.cpp
r30079 r32568 253 253 { 254 254 callback.cCurrentFile = i; 255 rc = RTSha1Digest (papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback);255 rc = RTSha1DigestFromFile(papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback); 256 256 } 257 257 else 258 rc = RTSha1Digest (papszFiles[i], &pszDigest, NULL, NULL);258 rc = RTSha1DigestFromFile(papszFiles[i], &pszDigest, NULL, NULL); 259 259 if (RT_FAILURE(rc)) 260 260 break; … … 301 301 { 302 302 callback.cCurrentFile = i; 303 rc = RTSha1Digest (papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback);303 rc = RTSha1DigestFromFile(papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback); 304 304 } 305 305 else 306 rc = RTSha1Digest (papszFiles[i], &pszDigest, NULL, NULL);306 rc = RTSha1DigestFromFile(papszFiles[i], &pszDigest, NULL, NULL); 307 307 if (RT_FAILURE(rc)) 308 308 break;
Note:
See TracChangeset
for help on using the changeset viewer.