VirtualBox

Ignore:
Timestamp:
Sep 16, 2010 3:26:13 PM (14 years ago)
Author:
vboxsync
Message:

OVA: parse ovf in memory on ova import (no need for a temporary ovf anymore)

Location:
trunk/src/VBox/Runtime/common/checksum
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/checksum/RTSha1Digest.cpp

    r30080 r32568  
    4141
    4242
    43 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
     43RTR3DECL(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
     111RTR3DECL(int) RTSha1DigestFromFile(const char *pszFile, char **ppszDigest, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
    44112{
    45113    /* Validate input */
  • trunk/src/VBox/Runtime/common/checksum/manifest.cpp

    r30079 r32568  
    253253        {
    254254            callback.cCurrentFile = i;
    255             rc = RTSha1Digest(papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback);
     255            rc = RTSha1DigestFromFile(papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback);
    256256        }
    257257        else
    258             rc = RTSha1Digest(papszFiles[i], &pszDigest, NULL, NULL);
     258            rc = RTSha1DigestFromFile(papszFiles[i], &pszDigest, NULL, NULL);
    259259        if (RT_FAILURE(rc))
    260260            break;
     
    301301        {
    302302            callback.cCurrentFile = i;
    303             rc = RTSha1Digest(papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback);
     303            rc = RTSha1DigestFromFile(papszFiles[i], &pszDigest, rtSHAProgressCallback, &callback);
    304304        }
    305305        else
    306             rc = RTSha1Digest(papszFiles[i], &pszDigest, NULL, NULL);
     306            rc = RTSha1DigestFromFile(papszFiles[i], &pszDigest, NULL, NULL);
    307307        if (RT_FAILURE(rc))
    308308            break;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette