Changeset 104745 in vbox for trunk/src/VBox/Runtime/common/crypto/iprt-openssl.cpp
- Timestamp:
- May 21, 2024 12:52:09 PM (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/iprt-openssl.cpp
r98103 r104745 43 43 #ifdef IPRT_WITH_OPENSSL /* Whole file. */ 44 44 # include <iprt/err.h> 45 # include <iprt/file.h> 45 46 # include <iprt/string.h> 46 47 # include <iprt/mem.h> … … 169 170 } 170 171 172 171 173 DECLHIDDEN(int) rtCrOpenSslConvertPkcs7Attribute(void **ppvOsslAttrib, PCRTCRPKCS7ATTRIBUTE pAttrib, PRTERRINFO pErrInfo) 172 174 { 173 const unsigned char *pabEncoded ;174 uint32_t cbEncoded ;175 void *pvFree ;175 const unsigned char *pabEncoded = NULL; 176 uint32_t cbEncoded = 0; 177 void *pvFree = NULL; 176 178 int rc = RTAsn1EncodeQueryRawBits(RTCrPkcs7Attribute_GetAsn1Core(pAttrib), 177 179 (const uint8_t **)&pabEncoded, &cbEncoded, &pvFree, pErrInfo); … … 199 201 200 202 203 /** 204 * Writes the content of the @a pvMemBio to the new file @a pszFilename. 205 * 206 * @returns IPRT status code. 207 * @param pvMemBio The memory BIO to write out. 208 * @param pszFilename The destination file. This will be created. 209 * The function will fail if this already exists. 210 * @param pErrInfo Where to provide additional error details. Optional. 211 */ 212 DECLHIDDEN(int) rtCrOpenSslWriteMemBioToNewFile(void *pvMemBio, const char *pszFilename, PRTERRINFO pErrInfo) 213 { 214 int rc; 215 216 /* Get the BIO buffer pointer first. */ 217 BUF_MEM *pBioBuf = NULL; 218 long rcOssl = BIO_get_mem_ptr((BIO *)pvMemBio, &pBioBuf); 219 if (rcOssl > 0) 220 { 221 AssertPtr(pBioBuf); 222 RTFILE hFile = NIL_RTFILE; 223 rc = RTFileOpen(&hFile, pszFilename, 224 RTFILE_O_WRITE | RTFILE_O_DENY_ALL | RTFILE_O_CREATE | (0600 << RTFILE_O_CREATE_MODE_SHIFT)); 225 if (RT_SUCCESS(rc)) 226 { 227 rc = RTFileWrite(hFile, pBioBuf->data, pBioBuf->length, NULL); 228 if (RT_SUCCESS(rc)) 229 { 230 rc = RTFileClose(hFile); 231 AssertRCStmt(rc, rc = RTErrInfoSetF(pErrInfo, rc, "RTFileClose failed on '%s'", pszFilename)); 232 } 233 else 234 { 235 rc = RTErrInfoSetF(pErrInfo, rc, "RTFileWrite(,,%#zx,) failed on '%s'", pBioBuf->length, pszFilename); 236 RTFileClose(hFile); 237 } 238 if (RT_FAILURE(rc)) 239 RTFileDelete(pszFilename); 240 } 241 else 242 rc = RTErrInfoSetF(pErrInfo, rc, "RTFileOpen failed on '%s'", pszFilename); 243 } 244 else 245 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "BIO_get_mem_ptr"); 246 return rc; 247 } 248 249 201 250 #endif /* IPRT_WITH_OPENSSL */ 202 251
Note:
See TracChangeset
for help on using the changeset viewer.