Index: /trunk/include/iprt/x509.h
===================================================================
--- /trunk/include/iprt/x509.h	(revision 50953)
+++ /trunk/include/iprt/x509.h	(revision 50954)
@@ -38,5 +38,12 @@
  */
 
-RTDECL(void) RTX509PrepareOpenSSL();
+/**
+ * Preparation before start to work with openssl
+ *
+ * @todo This should return a status and check that X509 code seems sane.  This
+ *       would allow dynamic linking if necessary at some point.
+ */
+RTDECL(int) RTX509PrepareOpenSSL(void);
+
 /**
  * Verify RSA signature for the given memory buffer.
@@ -64,4 +71,5 @@
 RTDECL(int) RTX509CertificateVerify(void *pvBuf, unsigned int cbSize);
 
+/** @todo document me. */
 RTDECL(unsigned long) RTX509GetErrorDescription(char** pErrorDesc);
 
Index: /trunk/src/VBox/Runtime/common/checksum/x509.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/checksum/x509.cpp	(revision 50953)
+++ /trunk/src/VBox/Runtime/common/checksum/x509.cpp	(revision 50954)
@@ -30,12 +30,6 @@
 *******************************************************************************/
 #include "internal/iprt.h"
-
-#include <openssl/bio.h>
-#include <openssl/err.h>
-#include <openssl/pem.h>
-#include <openssl/x509.h>
-#include <openssl/x509v3.h>
-
 #include <iprt/x509.h>
+
 #include <iprt/assert.h>
 #include <iprt/mem.h>
@@ -45,45 +39,51 @@
 #include <iprt/string.h>
 
+#include <openssl/bio.h>
+#include <openssl/err.h>
+#include <openssl/pem.h>
+#include <openssl/x509.h>
+#include <openssl/x509v3.h>
+
+
 /**
  * Preparation before start to work with openssl
  *
- * @returns none
- *
- */
-RTDECL(void) RTX509PrepareOpenSSL()
+ * @returns IPRT status code.
+ */
+RTDECL(int) RTX509PrepareOpenSSL(void)
 {
     OpenSSL_add_all_digests();
     ERR_load_BIO_strings();
     ERR_load_crypto_strings();
+    return VINF_SUCCESS;
 }
 RT_EXPORT_SYMBOL(RTX509PrepareOpenSSL);
 
+
 /**
- * Read X509 certificate from the given memory buffer into the 
- * internal structure.
- *
- * @returns iprt status code.
- *
- * @param   pvBuf                 string representation
- *                                containing X509 certificate
- *                                in PEM format
- * @param   cbSize                The amount of data (in bytes)
- * @param   out_cert              pointer to the structure where 
- *                                the info about X509
- *                                certificate will be stored
- */
-static int RTX509ReadCertificateFromPEM(void *pvBuf, unsigned int cbSize, X509** out_cert)
-{
-    int rc = VINF_SUCCESS;
-
-    BIO *bio_memory = BIO_new(BIO_s_mem());
-    int cbytes = BIO_write(bio_memory,(const void*)pvBuf ,cbSize) ;
-    *out_cert = PEM_read_bio_X509(bio_memory,NULL,0,NULL);
-    BIO_free(bio_memory);
-    if(!*out_cert)
-        rc = VERR_X509_READING_CERT_FROM_BIO;
-
-    return rc;
-}
+ * Read X509 certificate from the given memory buffer into the internal
+ * structure.
+ *
+ * @returns IPRT status code.
+ *
+ * @param   pvBuf           String representation containing X509
+ *                          certificate in PEM format.
+ * @param   cbBuf           The amount of data @a pvBuf points to.
+ * @param   ppOutCert       Where to store the pointer to the structure where
+ *                          the info about X509 certificate will be stored.
+ */
+static int rtX509ReadCertificateFromPEM(void const *pvPem, unsigned int cbPem, X509 **ppOutCert)
+{
+    BIO *pBio = BIO_new(BIO_s_mem());
+    if (!pBio)
+        return VERR_NO_MEMORY;
+
+    int cb = BIO_write(pBio, pvPem, cbPem);
+    *ppOutCert = PEM_read_bio_X509(pBio, NULL, 0, NULL);
+    BIO_free(pBio);
+
+    return *ppOutCert ? VINF_SUCCESS : VERR_X509_READING_CERT_FROM_BIO;
+}
+
 
 /**
@@ -194,5 +194,5 @@
         }
 
-        rc = RTX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
+        rc = rtX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
         if (RT_FAILURE(rc))
         {
@@ -267,7 +267,7 @@
     BIO *bio_memory = NULL;
 
-    while (1)
-    {
-        rc = RTX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
+    for (;;)
+    {
+        rc = rtX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
         int loc = X509_get_ext_by_NID(certificate, NID_basic_constraints,-1);
 
@@ -332,5 +332,5 @@
     while(1)
     {
-        rc = RTX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
+        rc = rtX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
         if (RT_FAILURE(rc))
         {
@@ -384,6 +384,6 @@
     return rc;
 }
-
 RT_EXPORT_SYMBOL(RTX509CertificateVerify);
+
 
 RTDECL(unsigned long) RTX509GetErrorDescription(char** pErrorDesc)
