Code:
{******************************************************************}
{ }
{ Borland Delphi Runtime Library }
{ Celik interface unit }
{ }
{ The original file is: CelikApi.h }
{ The original Pascal code is: CelikApi.pas }
{ The initial developer of the Pascal code is Davor Nikolic }
{ (
[email protected]). }
{ }
{ h. file obtained through: }
{ MUP RS official site }
{ }
{ The contents of this file are used with permission, subject to }
{ the Mozilla Public License Version 1.1 (the "License"); you may }
{ not use this file except in compliance with the License. You may }
{ obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
{ implied. See the License for the specific language governing }
{ rights and limitations under the License. }
{ }
{******************************************************************}
unit CelikApi;
interface
uses
Windows;
{$IFDEF CelikApi_LINKONREQUEST}
{$DEFINE CelikApi_DYNLINK}
{$ENDIF}
// Constants
const
// Option identifiers, used in function EidSetOption
EID_O_KEEP_CARD_CLOSED: Integer = 1;
// Certificate types, used in function EidReadCertificate
EID_Cert_MoiIntermediateCA: Integer = 1;
EID_Cert_User1: Integer = 2;
EID_Cert_User2: Integer = 3;
// Block types, used in function EidVerifySignature
EID_SIG_CARD: Integer = 1;
EID_SIG_FIXED: Integer = 2;
EID_SIG_VARIABLE: Integer = 3;
EID_SIG_PORTRAIT: Integer = 4;
// For new card version EidVerifySignature function will return EID_E_UNABLE_TO_EXECUTE for
// parameter EID_SIG_PORTRAIT. Portrait is in new cards part of EID_SIG_FIXED. To determine
// the card version use second parameter of function EidBeginRead
// Function return values
EID_OK: Integer = 0;
EID_E_GENERAL_ERROR: Integer = -1;
EID_E_INVALID_PARAMETER: Integer = -2;
EID_E_VERSION_NOT_SUPPORTED: Integer = -3;
EID_E_NOT_INITIALIZED: Integer = -4;
EID_E_UNABLE_TO_EXECUTE: Integer = -5;
EID_E_READER_ERROR: Integer = -6;
EID_E_CARD_MISSING: Integer = -7;
EID_E_CARD_UNKNOWN: Integer = -8;
EID_E_CARD_MISMATCH: Integer = -9;
EID_E_UNABLE_TO_OPEN_SESSION: Integer = -10;
EID_E_DATA_MISSING: Integer = -11;
EID_E_CARD_SECFORMAT_CHECK_ERROR: Integer = -12;
EID_E_SECFORMAT_CHECK_CERT_ERROR: Integer = -13;
EID_E_INVALID_PASSWORD: Integer = -14;
EID_E_PIN_BLOCKED: Integer = -15;
// Structures
// NOTE: char arrays DO NOT have zero char at the end
type
PEID_DOCUMENT_DATA = ^EID_DOCUMENT_DATA;
EID_DOCUMENT_DATA = record
docRegNo: array[0..8] of AnsiChar;
docRegNoSize: Integer;
documentType: array[0..1] of AnsiChar;
documentTypeSize: Integer;
issuingDate: array[0..9] of AnsiChar;
issuingDateSize: Integer;
expiryDate: array[0..9] of AnsiChar;
expiryDateSize: Integer;
issuingAuthority: array[0..99] of AnsiChar;
issuingAuthoritySize: Integer;
end;
type
PEID_FIXED_PERSONAL_DATA = ^EID_FIXED_PERSONAL_DATA;
EID_FIXED_PERSONAL_DATA = record
personalNumber: array[0..12] of AnsiChar;
personalNumberSize: Integer;
surname: array[0..199] of AnsiChar;
surnameSize: Integer;
givenName: array[0..199] of AnsiChar;
givenNameSize: Integer;
parentGivenName: array[0..199] of AnsiChar;
parentGivenNameSize: Integer;
sex: array[0..1] of AnsiChar;
sexSize: Integer;
placeOfBirth: array[0..199] of AnsiChar;
placeOfBirthSize: Integer;
stateOfBirth: array[0..199] of AnsiChar;
stateOfBirthSize: Integer;
dateOfBirth: array[0..9] of AnsiChar;
dateOfBirthSize: Integer;
communityOfBirth: array[0..199] of AnsiChar;
communityOfBirthSize: Integer;
end;
type
PEID_VARIABLE_PERSONAL_DATA = ^EID_VARIABLE_PERSONAL_DATA;
EID_VARIABLE_PERSONAL_DATA = record
state: array[0..99] of AnsiChar;
stateSize: Integer;
community: array[0..199] of AnsiChar;
communitySize: Integer;
place: array[0..199] of AnsiChar;
placeSize: Integer;
street: array[0..199] of AnsiChar;
streetSize: Integer;
houseNumber: array[0..19] of AnsiChar;
houseNumberSize: Integer;
houseLetter: array[0..7] of AnsiChar;
houseLetterSize: Integer;
entrance: array[0..9] of AnsiChar;
entranceSize: Integer;
floor: array[0..5] of AnsiChar;
floorSize: Integer;
apartmentNumber: array[0..11] of AnsiChar;
apartmentNumberSize: Integer;
addressDate: array[0..9] of AnsiChar;
addressDateSize: Integer;
addressLabel: array[0..59] of AnsiChar;
addressLabelSize: Integer;
end;
type
PEID_PORTRAIT = ^EID_PORTRAIT;
EID_PORTRAIT = record
portrait: array[0..7699] of Byte;
portraitSize: Integer;
end;
type
PEID_CERTIFICATE = ^EID_CERTIFICATE;
EID_CERTIFICATE = record
certificate: array[0..2047] of Byte;
certificateSize: Integer;
end;
// Functions
{$IFDEF CelikApi_DYNLINK}
TEidSetOption = function(nOptionID: Integer; nOptionValue: UINT_PTR): Integer; stdcall;
TEidStartup = function(nApiVersion: Integer): Integer; stdcall;
TEidCleanup = function: Integer; stdcall;
TEidBeginRead = function(const szReader: PAnsiChar; pnCardVersion: PInteger = nil): Integer; stdcall;
TEidEndRead = function: Integer; stdcall;
TEidReadDocumentData = function(var pData: EID_DOCUMENT_DATA): Integer; stdcall;
TEidReadFixedPersonalData = function(var pData: EID_FIXED_PERSONAL_DATA): Integer; stdcall;
TEidReadVariablePersonalData = function(var pData: EID_VARIABLE_PERSONAL_DATA): Integer; stdcall;
TEidReadPortrait = function(var pData: EID_PORTRAIT): Integer; stdcall;
TEidReadCertificate = function(var pData: EID_CERTIFICATE; certificateType: Integer): Integer; stdcall;
TEidChangePassword = function(const szOldPassword: PAnsiChar; const szNewPassword: PAnsiChar; var pnTriesLeft: Integer): Integer; stdcall;
TEidVerifySignature = function(nSignatureID: UINT): Integer; stdcall;
{$ELSE}
function EidSetOption(nOptionID: Integer; nOptionValue: UINT_PTR): Integer; stdcall;
function EidStartup(nApiVersion: Integer): Integer; stdcall;
function EidCleanup: Integer; stdcall;
function EidBeginRead(const szReader: PAnsiChar; pnCardVersion: PInteger = nil): Integer; stdcall;
function EidEndRead: Integer; stdcall;
function EidReadDocumentData(var pData: EID_DOCUMENT_DATA): Integer; stdcall;
function EidReadFixedPersonalData(var pData: EID_FIXED_PERSONAL_DATA): Integer; stdcall;
function EidReadVariablePersonalData(var pData: EID_VARIABLE_PERSONAL_DATA): Integer; stdcall;
function EidReadPortrait(var pData: EID_PORTRAIT): Integer; stdcall;
function EidReadCertificate(var pData: EID_CERTIFICATE; certificateType: Integer): Integer; stdcall;
function EidChangePassword(const szOldPassword: PAnsiChar; const szNewPassword: PAnsiChar; var pnTriesLeft: Integer): Integer; stdcall;
function EidVerifySignature(nSignatureID: UINT): Integer; stdcall;
{$ENDIF}
{$IFDEF CelikApi_DYNLINK}
var
EidSetOption: TEidSetOption = nil;
EidStartup: TEidStartup = nil;
EidCleanup: TEidCleanup = nil;
EidBeginRead: TEidBeginRead = nil;
EidEndRead: TEidEndRead = nil;
EidReadDocumentData: TEidReadDocumentData = nil;
EidReadFixedPersonalData: TEidReadFixedPersonalData = nil;
EidReadVariablePersonalData: TEidReadVariablePersonalData = nil;
EidReadPortrait: TEidReadPortrait = nil;
EidReadCertificate: TEidReadCertificate = nil;
EidChangePassword: TEidChangePassword = nil;
EidVerifySignature: TEidVerifySignature = nil;
bPCSCLoaded: Boolean;
hCelikApiDLL: THandle;
{ load PC/SC DLL, pass variable for handle to unload DLL later }
function PCSCLoadDLL: Boolean;
{$EXTERNALSYM PCSCLoadDLL}
procedure PCSCUnloadDLL;
{$EXTERNALSYM PCSCUnloadDLL}
{$ENDIF}
implementation
{$IFDEF CelikApi_DYNLINK}
procedure PCSCUnloadDLL;
begin
if hCelikApiDLL <> 0 then
FreeLibrary(hCelikApiDLL);
end;
function PCSCLoadDLL: Boolean;
begin
if hCelikApiDLL = 0 then
hCelikApiDLL := LoadLibrary('CelikApi.dll');
if hCelikApiDLL = 0 then
begin
Result := False;
Exit;
end;
@EidSetOption := GetProcAddress(hCelikApiDLL, 'EidSetOption');
@EidStartup := GetProcAddress(hCelikApiDLL, 'EidStartup');
@EidCleanup := GetProcAddress(hCelikApiDLL, 'EidCleanup');
@EidBeginRead := GetProcAddress(hCelikApiDLL, 'EidBeginRead');
@EidEndRead := GetProcAddress(hCelikApiDLL, 'EidEndRead');
@EidReadDocumentData := GetProcAddress(hCelikApiDLL, 'EidReadDocumentData');
@EidReadFixedPersonalData := GetProcAddress(hCelikApiDLL, 'EidReadFixedPersonalData');
@EidReadVariablePersonalData := GetProcAddress(hCelikApiDLL, 'EidReadVariablePersonalData');
@EidReadPortrait := GetProcAddress(hCelikApiDLL, 'EidReadPortrait');
@EidReadCertificate := GetProcAddress(hCelikApiDLL, 'EidReadCertificate');
@EidChangePassword := GetProcAddress(hCelikApiDLL, 'EidChangePassword');
@EidVerifySignature := GetProcAddress(hCelikApiDLL, 'EidVerifySignature');
Result := True;
end;
{$ELSE}
const
CelikApiDLL = 'CelikApi.dll';
function EidSetOption; external CelikApiDLL name 'EidSetOption';
function EidStartup; external CelikApiDLL name 'EidStartup';
function EidCleanup; external CelikApiDLL name 'EidCleanup';
function EidBeginRead; external CelikApiDLL name 'EidBeginRead';
function EidEndRead; external CelikApiDLL name 'EidEndRead';
function EidReadDocumentData; external CelikApiDLL name 'EidReadDocumentData';
function EidReadFixedPersonalData; external CelikApiDLL name 'EidReadFixedPersonalData';
function EidReadVariablePersonalData; external CelikApiDLL name 'EidReadVariablePersonalData';
function EidReadPortrait; external CelikApiDLL name 'EidReadPortrait';
function EidReadCertificate; external CelikApiDLL name 'EidReadCertificate';
function EidChangePassword; external CelikApiDLL name 'EidChangePassword';
function EidVerifySignature; external CelikApiDLL name 'EidVerifySignature';
{$ENDIF}
{$IFDEF CelikApi_DYNLINK}
initialization
bPCSCLoaded := PCSCLoadDLL;
finalization
PCSCUnloadDll;
{$ENDIF}
end.