/* ----------------------------------------------------------------------------
 * 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.
 * ----------------------------------------------------------------------------- */

package be.portugal.eid;

/******************************************************************************//**
  * Base class for a Smart card
  *********************************************************************************/
public class PTEID_SmartCard extends PTEID_Card {
  private long swigCPtr;

  protected PTEID_SmartCard(long cPtr, boolean cMemoryOwn) {
    super(pteidlibJava_WrapperJNI.SWIGPTEID_SmartCardUpcast(cPtr), cMemoryOwn);
    swigCPtr = cPtr;
  }

  protected static long getCPtr(PTEID_SmartCard obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if(swigCPtr != 0 && swigCMemOwn) {
      swigCMemOwn = false;
      pteidlibJava_WrapperJNI.delete_PTEID_SmartCard(swigCPtr);
    }
    swigCPtr = 0;
    super.delete();
  }

 	/**
	 * Select an application from the card
	 */
  public void selectApplication(PTEID_ByteArray applicationId) throws java.lang.Exception {
    pteidlibJava_WrapperJNI.PTEID_SmartCard_selectApplication(swigCPtr, this, PTEID_ByteArray.getCPtr(applicationId), applicationId);
  }

 	/**
	 * Send an APDU command to the card and get the result
	 * @param cmd is the apdu command
	 * @param pin is the pin to ask for writing
	 * @param csPinCode is the code of the pin (it will be asked if needed and not set)
	 * @return a PTEID_ByteArray containing the result
	 */
  public PTEID_ByteArray sendAPDU(PTEID_ByteArray cmd, PTEID_Pin pin, String csPinCode) throws java.lang.Exception {
    return new PTEID_ByteArray(pteidlibJava_WrapperJNI.PTEID_SmartCard_sendAPDU__SWIG_0(swigCPtr, this, PTEID_ByteArray.getCPtr(cmd), cmd, PTEID_Pin.getCPtr(pin), pin, csPinCode), true);
  }

 	/**
	 * Send an APDU command to the card and get the result
	 * @param cmd is the apdu command
	 * @param pin is the pin to ask for writing
	 * @return a PTEID_ByteArray containing the result
	 */
  public PTEID_ByteArray sendAPDU(PTEID_ByteArray cmd, PTEID_Pin pin) throws java.lang.Exception {
    return new PTEID_ByteArray(pteidlibJava_WrapperJNI.PTEID_SmartCard_sendAPDU__SWIG_1(swigCPtr, this, PTEID_ByteArray.getCPtr(cmd), cmd, PTEID_Pin.getCPtr(pin), pin), true);
  }

 	/**
	 * Send an APDU command to the card and get the result
	 * @param cmd is the apdu command
	 * @return a PTEID_ByteArray containing the result
	 */
  public PTEID_ByteArray sendAPDU(PTEID_ByteArray cmd) throws java.lang.Exception {
    return new PTEID_ByteArray(pteidlibJava_WrapperJNI.PTEID_SmartCard_sendAPDU__SWIG_2(swigCPtr, this, PTEID_ByteArray.getCPtr(cmd), cmd), true);
  }

 	/**
	 * Read a File from the card
	 *
	 * If no pin is passed and a pin is needed by the card, the pin code will be asked anyway
	 *
	 * @param fileID is the path of the file
	 * @param in return the file
	 * @param pin is the pin to ask for writing
	 * @param csPinCode is the code of the pin (it will be asked if needed and not set)
	 */
  public int readFile(String fileID, PTEID_ByteArray in, PTEID_Pin pin, String csPinCode) throws java.lang.Exception {
    return pteidlibJava_WrapperJNI.PTEID_SmartCard_readFile__SWIG_0(swigCPtr, this, fileID, PTEID_ByteArray.getCPtr(in), in, PTEID_Pin.getCPtr(pin), pin, csPinCode);
  }

 	/**
	 * Read a File from the card
	 *
	 * If no pin is passed and a pin is needed by the card, the pin code will be asked anyway
	 *
	 * @param fileID is the path of the file
	 * @param in return the file
	 * @param pin is the pin to ask for writing
	 */
  public int readFile(String fileID, PTEID_ByteArray in, PTEID_Pin pin) throws java.lang.Exception {
    return pteidlibJava_WrapperJNI.PTEID_SmartCard_readFile__SWIG_1(swigCPtr, this, fileID, PTEID_ByteArray.getCPtr(in), in, PTEID_Pin.getCPtr(pin), pin);
  }

 	/**
	 * Read a File from the card
	 *
	 * If no pin is passed and a pin is needed by the card, the pin code will be asked anyway
	 *
	 * @param fileID is the path of the file
	 * @param in return the file
	 */
  public int readFile(String fileID, PTEID_ByteArray in) throws java.lang.Exception {
    return pteidlibJava_WrapperJNI.PTEID_SmartCard_readFile__SWIG_2(swigCPtr, this, fileID, PTEID_ByteArray.getCPtr(in), in);
  }

 	/**
	 * Write a file to the card
	 * Throw PTEID_ExCmdNotAllowed exception you're not allowed to write the file
	 *
	 * If no pin is passed and a pin is needed by the card, the pin code will be asked anyway
	 *
	 * @param fileID is the path of the file
	 * @param out contents the bytes to write
	 * @param pin is the pin to ask for writing
	 * @param csPinCode is the code of the pin (it will be asked if needed and not set)
	 */
  public boolean writeFile(String fileID, PTEID_ByteArray out, PTEID_Pin pin, String csPinCode) throws java.lang.Exception {
    return pteidlibJava_WrapperJNI.PTEID_SmartCard_writeFile__SWIG_0(swigCPtr, this, fileID, PTEID_ByteArray.getCPtr(out), out, PTEID_Pin.getCPtr(pin), pin, csPinCode);
  }

 	/**
	 * Write a file to the card
	 * Throw PTEID_ExCmdNotAllowed exception you're not allowed to write the file
	 *
	 * If no pin is passed and a pin is needed by the card, the pin code will be asked anyway
	 *
	 * @param fileID is the path of the file
	 * @param out contents the bytes to write
	 * @param pin is the pin to ask for writing
	 */
  public boolean writeFile(String fileID, PTEID_ByteArray out, PTEID_Pin pin) throws java.lang.Exception {
    return pteidlibJava_WrapperJNI.PTEID_SmartCard_writeFile__SWIG_1(swigCPtr, this, fileID, PTEID_ByteArray.getCPtr(out), out, PTEID_Pin.getCPtr(pin), pin);
  }

 	/**
	 * Write a file to the card
	 * Throw PTEID_ExCmdNotAllowed exception you're not allowed to write the file
	 *
	 * If no pin is passed and a pin is needed by the card, the pin code will be asked anyway
	 *
	 * @param fileID is the path of the file
	 * @param out contents the bytes to write
	 */
  public boolean writeFile(String fileID, PTEID_ByteArray out) throws java.lang.Exception {
    return pteidlibJava_WrapperJNI.PTEID_SmartCard_writeFile__SWIG_2(swigCPtr, this, fileID, PTEID_ByteArray.getCPtr(out), out);
  }
	/** Return the number of pins on the card */
  public long pinCount() throws java.lang.Exception {
    return pteidlibJava_WrapperJNI.PTEID_SmartCard_pinCount(swigCPtr, this);
  }
	/** Return an object to access all the pins on the card */
  public PTEID_Pins getPins() throws java.lang.Exception {
    return new PTEID_Pins(pteidlibJava_WrapperJNI.PTEID_SmartCard_getPins(swigCPtr, this), false);
  }

	/** Return the number of certificates on the card */
  public long certificateCount() throws java.lang.Exception {
    return pteidlibJava_WrapperJNI.PTEID_SmartCard_certificateCount(swigCPtr, this);
  }
	/** Return an object to access all the certificates on the card */
  public PTEID_Certificates getCertificates() throws java.lang.Exception {
    return new PTEID_Certificates(pteidlibJava_WrapperJNI.PTEID_SmartCard_getCertificates(swigCPtr, this), false);
  }

	/**
	  * Get the challenge
	  *
	  * @param bForceNewInit force a new initialization of the couple challenge/response
	  */
  public PTEID_ByteArray getChallenge(boolean bForceNewInit) throws java.lang.Exception {
    return new PTEID_ByteArray(pteidlibJava_WrapperJNI.PTEID_SmartCard_getChallenge__SWIG_0(swigCPtr, this, bForceNewInit), false);
  }

	/**
	  * Get the challenge
	  */
  public PTEID_ByteArray getChallenge() throws java.lang.Exception {
    return new PTEID_ByteArray(pteidlibJava_WrapperJNI.PTEID_SmartCard_getChallenge__SWIG_1(swigCPtr, this), false);
  }

	/** Get the response to the challenge */
	public PTEID_ByteArray getChallengeResponse() throws java.lang.Exception {
    return new PTEID_ByteArray(pteidlibJava_WrapperJNI.PTEID_SmartCard_getChallengeResponse(swigCPtr, this), false);
  }

	/**
	  * Verify the challenge-response
	  *
	  * @param challenge is the challenge to check
	  * @param response is the response expected from the card
	  * @return true if the response of the card to the given challenge is the same as the response expected
	  * For virtual cards (=from file), always return false
	  */
  public boolean verifyChallengeResponse(PTEID_ByteArray challenge, PTEID_ByteArray response) throws java.lang.Exception {
    return pteidlibJava_WrapperJNI.PTEID_SmartCard_verifyChallengeResponse(swigCPtr, this, PTEID_ByteArray.getCPtr(challenge), challenge, PTEID_ByteArray.getCPtr(response), response);
  }

}
