Changeset 84163 in vbox
- Timestamp:
- May 6, 2020 3:31:33 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/crypto/pem.h
r82968 r84163 31 31 32 32 #include <iprt/types.h> 33 #include <iprt/asn1.h> /* PRTASN1CORE */ 34 #include <iprt/string.h> /* PFNRTSTROUTPUT */ 33 35 34 36 … … 205 207 PCRTCRPEMMARKER paMarkers, size_t cMarkers); 206 208 209 210 /** 211 * PEM formatter for a binary data blob. 212 * 213 * @returns Number of output bytes (sum of @a pfnOutput return values). 214 * @param pfnOutput The output callback function. 215 * @param pvUser The user argument to the output callback. 216 * @param pvContent The binary blob to output. 217 * @param cbContent Size of the binary blob. 218 * @param pszMarker The PEM marker, .e.g "PRIVATE KEY", "CERTIFICATE" or 219 * similar. 220 * @sa RTCrPemWriteAsn1, RTCrPemWriteAsn1ToVfsFile, 221 * RTCrPemWriteAsn1ToVfsFile 222 */ 223 RTDECL(size_t) RTCrPemWriteBlob(PFNRTSTROUTPUT pfnOutput, void *pvUser, 224 const void *pvContent, size_t cbContent, const char *pszMarker); 225 226 /** 227 * PEM formatter for a generic ASN.1 structure. 228 * 229 * This will call both RTAsn1EncodePrepare() and RTAsn1EncodeWrite() on 230 * @a pRoot. Uses DER encoding. 231 * 232 * @returns Number of outputted chars (sum of @a pfnOutput return values), 233 * negative values are error status codes from the ASN.1 encoding. 234 * @param pfnOutput The output callback function. 235 * @param pvUser The user argument to the output callback. 236 * @param fFlags Reserved, MBZ. 237 * @param pRoot The root of the ASN.1 to encode and format as PEM. 238 * @param pszMarker The PEM marker, .e.g "PRIVATE KEY", "CERTIFICATE" or 239 * similar. 240 * @sa RTCrPemWriteAsn1ToVfsFile, RTCrPemWriteAsn1ToVfsFile, 241 * RTCrPemWriteBlob 242 */ 243 RTDECL(ssize_t) RTCrPemWriteAsn1(PFNRTSTROUTPUT pfnOutput, void *pvUser, PRTASN1CORE pRoot, 244 uint32_t fFlags, const char *pszMarker, PRTERRINFO pErrInfo); 245 246 /** 247 * PEM formatter for a generic ASN.1 structure and output it to @a hVfsIos. 248 * 249 * This will call both RTAsn1EncodePrepare() and RTAsn1EncodeWrite() on 250 * @a pRoot. Uses DER encoding. 251 * 252 * @returns Number of chars written, negative values are error status codes from 253 * the ASN.1 encoding or from RTVfsIoStrmWrite(). 254 * @param hVfsIos Handle to the I/O stream to write it to. 255 * @param fFlags Reserved, MBZ. 256 * @param pRoot The root of the ASN.1 to encode and format as PEM. 257 * @param pszMarker The PEM marker, .e.g "PRIVATE KEY", "CERTIFICATE" or 258 * similar. 259 * @sa RTCrPemWriteAsn1ToVfsFile, RTCrPemWriteAsn1, RTCrPemWriteBlob 260 */ 261 RTDECL(ssize_t) RTCrPemWriteAsn1ToVfsIoStrm(RTVFSIOSTREAM hVfsIos, PRTASN1CORE pRoot, 262 uint32_t fFlags, const char *pszMarker, PRTERRINFO pErrInfo); 263 264 /** 265 * PEM formatter for a generic ASN.1 structure and output it to @a hVfsFile. 266 * 267 * This will call both RTAsn1EncodePrepare() and RTAsn1EncodeWrite() on 268 * @a pRoot. Uses DER encoding. 269 * 270 * @returns Number of chars written, negative values are error status codes from 271 * the ASN.1 encoding or from RTVfsIoStrmWrite(). 272 * @param hVfsFile Handle to the file to write it to. 273 * @param fFlags Reserved, MBZ. 274 * @param pRoot The root of the ASN.1 to encode and format as PEM. 275 * @param pszMarker The PEM marker, .e.g "PRIVATE KEY", "CERTIFICATE" or 276 * similar. 277 * @sa RTCrPemWriteAsn1ToVfsIoStrm, RTCrPemWriteAsn1, RTCrPemWriteBlob 278 */ 279 RTDECL(ssize_t) RTCrPemWriteAsn1ToVfsFile(RTVFSFILE hVfsFile, PRTASN1CORE pRoot, 280 uint32_t fFlags, const char *pszMarker, PRTERRINFO pErrInfo); 281 207 282 /** @} */ 208 283 -
trunk/include/iprt/crypto/x509.h
r82968 r84163 1034 1034 1035 1035 1036 /** Wrapper around RTCrPemWriteAsn1ToVfsIoStrm(). */ 1037 DECLINLINE(int) RTCrX509Certificate_WriteToVfsIoStrm(RTVFSIOSTREAM hVfsIos, PRTCRX509CERTIFICATE pCertificate, PRTERRINFO pErrInfo) 1038 { 1039 return RTCrPemWriteAsn1ToVfsIoStrm(hVfsIos, &pCertificate->SeqCore.Asn1Core, 0 /*fFlags*/, 1040 g_aRTCrX509CertificateMarkers[0].paWords[0].pszWord, pErrInfo); 1041 } 1042 1043 /** Wrapper around RTCrPemWriteAsn1ToVfsFile(). */ 1044 DECLINLINE(int) RTCrX509Certificate_WriteToVfsFile(RTVFSFILE hVfsFile, PRTCRX509CERTIFICATE pCertificate, PRTERRINFO pErrInfo) 1045 { 1046 return RTCrPemWriteAsn1ToVfsFile(hVfsFile, &pCertificate->SeqCore.Asn1Core, 0 /*fFlags*/, 1047 g_aRTCrX509CertificateMarkers[0].paWords[0].pszWord, pErrInfo); 1048 } 1036 1049 1037 1050 /** @name X.509 Certificate Extensions -
trunk/include/iprt/mangling.h
r84146 r84163 2764 2764 # define RTVfsIoStrmSgWrite RT_MANGLER(RTVfsIoStrmSgWrite) 2765 2765 # define RTVfsIoStrmSkip RT_MANGLER(RTVfsIoStrmSkip) 2766 # define RTVfsIoStrmStrOutputCallback RT_MANGLER(RTVfsIoStrmStrOutputCallback) 2766 2767 # define RTVfsIoStrmTell RT_MANGLER(RTVfsIoStrmTell) 2767 2768 # define RTVfsIoStrmToFile RT_MANGLER(RTVfsIoStrmToFile) … … 3341 3342 # define RTCrPemParseContent RT_MANGLER(RTCrPemParseContent) 3342 3343 # define RTCrPemReadFile RT_MANGLER(RTCrPemReadFile) 3344 # define RTCrPemWriteBlob RT_MANGLER(RTCrPemWriteBlob) 3345 # define RTCrPemWriteAsn1 RT_MANGLER(RTCrPemWriteAsn1) 3346 # define RTCrPemWriteAsn1ToVfsIoStrm RT_MANGLER(RTCrPemWriteAsn1ToVfsIoStrm) 3347 # define RTCrPemWriteAsn1ToVfsFile RT_MANGLER(RTCrPemWriteAsn1ToVfsFile) 3343 3348 # define RTCrPkcs5Pbkdf2Hmac RT_MANGLER(RTCrPkcs5Pbkdf2Hmac) 3344 3349 # define RTCrPkcs7Attribute_DecodeAsn1 RT_MANGLER(RTCrPkcs7Attribute_DecodeAsn1) -
trunk/include/iprt/vfs.h
r84146 r84163 1229 1229 RTDECL(ssize_t) RTVfsIoStrmPrintfV(RTVFSIOSTREAM hVfsIos, const char *pszFormat, va_list va); 1230 1230 1231 /** 1232 * VFS I/O stream output buffer structure to use with 1233 * RTVfsIoStrmStrOutputCallback(). 1234 */ 1235 typedef struct VFSIOSTRMOUTBUF 1236 { 1237 /** The I/O stream handle. */ 1238 RTVFSIOSTREAM hVfsIos; 1239 /** Size of this structure (for sanity). */ 1240 size_t cbSelf; 1241 /** Status code of the operation. */ 1242 int rc; 1243 /** Current offset into szBuf (number of output bytes pending). */ 1244 size_t offBuf; 1245 /** Modest output buffer. */ 1246 char szBuf[256]; 1247 } VFSIOSTRMOUTBUF; 1248 /** Pointer to an VFS I/O stream output buffer for use with 1249 * RTVfsIoStrmStrOutputCallback() */ 1250 typedef VFSIOSTRMOUTBUF *PVFSIOSTRMOUTBUF; 1251 1252 /** Initializer for a VFS I/O stream output buffer. */ 1253 #define VFSIOSTRMOUTBUF_INIT(a_pOutBuf, a_hVfsIos) \ 1254 do { \ 1255 (a_pOutBuf)->hVfsIos = a_hVfsIos; \ 1256 (a_pOutBuf)->cbSelf = sizeof(*(a_pOutBuf)); \ 1257 (a_pOutBuf)->rc = VINF_SUCCESS; \ 1258 (a_pOutBuf)->offBuf = 0; \ 1259 (a_pOutBuf)->szBuf[0] = '\0'; \ 1260 } while (0) 1261 1262 /** 1263 * @callback_method_impl{FNRTSTROUTPUT, 1264 * For use with VFSIOSTRMOUTBUF. 1265 * 1266 * Users must use VFSIOSTRMOUTBUF_INIT to initialize a VFSIOSTRMOUTBUF and pass 1267 * that as the outputter argument to the function this callback is handed to.} 1268 */ 1269 RTDECL(size_t) RTVfsIoStrmStrOutputCallback(void *pvArg, const char *pachChars, size_t cbChars); 1270 1231 1271 /** @} */ 1232 1272 -
trunk/src/VBox/Runtime/Makefile.kmk
r84146 r84163 393 393 common/crypto/rsa-init.cpp \ 394 394 common/crypto/rsa-sanity.cpp \ 395 common/crypto/pemfile.cpp \ 395 common/crypto/pemfile-read.cpp \ 396 common/crypto/pemfile-write.cpp \ 396 397 common/crypto/pkcs7-asn1-decoder.cpp \ 397 398 common/crypto/pkcs7-core.cpp \ … … 1682 1683 common/checksum/sha512str.cpp \ 1683 1684 common/crypto/digest-core.cpp \ 1684 common/crypto/pemfile.cpp \ 1685 common/crypto/pemfile-read.cpp \ 1686 common/crypto/pemfile-write.cpp \ 1685 1687 common/crypto/pkcs7-asn1-decoder.cpp \ 1686 1688 common/crypto/pkcs7-core.cpp \ -
trunk/src/VBox/Runtime/common/crypto/pemfile-read.cpp
r84162 r84163 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Crypto - PEM file reader / writer.3 * IPRT - Crypto - PEM file reader. 4 4 * 5 5 * See RFC-1341 for the original ideas for the format, but keep in mind … … 651 651 return NULL; 652 652 } 653 -
trunk/src/VBox/Runtime/common/vfs/vfsprintf.cpp
r84152 r84163 35 35 36 36 37 /*********************************************************************************************************************************38 * Structures and Typedefs *39 *********************************************************************************************************************************/40 typedef struct PRINTFBUF41 {42 RTVFSIOSTREAM hVfsIos;43 int rc;44 size_t offBuf;45 char szBuf[256];46 } PRINTFBUF;47 48 49 37 /** Writes the buffer to the VFS file. */ 50 static void FlushPrintfBuffer(P RINTFBUF *pBuf)38 static void FlushPrintfBuffer(PVFSIOSTRMOUTBUF pBuf) 51 39 { 52 40 if (pBuf->offBuf) … … 61 49 62 50 63 /** @callback_method_impl{FNRTSTROUTPUT} */ 64 static DECLCALLBACK(size_t) MyPrintfOutputter(void *pvArg, const char *pachChars, size_t cbChars) 51 /** 52 * @callback_method_impl{FNRTSTROUTPUT, 53 * For use with VFSIOSTRMOUTBUF.} 54 */ 55 RTDECL(size_t) RTVfsIoStrmStrOutputCallback(void *pvArg, const char *pachChars, size_t cbChars) 65 56 { 66 PRINTFBUF *pBuf = (PRINTFBUF *)pvArg; 57 PVFSIOSTRMOUTBUF pBuf = (PVFSIOSTRMOUTBUF)pvArg; 58 AssertReturn(pBuf->cbSelf == sizeof(*pBuf), 0); 59 67 60 if (cbChars != 0) 68 61 { 69 size_t offSrc = 0; 70 while (offSrc < cbChars) 62 if (cbChars <= sizeof(pBuf->szBuf) * 3 / 2) 71 63 { 72 size_t cbLeft = sizeof(pBuf->szBuf) - pBuf->offBuf - 1; 73 if (cbLeft > 0) 64 /* 65 * Small piece of output: Buffer it. 66 */ 67 size_t offSrc = 0; 68 while (offSrc < cbChars) 74 69 { 75 size_t cbToCopy = RT_MIN(cbChars - offSrc, cbLeft); 76 memcpy(&pBuf->szBuf[pBuf->offBuf], &pachChars[offSrc], cbToCopy); 77 pBuf->offBuf += cbToCopy; 78 pBuf->szBuf[pBuf->offBuf] = '\0'; 79 if (cbLeft > cbToCopy) 80 break; 81 offSrc += cbToCopy; 70 size_t cbLeft = sizeof(pBuf->szBuf) - pBuf->offBuf - 1; 71 if (cbLeft > 0) 72 { 73 size_t cbToCopy = RT_MIN(cbChars - offSrc, cbLeft); 74 memcpy(&pBuf->szBuf[pBuf->offBuf], &pachChars[offSrc], cbToCopy); 75 pBuf->offBuf += cbToCopy; 76 pBuf->szBuf[pBuf->offBuf] = '\0'; 77 if (cbLeft > cbToCopy) 78 break; 79 offSrc += cbToCopy; 80 } 81 FlushPrintfBuffer(pBuf); 82 82 } 83 } 84 else 85 { 86 /* 87 * Large chunk of output: Output it directly. 88 */ 83 89 FlushPrintfBuffer(pBuf); 90 91 int rc = RTVfsIoStrmWrite(pBuf->hVfsIos, pachChars, cbChars, true /*fBlocking*/, NULL); 92 if (RT_FAILURE(rc)) 93 pBuf->rc = rc; 84 94 } 85 95 } … … 90 100 91 101 92 93 102 RTDECL(ssize_t) RTVfsIoStrmPrintfV(RTVFSIOSTREAM hVfsIos, const char *pszFormat, va_list va) 94 103 { 95 PRINTFBUF Buf; 96 Buf.hVfsIos = hVfsIos; 97 Buf.rc = VINF_SUCCESS; 98 Buf.offBuf = 0; 99 Buf.szBuf[0] = '\0'; 104 VFSIOSTRMOUTBUF Buf; 105 VFSIOSTRMOUTBUF_INIT(&Buf, hVfsIos); 100 106 101 size_t cchRet = RTStrFormatV( MyPrintfOutputter, &Buf, NULL, NULL, pszFormat, va);107 size_t cchRet = RTStrFormatV(RTVfsIoStrmStrOutputCallback, &Buf, NULL, NULL, pszFormat, va); 102 108 if (RT_SUCCESS(Buf.rc)) 103 109 return cchRet;
Note:
See TracChangeset
for help on using the changeset viewer.