Changeset 59620 in vbox
- Timestamp:
- Feb 10, 2016 12:47:33 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/crypto/digest.h
r58338 r59620 174 174 RTDECL(uint32_t) RTCrDigestRelease(RTCRDIGEST hDigest); 175 175 RTDECL(int) RTCrDigestUpdate(RTCRDIGEST hDigest, void const *pvData, size_t cbData); 176 RTDECL(int) RTCrDigestUpdateFromVfsFile(RTCRDIGEST hDigest, RTVFSFILE hVfsFile, bool fRewindFile); 176 177 RTDECL(int) RTCrDigestFinal(RTCRDIGEST hDigest, void *pvHash, size_t cbHash); 177 178 RTDECL(bool) RTCrDigestMatch(RTCRDIGEST hDigest, void const *pvHash, size_t cbHash); -
trunk/include/iprt/crypto/pkix.h
r56291 r59620 374 374 bool fEncrypt, PCRTASN1BITSTRING pKey,PCRTASN1DYNTYPE pParams); 375 375 RTDECL(int) RTCrPkixEncryptionCreateByObjId(PRTCRPKIXENCRYPTION phEncryption, PCRTASN1OBJID pObjId, bool fEncrypt, 376 PCRTASN1BITSTRING pKey, PCRTASN1DYNTYPE pParams);376 PCRTASN1BITSTRING pKey, PCRTASN1DYNTYPE pParams); 377 377 378 378 379 379 RTDECL(int) RTCrPkixEncryptionCreate(PRTCRPKIXENCRYPTION phEncryption, PCRTCRPKIXENCRYPTIONDESC pDesc, void *pvOpaque, 380 bool fEncrypt, PCRTASN1BITSTRING pKey, PCRTASN1DYNTYPE pParams);380 bool fEncrypt, PCRTASN1BITSTRING pKey, PCRTASN1DYNTYPE pParams); 381 381 RTDECL(int) RTCrPkixEncryptionReset(RTCRPKIXENCRYPTION hEncryption); 382 382 RTDECL(uint32_t) RTCrPkixEncryptionRetain(RTCRPKIXENCRYPTION hEncryption); -
trunk/include/iprt/crypto/x509.h
r58338 r59620 961 961 RTDECL(int) RTCrX509Certificate_ReadFromFile(PRTCRX509CERTIFICATE pCertificate, const char *pszFilename, uint32_t fFlags, 962 962 PCRTASN1ALLOCATORVTABLE pAllocator, PRTERRINFO pErrInfo); 963 RTDECL(int) RTCrX509Certificate_ReadFromBuffer(PRTCRX509CERTIFICATE pCertificate, const void *pvBuf, size_t cbBuf, 964 uint32_t fFlags, PCRTASN1ALLOCATORVTABLE pAllocator, 965 PRTERRINFO pErrInfo, const char *pszErrorTag); 966 963 967 964 968 -
trunk/include/iprt/mangling.h
r59575 r59620 1144 1144 # define RTManifestEqualsEx RT_MANGLER(RTManifestEqualsEx) 1145 1145 # define RTManifestPtIosAddEntryNow RT_MANGLER(RTManifestPtIosAddEntryNow) 1146 # define RTManifestPtIosIsInstanceOf RT_MANGLER(RTManifestPtIosIsInstanceOf) 1146 1147 # define RTManifestQueryAllAttrTypes RT_MANGLER(RTManifestQueryAllAttrTypes) 1147 1148 # define RTManifestQueryAttr RT_MANGLER(RTManifestQueryAttr) … … 2234 2235 # define RTVfsIoStreamToPrivate RT_MANGLER(RTVfsIoStreamToPrivate) 2235 2236 # define RTVfsIoStrmFlush RT_MANGLER(RTVfsIoStrmFlush) 2237 # define RTVfsIoStrmFromBuffer RT_MANGLER(RTVfsIoStrmFromBuffer) 2236 2238 # define RTVfsIoStrmFromRTFile RT_MANGLER(RTVfsIoStrmFromRTFile) 2237 2239 # define RTVfsIoStrmFromRTPipe RT_MANGLER(RTVfsIoStrmFromRTPipe) … … 2243 2245 # define RTVfsIoStrmRead RT_MANGLER(RTVfsIoStrmRead) 2244 2246 # define RTVfsIoStrmReadAt RT_MANGLER(RTVfsIoStrmReadAt) 2247 # define RTVfsIoStrmReadAll RT_MANGLER(RTVfsIoStrmReadAll) 2248 # define RTVfsIoStrmReadAllFree RT_MANGLER(RTVfsIoStrmReadAllFree) 2245 2249 # define RTVfsIoStrmRelease RT_MANGLER(RTVfsIoStrmRelease) 2246 2250 # define RTVfsIoStrmRetain RT_MANGLER(RTVfsIoStrmRetain) … … 2697 2701 # define RTCrDigestRetain RT_MANGLER(RTCrDigestRetain) 2698 2702 # define RTCrDigestUpdate RT_MANGLER(RTCrDigestUpdate) 2703 # define RTCrDigestUpdateFromVfsFile RT_MANGLER(RTCrDigestUpdateFromVfsFile) 2699 2704 # define RTCrDigestCreateByObjId RT_MANGLER(RTCrDigestCreateByObjId) 2700 2705 # define RTCrDigestCreateByObjIdString RT_MANGLER(RTCrDigestCreateByObjIdString) … … 3059 3064 # define RTCrX509Validity_IsValidAtTimeSpec RT_MANGLER(RTCrX509Validity_IsValidAtTimeSpec) 3060 3065 # define RTCrX509Certificate_ReadFromFile RT_MANGLER(RTCrX509Certificate_ReadFromFile) 3066 # define RTCrX509Certificate_ReadFromBuffer RT_MANGLER(RTCrX509Certificate_ReadFromBuffer) 3061 3067 # define RTCrX509AlgorithmIdentifier_Clone RT_MANGLER(RTCrX509AlgorithmIdentifier_Clone) 3062 3068 # define RTCrX509AlgorithmIdentifier_Init RT_MANGLER(RTCrX509AlgorithmIdentifier_Init) -
trunk/include/iprt/manifest.h
r59575 r59620 320 320 321 321 /** 322 * Checks if the give I/O stream is a manifest passthru instance or not. 323 * 324 * @returns true if it's a manifest passthru I/O stream, false if not. 325 * @param hVfsPtIos Possible the manifest passthru I/O stream handle. 326 */ 327 RTDECL(bool) RTManifestPtIosIsInstanceOf(RTVFSIOSTREAM hVfsPtIos); 328 329 /** 322 330 * Adds an entry for a file with the specified set of attributes. 323 331 * -
trunk/include/iprt/vfs.h
r59524 r59620 440 440 441 441 /** 442 * Creates a VFS file from a memory buffer. 443 * 444 * @returns IPRT status code. 445 * 446 * @param fFlags A combination of RTFILE_O_READ and RTFILE_O_WRITE. 447 * @param pvBuf The buffer. This will be copied and not referenced 448 * after this function returns. 449 * @param cbBuf The buffer size. 450 * @param phVfsIos Where to return the VFS I/O stream handle. 451 */ 452 RTDECL(int) RTVfsIoStrmFromBuffer(uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSIOSTREAM phVfsIos); 453 454 /** 442 455 * Creates a VFS I/O stream handle from a standard IPRT file handle (RTFILE). 443 456 * … … 554 567 */ 555 568 RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead); 556 RTDECL(int) RTVfsIoStrmReadAt(RTVFSIOSTREAM hVfsIos, RTFOFF off, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead); 557 558 /** 559 * Write bytes to the I/O stream. 560 * 561 * @returns IPRT status code. 562 * @retval VERR_ACCESS_DENIED if the stream is not writable. 563 * 564 * @param hVfsIos The VFS I/O stream handle. 565 * @param pvBuf The bytes to write. 566 * @param cbToWrite The number of bytes to write. 567 * @param fBlocking Whether the call is blocking (@c true) or not. If 568 * not, the @a pcbWritten parameter must not be NULL. 569 * @param pcbWritten Where to always store the number of bytes actually 570 * written. This can be NULL if @a fBlocking is true. 571 * @sa RTVfsFileWrite, RTFileWrite, RTPipeWrite, RTPipeWriteBlocking, 572 * RTSocketWrite 573 */ 574 RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten); 575 RTDECL(int) RTVfsIoStrmWriteAt(RTVFSIOSTREAM hVfsIos, RTFOFF off, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten); 576 577 /** 578 * Reads bytes from the I/O stream into a scatter buffer. 569 570 /** 571 * Read bytes from the I/O stream, optionally with offset. 579 572 * 580 573 * @returns IPRT status code. … … 594 587 * 595 588 * @param hVfsIos The VFS I/O stream handle. 589 * @param off Where to read at, -1 for the current position. 590 * @param pvBuf Where to store the read bytes. 591 * @param cbToRead The number of bytes to read. 592 * @param fBlocking Whether the call is blocking (@c true) or not. If 593 * not, the @a pcbRead parameter must not be NULL. 594 * @param pcbRead Where to always store the number of bytes actually 595 * read. This can be NULL if @a fBlocking is true. 596 * @sa RTVfsFileRead, RTFileRead, RTPipeRead, RTPipeReadBlocking, 597 * RTSocketRead 598 */ 599 RTDECL(int) RTVfsIoStrmReadAt(RTVFSIOSTREAM hVfsIos, RTFOFF off, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead); 600 601 /** 602 * Reads the remainder of the stream into a memory buffer. 603 * 604 * For simplifying string-style processing, the is a zero byte after the 605 * returned buffer, making sure it can be used as a zero terminated string. 606 * 607 * @returns IPRT status code. 608 * @param hVfsIos The VFS I/O stream handle. 609 * @param ppvBuf Where to return the buffer. Must pass to 610 * RTVfsIoStrmReadAllFree for freeing, not RTMemFree! 611 * @param pcbBuf Where to return the buffer size. 612 */ 613 RTDECL(int) RTVfsIoStrmReadAll(RTVFSIOSTREAM hVfsIos, void **ppvBuf, size_t *pcbBuf); 614 615 /** 616 * Free memory buffer returned by RTVfsIoStrmReadAll. 617 * 618 * @param pvBuf What RTVfsIoStrmReadAll returned. 619 * @param cbBuf What RTVfsIoStrmReadAll returned. 620 */ 621 RTDECL(void) RTVfsIoStrmReadAllFree(void *pvBuf, size_t cbBuf); 622 623 /** 624 * Write bytes to the I/O stream. 625 * 626 * @returns IPRT status code. 627 * @retval VERR_ACCESS_DENIED if the stream is not writable. 628 * 629 * @param hVfsIos The VFS I/O stream handle. 630 * @param pvBuf The bytes to write. 631 * @param cbToWrite The number of bytes to write. 632 * @param fBlocking Whether the call is blocking (@c true) or not. If 633 * not, the @a pcbWritten parameter must not be NULL. 634 * @param pcbWritten Where to always store the number of bytes actually 635 * written. This can be NULL if @a fBlocking is true. 636 * @sa RTVfsFileWrite, RTFileWrite, RTPipeWrite, RTPipeWriteBlocking, 637 * RTSocketWrite 638 */ 639 RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten); 640 RTDECL(int) RTVfsIoStrmWriteAt(RTVFSIOSTREAM hVfsIos, RTFOFF off, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten); 641 642 /** 643 * Reads bytes from the I/O stream into a scatter buffer. 644 * 645 * @returns IPRT status code. 646 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead. 647 * @retval VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL, 648 * and no data was available. @a *pcbRead will be set to 0. 649 * @retval VINF_EOF when trying to read __beyond__ the end of the stream and 650 * @a pcbRead is not NULL (it will be set to the number of bytes read, 651 * or 0 if the end of the stream was reached before this call). 652 * When the last byte of the read request is the last byte in the 653 * stream, this status code will not be used. However, VINF_EOF is 654 * returned when attempting to read 0 bytes while standing at the end 655 * of the stream. 656 * @retval VERR_EOF when trying to read __beyond__ the end of the stream and 657 * @a pcbRead is NULL. 658 * @retval VERR_ACCESS_DENIED if the stream is not readable. 659 * 660 * @param hVfsIos The VFS I/O stream handle. 661 * @param off Where to read at, -1 for the current position. 596 662 * @param pSgBuf Pointer to a scatter buffer descriptor. The number 597 663 * of bytes described by the segments is what will be … … 603 669 * @sa RTFileSgRead, RTSocketSgRead, RTPipeRead, RTPipeReadBlocking 604 670 */ 605 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);671 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead); 606 672 607 673 /** … … 612 678 * 613 679 * @param hVfsIos The VFS I/O stream handle. 680 * @param off Where to write at, -1 for the current position. 614 681 * @param pSgBuf Pointer to a gather buffer descriptor. The number 615 682 * of bytes described by the segments is what will be … … 621 688 * @sa RTFileSgWrite, RTSocketSgWrite 622 689 */ 623 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);690 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten); 624 691 625 692 /** … … 686 753 * Process the rest of the stream, checking if it's all valid UTF-8 encoding. 687 754 * 688 * @returns VBox status cod.e755 * @returns IPRT status code. 689 756 * 690 757 * @param hVfsIos The VFS I/O stream handle. … … 785 852 * @returns IPRT status code. 786 853 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead. 787 * @retval VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL,788 * and no data was available. @a *pcbRead will be set to 0.789 854 * @retval VINF_EOF when trying to read __beyond__ the end of the file and 790 855 * @a pcbRead is not NULL (it will be set to the number of bytes read, … … 890 955 * Memorizes the I/O stream as a file backed by memory. 891 956 * 892 * @returns VBoxstatus code.957 * @returns IPRT status code. 893 958 * 894 959 * @param hVfsIos The VFS I/O stream to memorize. This will be read … … 905 970 * Creates a VFS file from a memory buffer. 906 971 * 907 * @returns VBox status code. 908 * 909 * @param hVfsIos The VFS I/O stream to memorize. This will be read 910 * to the end on success, on failure its position is 911 * undefined. 972 * @returns IPRT status code. 973 * 912 974 * @param fFlags A combination of RTFILE_O_READ and RTFILE_O_WRITE. 913 975 * @param pvBuf The buffer. This will be copied and not referenced … … 917 979 * success. 918 980 */ 919 RTDECL(int) RTVfsFileFromBuffer( RTVFSIOSTREAM hVfsIos,uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile);981 RTDECL(int) RTVfsFileFromBuffer(uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile); 920 982 921 983 /** 922 984 * Creates a memory backed VFS file object for read and write. 923 985 * 924 * @returns VBoxstatus code.986 * @returns IPRT status code. 925 987 * 926 988 * @param hVfsIos The VFS I/O stream to memorize. This will be read -
trunk/src/VBox/Runtime/Makefile.kmk
r59527 r59620 336 336 common/crypto/digest-core.cpp \ 337 337 common/crypto/digest-builtin.cpp \ 338 common/crypto/digest-vfs.cpp \ 338 339 common/crypto/iprt-openssl.cpp \ 339 340 common/crypto/rsa-asn1-decoder.cpp \ -
trunk/src/VBox/Runtime/common/checksum/manifest2.cpp
r59575 r59620 527 527 528 528 /* 529 * Ignore this entry .529 * Ignore this entry? 530 530 */ 531 531 char const * const *ppsz = pEquals->papszIgnoreEntries; -
trunk/src/VBox/Runtime/common/checksum/manifest3.cpp
r57358 r59620 32 32 #include <iprt/manifest.h> 33 33 34 #include <iprt/alloca.h> 34 35 #include <iprt/asm.h> 35 36 #include <iprt/assert.h> … … 91 92 /** The hashes. */ 92 93 PRTMANIFESTHASHES pHashes; 94 /** The current hash position. */ 95 RTFOFF offCurPos; 93 96 /** Whether we're reading or writing. */ 94 97 bool fReadOrWrite; … … 315 318 { 316 319 PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis; 317 int rc = RTVfsIoStrmSgRead(pThis->hVfsIos, pSgBuf, fBlocking, pcbRead); 320 int rc; 321 322 /* 323 * To make sure we're continuing where we left off, we must have the exact 324 * stream position since a previous read using 'off' may change it. 325 */ 326 RTFOFF offActual = off == -1 ? RTVfsIoStrmTell(pThis->hVfsIos) : off; 327 if (offActual == pThis->offCurPos) 328 { 329 rc = RTVfsIoStrmSgRead(pThis->hVfsIos, off, pSgBuf, fBlocking, pcbRead); 330 if (RT_SUCCESS(rc)) 331 { 332 rtManifestPtIos_UpdateHashes(pThis, pSgBuf, pcbRead ? *pcbRead : ~(size_t)0); 333 if (!pcbRead) 334 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++) 335 pThis->offCurPos += pSgBuf->paSegs[iSeg].cbSeg; 336 else 337 pThis->offCurPos += *pcbRead; 338 } 339 Assert(RTVfsIoStrmTell(pThis->hVfsIos) == pThis->offCurPos); 340 } 341 else 342 { 343 /* 344 * If we're skipping over stuff, we need to read the gap and hash it. 345 */ 346 if (pThis->offCurPos < offActual) 347 { 348 size_t cbBuf = _8K; 349 void *pvBuf = alloca(cbBuf); 350 do 351 { 352 RTFOFF cbGap = off - pThis->offCurPos; 353 size_t cbThisRead = cbGap >= (RTFOFF)cbBuf ? cbBuf : (size_t)cbGap; 354 size_t cbActual; 355 rc = RTVfsIoStrmReadAt(pThis->hVfsIos, pThis->offCurPos, pvBuf, cbThisRead, fBlocking, &cbActual); 356 if (RT_FAILURE(rc) || rc == VINF_TRY_AGAIN) 357 return rc; 358 359 rtManifestHashesUpdate(pThis->pHashes, pvBuf, cbActual); 360 pThis->offCurPos += cbActual; 361 362 if (rc == VINF_EOF) 363 { 364 if (pcbRead) 365 *pcbRead = 0; 366 else 367 rc = VERR_EOF; 368 return rc; 369 } 370 } while (pThis->offCurPos < offActual); 371 Assert(RTVfsIoStrmTell(pThis->hVfsIos) == offActual); 372 } 373 374 /* 375 * At this point we've eliminated any gap and can execute the requested read. 376 */ 377 rc = RTVfsIoStrmSgRead(pThis->hVfsIos, off, pSgBuf, fBlocking, pcbRead); 378 if (RT_SUCCESS(rc)) 379 { 380 /* See if there is anything to update the hash with. */ 381 size_t cbLeft = pcbRead ? *pcbRead : ~(size_t)0; 382 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++) 383 { 384 size_t cbThis = pSgBuf->paSegs[iSeg].cbSeg; 385 if (cbThis > cbLeft) 386 cbThis = cbLeft; 387 388 if ( offActual >= pThis->offCurPos 389 && pThis->offCurPos < offActual + (ssize_t)cbThis) 390 { 391 size_t offSeg = (size_t)(offActual - pThis->offCurPos); 392 rtManifestHashesUpdate(pThis->pHashes, (uint8_t *)pSgBuf->paSegs[iSeg].pvSeg + offSeg, cbThis - offSeg); 393 pThis->offCurPos += cbThis - offSeg; 394 } 395 396 cbLeft -= cbThis; 397 if (!cbLeft) 398 break; 399 offActual += cbThis; 400 } 401 } 402 } 403 return rc; 404 } 405 406 407 /** 408 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 409 */ 410 static DECLCALLBACK(int) rtManifestPtIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 411 { 412 PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis; 413 AssertReturn(off == -1 || off == pThis->offCurPos, VERR_WRONG_ORDER); 414 Assert(RTVfsIoStrmTell(pThis->hVfsIos) == pThis->offCurPos); 415 416 int rc = RTVfsIoStrmSgWrite(pThis->hVfsIos, -1 /*off*/, pSgBuf, fBlocking, pcbWritten); 318 417 if (RT_SUCCESS(rc)) 319 rtManifestPtIos_UpdateHashes(pThis, pSgBuf, pcbRead ? *pcbRead : ~(size_t)0); 320 Assert(off == -1); NOREF(off); 321 return rc; 322 } 323 324 325 /** 326 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 327 */ 328 static DECLCALLBACK(int) rtManifestPtIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 329 { 330 PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis; 331 int rc = RTVfsIoStrmSgWrite(pThis->hVfsIos, pSgBuf, fBlocking, pcbWritten); 332 if (RT_SUCCESS(rc)) 418 { 333 419 rtManifestPtIos_UpdateHashes(pThis, pSgBuf, pcbWritten ? *pcbWritten : ~(size_t)0); 334 Assert(off == -1); NOREF(off); 420 if (!pcbWritten) 421 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++) 422 pThis->offCurPos += pSgBuf->paSegs[iSeg].cbSeg; 423 else 424 pThis->offCurPos += *pcbWritten; 425 } 335 426 return rc; 336 427 } … … 425 516 AssertPtr(pszEntry); 426 517 AssertPtr(phVfsIosPassthru); 518 519 RTFOFF const offCurPos = RTVfsIoStrmTell(hVfsIos); 520 AssertReturn(offCurPos >= 0, (int)offCurPos); 521 427 522 uint32_t cRefs = RTManifestRetain(hManifest); 428 523 AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE); 524 429 525 cRefs = RTVfsIoStrmRetain(hVfsIos); 430 526 AssertReturnStmt(cRefs != UINT32_MAX, RTManifestRelease(hManifest), VERR_INVALID_HANDLE); … … 441 537 pThis->hVfsIos = hVfsIos; 442 538 pThis->pHashes = rtManifestHashesCreate(fAttrs); 539 pThis->offCurPos = offCurPos; 443 540 pThis->hManifest = hManifest; 444 541 pThis->fReadOrWrite = fReadOrWrite; … … 478 575 rtManifestHashesFinal(pThis->pHashes); 479 576 return rtManifestHashesSetAttrs(pThis->pHashes, pThis->hManifest, pThis->pszEntry); 577 } 578 579 580 /** 581 * Checks if the give I/O stream is a manifest passthru instance or not. 582 * 583 * @returns true if it's a manifest passthru I/O stream, false if not. 584 * @param hVfsPtIos Possible the manifest passthru I/O stream handle. 585 */ 586 RTDECL(bool) RTManifestPtIosIsInstanceOf(RTVFSIOSTREAM hVfsPtIos) 587 { 588 if (hVfsPtIos != NIL_RTVFSIOSTREAM) 589 { 590 PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)RTVfsIoStreamToPrivate(hVfsPtIos, &g_rtManifestPassthruIosOps); 591 if (pThis) 592 return true; 593 } 594 return false; 480 595 } 481 596 -
trunk/src/VBox/Runtime/common/crypto/x509-file.cpp
r57358 r59620 79 79 80 80 81 RTDECL(int) RTCrX509Certificate_ReadFromBuffer(PRTCRX509CERTIFICATE pCertificate, const void *pvBuf, size_t cbBuf, 82 uint32_t fFlags, PCRTASN1ALLOCATORVTABLE pAllocator, 83 PRTERRINFO pErrInfo, const char *pszErrorTag) 84 { 85 AssertReturn(!fFlags, VERR_INVALID_FLAGS); 86 PCRTCRPEMSECTION pSectionHead; 87 int rc = RTCrPemParseContent(pvBuf, cbBuf, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), 88 &pSectionHead, pErrInfo); 89 if (RT_SUCCESS(rc)) 90 { 91 RTCRX509CERTIFICATE TmpCert; 92 RTASN1CURSORPRIMARY PrimaryCursor; 93 RTAsn1CursorInitPrimary(&PrimaryCursor, pSectionHead->pbData, (uint32_t)RT_MIN(pSectionHead->cbData, UINT32_MAX), 94 pErrInfo, pAllocator, RTASN1CURSOR_FLAGS_DER, pszErrorTag); 95 rc = RTCrX509Certificate_DecodeAsn1(&PrimaryCursor.Cursor, 0, &TmpCert, "Cert"); 96 if (RT_SUCCESS(rc)) 97 { 98 rc = RTCrX509Certificate_CheckSanity(&TmpCert, 0, pErrInfo, "Cert"); 99 if (RT_SUCCESS(rc)) 100 { 101 rc = RTCrX509Certificate_Clone(pCertificate, &TmpCert, &g_RTAsn1DefaultAllocator); 102 if (RT_SUCCESS(rc)) 103 { 104 if (pSectionHead->pNext || PrimaryCursor.Cursor.cbLeft) 105 rc = VINF_ASN1_MORE_DATA; 106 } 107 } 108 RTCrX509Certificate_Delete(&TmpCert); 109 } 110 RTCrPemFreeSections(pSectionHead); 111 } 112 return rc; 113 } 114 115 81 116 82 117 #if 0 -
trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp
r57358 r59620 2135 2135 2136 2136 2137 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)2137 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 2138 2138 { 2139 2139 AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER); … … 2150 2150 int rc; 2151 2151 if (!(pThis->pOps->fFeatures & RTVFSIOSTREAMOPS_FEAT_NO_SG)) 2152 rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, pSgBuf, fBlocking, pcbRead);2152 rc = pThis->pOps->pfnRead(pThis->Base.pvThis, off, pSgBuf, fBlocking, pcbRead); 2153 2153 else 2154 2154 { … … 2162 2162 2163 2163 size_t cbReadSeg = pcbRead ? 0 : pSgBuf->paSegs[iSeg].cbSeg; 2164 rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbRead ? &cbReadSeg : NULL);2164 rc = pThis->pOps->pfnRead(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbRead ? &cbReadSeg : NULL); 2165 2165 if (RT_FAILURE(rc)) 2166 2166 break; … … 2168 2168 if ((pcbRead && cbReadSeg != SgBuf.paSegs[0].cbSeg) || rc != VINF_SUCCESS) 2169 2169 break; 2170 if (off != -1) 2171 off += cbReadSeg; 2170 2172 } 2171 2173 … … 2178 2180 2179 2181 2180 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)2182 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 2181 2183 { 2182 2184 AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER); … … 2193 2195 int rc; 2194 2196 if (!(pThis->pOps->fFeatures & RTVFSIOSTREAMOPS_FEAT_NO_SG)) 2195 rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, pSgBuf, fBlocking, pcbWritten);2197 rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, pSgBuf, fBlocking, pcbWritten); 2196 2198 else 2197 2199 { … … 2205 2207 2206 2208 size_t cbWrittenSeg = 0; 2207 rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbWritten ? &cbWrittenSeg : NULL);2209 rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbWritten ? &cbWrittenSeg : NULL); 2208 2210 if (RT_FAILURE(rc)) 2209 2211 break; … … 2213 2215 if (cbWrittenSeg != SgBuf.paSegs[0].cbSeg) 2214 2216 break; 2217 if (off != -1) 2218 off += cbWrittenSeg; 2215 2219 } 2220 else if (off != -1) 2221 off += pSgBuf->paSegs[iSeg].cbSeg; 2216 2222 } 2217 2223 -
trunk/src/VBox/Runtime/common/vfs/vfsiosmisc.cpp
r57358 r59620 33 33 34 34 #include <iprt/err.h> 35 #include <iprt/mem.h> 35 36 #include <iprt/string.h> 36 37 … … 124 125 } 125 126 127 128 /** Header size. */ 129 #define READ_ALL_HEADER_SIZE 0x20 130 /** The header magic. It's followed by the size (both size_t). */ 131 #define READ_ALL_HEADER_MAGIC UINT32_C(0x11223355) 132 133 RTDECL(int) RTVfsIoStrmReadAll(RTVFSIOSTREAM hVfsIos, void **ppvBuf, size_t *pcbBuf) 134 { 135 /* 136 * Try query the object information and in case the stream has a known 137 * size we could use for guidance. 138 */ 139 RTFSOBJINFO ObjInfo; 140 int rc = RTVfsIoStrmQueryInfo(hVfsIos, &ObjInfo, RTFSOBJATTRADD_NOTHING); 141 size_t cbAllocated = RT_SUCCESS(rc) && ObjInfo.cbObject > 0 && ObjInfo.cbObject < _1G 142 ? (size_t)ObjInfo.cbObject + 1 : _16K; 143 cbAllocated += READ_ALL_HEADER_SIZE; 144 void *pvBuf = RTMemAlloc(cbAllocated); 145 if (pvBuf) 146 { 147 memset(pvBuf, 0xfe, READ_ALL_HEADER_SIZE); 148 size_t off = 0; 149 for (;;) 150 { 151 /* 152 * Handle buffer growing and detecting the end of it all. 153 */ 154 size_t cbToRead = cbAllocated - off - READ_ALL_HEADER_SIZE - 1; 155 if (!cbToRead) 156 { 157 /* The end? */ 158 uint8_t bIgn; 159 size_t cbIgn; 160 rc = RTVfsIoStrmRead(hVfsIos, &bIgn, 0, true /*fBlocking*/, &cbIgn); 161 if (rc == VINF_EOF) 162 break; 163 164 /* Grow the buffer. */ 165 cbAllocated -= READ_ALL_HEADER_SIZE - 1; 166 cbAllocated = RT_MAX(RT_MIN(cbAllocated, _32M), _1K); 167 cbAllocated = RT_ALIGN_Z(cbAllocated, _4K); 168 cbAllocated += READ_ALL_HEADER_SIZE + 1; 169 170 void *pvNew = RTMemRealloc(pvBuf, cbAllocated); 171 AssertBreakStmt(pvNew, rc = VERR_NO_MEMORY); 172 173 cbToRead = cbAllocated - off - READ_ALL_HEADER_SIZE - 1; 174 } 175 Assert(cbToRead < cbAllocated); 176 177 /* 178 * Read. 179 */ 180 size_t cbActual; 181 rc = RTVfsIoStrmRead(hVfsIos, (uint8_t *)pvBuf + READ_ALL_HEADER_SIZE + off, cbToRead, 182 true /*fBlocking*/, &cbActual); 183 if (RT_FAILURE(rc)) 184 break; 185 Assert(cbActual > 0); 186 Assert(cbActual <= cbToRead); 187 off += cbActual; 188 if (rc == VINF_EOF) 189 break; 190 } 191 Assert(rc != VERR_EOF); 192 if (RT_SUCCESS(rc)) 193 { 194 ((size_t *)pvBuf)[0] = READ_ALL_HEADER_MAGIC; 195 ((size_t *)pvBuf)[1] = off; 196 ((uint8_t *)pvBuf)[READ_ALL_HEADER_SIZE + off] = 0; 197 198 *ppvBuf = (uint8_t *)pvBuf + READ_ALL_HEADER_SIZE; 199 *pcbBuf = off; 200 return VINF_SUCCESS; 201 } 202 203 RTMemFree(pvBuf); 204 } 205 else 206 rc = VERR_NO_MEMORY; 207 *ppvBuf = NULL; 208 *pcbBuf = 0; 209 return rc; 210 } 211 212 213 RTDECL(void) RTVfsIoStrmReadAllFree(void *pvBuf, size_t cbBuf) 214 { 215 AssertPtrReturnVoid(pvBuf); 216 217 /* Spool back to the start of the header. */ 218 pvBuf = (uint8_t *)pvBuf - READ_ALL_HEADER_SIZE; 219 220 /* Make sure the caller isn't messing with us. Hardcoded, but works. */ 221 Assert(((size_t *)pvBuf)[0] == READ_ALL_HEADER_MAGIC); 222 Assert(((size_t *)pvBuf)[1] == cbBuf); 223 224 /* Free it. */ 225 RTMemFree(pvBuf); 226 } 227 -
trunk/src/VBox/Runtime/common/vfs/vfsmemory.cpp
r59524 r59620 805 805 806 806 807 RTDECL(int) RTVfsFileFromBuffer( RTVFSIOSTREAM hVfsIos,uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile)807 RTDECL(int) RTVfsFileFromBuffer(uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile) 808 808 { 809 809 /* … … 832 832 return VINF_SUCCESS; 833 833 } 834 RTVfsFileRelease(hVfsFile); 835 } 836 return rc; 837 } 838 839 840 RTDECL(int) RTVfsIoStrmFromBuffer(uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSIOSTREAM phVfsIos) 841 { 842 RTVFSFILE hVfsFile; 843 int rc = RTVfsFileFromBuffer(fFlags, pvBuf, cbBuf, &hVfsFile); 844 if (RT_SUCCESS(rc)) 845 { 846 *phVfsIos = RTVfsFileToIoStream(hVfsFile); 834 847 RTVfsFileRelease(hVfsFile); 835 848 } -
trunk/src/VBox/Runtime/common/vfs/vfsstdfile.cpp
r57635 r59620 502 502 int rc = RTVfsFileOpenNormal(pszFilename, fOpen, &hVfsFile); 503 503 if (RT_SUCCESS(rc)) 504 { 504 505 *phVfsIos = RTVfsFileToIoStream(hVfsFile); 505 return rc; 506 } 507 506 RTVfsFileRelease(hVfsFile); 507 } 508 return rc; 509 } 510 -
trunk/src/VBox/Runtime/common/zip/gzipvfs.cpp
r57358 r59620 313 313 { 314 314 size_t cbReadIn = ~(size_t)0; 315 rc = RTVfsIoStrmSgRead(pThis->hVfsIos, &pThis->SgBuf, fBlocking, &cbReadIn);315 rc = RTVfsIoStrmSgRead(pThis->hVfsIos, -1 /*off*/, &pThis->SgBuf, fBlocking, &cbReadIn); 316 316 if (rc != VINF_SUCCESS) 317 317 { … … 425 425 426 426 cbWrittenOut = ~(size_t)0; 427 rc = RTVfsIoStrmSgWrite(pThis->hVfsIos, &pThis->SgBuf, fBlocking, &cbWrittenOut);427 rc = RTVfsIoStrmSgWrite(pThis->hVfsIos, -1 /*off*/, &pThis->SgBuf, fBlocking, &cbWrittenOut); 428 428 if (rc != VINF_SUCCESS) 429 429 {
Note:
See TracChangeset
for help on using the changeset viewer.