/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 1.3.35
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

namespace be.portugal.eid {

using System;
using System.Runtime.InteropServices;

/// <summary>Class that represent one certificate.</summary>
public class PTEID_Certificate : PTEID_Crypto {
  private HandleRef swigCPtr;

  internal PTEID_Certificate(IntPtr cPtr, bool cMemoryOwn) : base(pteidlib_dotNetPINVOKE.PTEID_CertificateUpcast(cPtr), cMemoryOwn) {
    swigCPtr = new HandleRef(this, cPtr);
  }

  internal static HandleRef getCPtr(PTEID_Certificate obj) {
    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  }

  ~PTEID_Certificate() {
    Dispose();
  }

  public override void Dispose() {
    lock(this) {
      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
        swigCMemOwn = false;
        pteidlib_dotNetPINVOKE.delete_PTEID_Certificate(swigCPtr);
      }
      swigCPtr = new HandleRef(null, IntPtr.Zero);
      GC.SuppressFinalize(this);
      base.Dispose();
    }
  }

  /// <summary>Return the label of the certificate.</summary>
  public string getLabel()
  {
    string ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_getLabel(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the id of the certificate.</summary>
  public uint getID()
  {
    uint ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_getID(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the status of the certificate using default validation level (from config).</summary>
  public PTEID_CertifStatus getStatus()
  {
    PTEID_CertifStatus ret = (PTEID_CertifStatus)pteidlib_dotNetPINVOKE.PTEID_Certificate_getStatus__SWIG_0(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the status of the certificate.</summary>
  public PTEID_CertifStatus getStatus(PTEID_ValidationLevel crl, PTEID_ValidationLevel ocsp)
  {
    PTEID_CertifStatus ret = (PTEID_CertifStatus)pteidlib_dotNetPINVOKE.PTEID_Certificate_getStatus__SWIG_1(swigCPtr, (int)crl, (int)ocsp);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the type of the certificate.</summary>
  public PTEID_CertifType getType()
  {
    PTEID_CertifType ret = (PTEID_CertifType)pteidlib_dotNetPINVOKE.PTEID_Certificate_getType(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the content of the certificate.</summary>
  public PTEID_ByteArray getCertData()
  {
    PTEID_ByteArray ret = new PTEID_ByteArray(pteidlib_dotNetPINVOKE.PTEID_Certificate_getCertData(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the content of the certificate without ending zero.</summary>
  public void getFormattedData(PTEID_ByteArray data)
  {
    pteidlib_dotNetPINVOKE.PTEID_Certificate_getFormattedData(swigCPtr, PTEID_ByteArray.getCPtr(data));
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
  }

  /// <summary>Return the serial number of the certificate.</summary>
  public string getSerialNumber()
  {
    string ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_getSerialNumber(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the name of the owner of the certificate.</summary>
  public string getOwnerName()
  {
    string ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_getOwnerName(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the name of the issuer of the certificate.</summary>
  public string getIssuerName()
  {
    string ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_getIssuerName(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the validity begin date of the certificate.</summary>
  public string getValidityBegin()
  {
    string ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_getValidityBegin(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the validity end date of the certificate.</summary>
  public string getValidityEnd()
  {
    string ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_getValidityEnd(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the length of public/private key on the certificate.</summary>
  public uint getKeyLength()
  {
    uint ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_getKeyLength(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return true if this is a root certificate.</summary>
  public bool isRoot()
  {
    bool ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_isRoot(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the test status.</summary>
  /// <returns>
  /// - true if test certificate
  /// - false if good one
  /// </returns>
  public bool isTest()
  {
    bool ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_isTest(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return true if the certificate chain end by the one of pteid root.</summary>
  public bool isFromPteidValidChain()
  {
    bool ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_isFromPteidValidChain(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>This certificate comes from the card.</summary>
  public bool isFromCard()
  {
    bool ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_isFromCard(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>
  /// Return the issuer certificate.
  /// </summary>
  /// <remarks>
  /// If there is no issuer (root), PTEID_ExCertNoIssuer exception is thrown.
  /// </remarks>
  public PTEID_Certificate getIssuer()
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificate_getIssuer(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the number of children for this certificate.</summary>
  public uint countChildren()
  {
    uint ret = pteidlib_dotNetPINVOKE.PTEID_Certificate_countChildren(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>
  /// Return the children certificate (certificate that has been issued by this one).
  /// </summary>
  /// <remarks>
  /// Throw PTEID_ExParamRange exception if the index is out of range.
  /// </remarks>
  /// <param name="ulIndex">is the children index (the index for the first child is 0</param>  )
  public PTEID_Certificate getChildren(uint ulIndex)
  {
    PTEID_Certificate ret = new PTEID_Certificate(pteidlib_dotNetPINVOKE.PTEID_Certificate_getChildren(swigCPtr, ulIndex), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the crl of the certificate.</summary>
  public PTEID_Crl getCRL()
  {
    PTEID_Crl ret = new PTEID_Crl(pteidlib_dotNetPINVOKE.PTEID_Certificate_getCRL(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Return the ocsp response object of the certificate.</summary>
  public PTEID_OcspResponse getOcspResponse()
  {
    PTEID_OcspResponse ret = new PTEID_OcspResponse(pteidlib_dotNetPINVOKE.PTEID_Certificate_getOcspResponse(swigCPtr), false);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Verify the certificate trough CRL validation.</summary>
  public PTEID_CertifStatus verifyCRL(bool forceDownload)
  {
    PTEID_CertifStatus ret = (PTEID_CertifStatus)pteidlib_dotNetPINVOKE.PTEID_Certificate_verifyCRL__SWIG_0(swigCPtr, forceDownload);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Verify the certificate trough CRL validation.</summary>
  public PTEID_CertifStatus verifyCRL()
  {
    PTEID_CertifStatus ret = (PTEID_CertifStatus)pteidlib_dotNetPINVOKE.PTEID_Certificate_verifyCRL__SWIG_1(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  /// <summary>Verify the certificate trough OCSP validation.</summary>
  public PTEID_CertifStatus verifyOCSP()
  {
    PTEID_CertifStatus ret = (PTEID_CertifStatus)pteidlib_dotNetPINVOKE.PTEID_Certificate_verifyOCSP(swigCPtr);
    if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

}

}
