/* This function returns the local public certificate which was currently set in the specified TLS object. */
EFI_STATUS EFIAPI TlsGetHostPublicCert(IN VOID *Tls, OUT VOID *Data, IN OUT UINTN *DataSize)
/* This function returns the local public certificate which was currently set in the specified TLS object. */
EFI_STATUS EFIAPI TlsGetHostPublicCert(IN VOID *Tls, OUT VOID *Data, IN OUT UINTN *DataSize)
{
  X509            *Cert;
  TLS_CONNECTION  *TlsConn;
  Cert    = NULL;
  TlsConn = (TLS_CONNECTION *)Tls;
  if ((TlsConn == NULL) || (TlsConn->Ssl == NULL) || (DataSize == NULL) || ((*DataSize != 0) && (Data == NULL))) {
    return EFI_INVALID_PARAMETER;
  }
  Cert = SSL_get_certificate (TlsConn->Ssl);
  if (Cert == NULL) {
    return EFI_NOT_FOUND;
  }
  if (*DataSize < (UINTN)i2d_X509 (Cert, NULL)) {
    *DataSize = (UINTN)i2d_X509 (Cert, NULL);
    return EFI_BUFFER_TOO_SMALL;
  }
  *DataSize = (UINTN)i2d_X509 (Cert, (unsigned char **)&Data);
  return EFI_SUCCESS;
}