unit uemUser; //uemUser3rd

interface

uses Windows, SysUtils, Classes, Math, Forms,
     uemTypes, uemBase;

const kb_device_name          = 'smart-card';     

type TEGMUser = class(TEGMBase)
  private

  protected
  public
		constructor create;
		destructor  destroy; //override;

    function  connect_applet(mode: boolean): boolean;
  published
end;

var  egtbuf:             string = ''; //Temporary buffer for encode/decode
     egtidx:             dword;       //Temporary index
     e:                  TEGMUser;
     sw:                 word = 0;
     box_found:          boolean = false;

implementation

constructor TEGMUser.create;
begin
  inherited create;
end;

destructor TEGMUser.destroy;
begin
  inherited destroy;
end;

function TEGMUser.connect_applet(mode: boolean): boolean;
begin
  result := false;

  if not self.SysInit then exit;

  if mode then
  begin
    if (not self.connected) then //check for aid1
    begin
      if boolean(self.connect('', self.RequiredCardAID)) then self.apdu_SelectAID(self.RequiredCardAID);
    end;

    if (not self.connected) and (kb_access_module[self.access_module_no].aid1 <> kb_access_module[self.access_module_no].aid2) then //check for aid2
    begin
      self.requiredCardAID := kb_access_module[self.access_module_no].aid2;
      if boolean(self.connect('', self.RequiredCardAID)) then self.apdu_SelectAID(self.RequiredCardAID);
      if self.connected then self.msg(kb_device_name + ': connected to reader #2');
    end;

    result := self.connected;
    if result then
    begin
      self.msg(kb_device_name + ': connected');
      self.Configure;
    end
    else
    begin
      self.msg(kb_device_name + ': can not be found/connected');
    end;
   end
  else
  begin
    self.disconnect;
    result := not self.connected;
    if result then self.msg(kb_device_name + ': disconnected');
  end;
end;

initialization

finalization

end.
