public List<OpenSslX509CertificateReader> ReadCertificates()
{
var certs = new List<OpenSslX509CertificateReader>();
if (_caStackHandle != null && !_caStackHandle.IsInvalid)
{
int caCertCount = Interop.Crypto.GetX509StackFieldCount(_caStackHandle);
for (int i = 0; i < caCertCount; i++)
{
IntPtr certPtr = Interop.Crypto.GetX509StackField(_caStackHandle, i);
if (certPtr != IntPtr.Zero)
{
// The STACK_OF(X509) still needs to be cleaned up, so upref the handle out of it.
certs.Add(new OpenSslX509CertificateReader(Interop.Crypto.X509UpRef(certPtr)));
}
}
}
if (_x509Handle != null && !_x509Handle.IsInvalid)
{
// The certificate and (if applicable) private key handles will be given over
// to the OpenSslX509CertificateReader, and the fields here are thus nulled out to
// prevent double-Dispose.
OpenSslX509CertificateReader reader = new OpenSslX509CertificateReader(_x509Handle);
_x509Handle = null;
if (_evpPkeyHandle != null && !_evpPkeyHandle.IsInvalid)
{
reader.SetPrivateKey(_evpPkeyHandle);
_evpPkeyHandle = null;
}
certs.Add(reader);
}
return certs;
}