<commit_before>/*
 * To the extent possible under law, contributors have waived all
 * copyright and related or neighboring rights to work.
 */
package jnasmartcardio;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import com.sun.jna.NativeLong;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import com.sun.jna.PointerType;
import com.sun.jna.Structure;
import com.sun.jna.ptr.ByReference;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.NativeLongByReference;


class Winscard {
	public static class Scope extends Structure implements Structure.ByValue {
		public int scope;
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("scope");
		}
	}
	// typedef LONG SCARDCONTEXT;
	public static class SCardContext extends Structure implements Structure.ByValue {
		public NativeLong context;
		public SCardContext(NativeLong nativeLong) {
			this.context = nativeLong;
		}
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("context");
		}
	}
	public static class SCardContextByReference extends ByReference {
		public SCardContextByReference() {super(NativeLong.SIZE);}
		public SCardContext getValue() {
			return new SCardContext(getPointer().getNativeLong(0));
		}
		public void setValue(SCardContext context) {
			getPointer().setNativeLong(0, context.context);
		}
	}
	public static class SCardHandle extends Structure implements Structure.ByValue {
		public NativeLong scard;
		public SCardHandle(NativeLong nativeLong) {this.scard = nativeLong;}
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("scard");
		}
	}
	public static class SCardHandleByReference extends ByReference {
		public SCardHandleByReference() {super(NativeLong.SIZE);}
		public SCardHandle getValue() {
			return new SCardHandle(getPointer().getNativeLong(0));
		}
		public void setValue(SCardHandle context) {
			getPointer().setNativeLong(0, context.scard);
		}
	}
	// typedef struct _SCARD_IO_REQUEST {
	//   uint32_t dwProtocol;    /**< Protocol identifier */
	//   uint32_t cbPciLength;   /**< Protocol Control Inf Length */
	// }
	public static class ScardIoRequest extends PointerType {
		public ScardIoRequest() {super();}
		public ScardIoRequest(Pointer p) {super(p);}
	}

	/**
	 * Interface to wrap the particular SCARD_READERSTATE declaration on the
	 * platform. Unfortunately, each platform has a different type:
	 * 
	 * <ul>
	 * <li>Windows has extra padding after rgbAtr, so that the structure is
	 * aligned at word boundaries even when it is in an array
	 * SCARD_READERSTATE[]
	 * <li>OSX has no extra padding around rgbAtr, so that array elements are
	 * not word-aligned.
	 * <li>Linux pcsclite has no extra padding around rgbAtr. In addition, DWORD
	 * is typedef'd to long instead of int.
	 * </ul>
	 */
	public interface SCardReaderState {
		public void setReaderName(String szReader);
		public String getReaderName();
		public void setCurrentState(int dwCurrentState);
		public int getCurrentState();
		public void setEventState(int dwEventState);
		public int getEventState();
		public void toArray(SCardReaderState[] array);
		public int getAtrLength();
		public void setAtrLength(int cbAtr);
		public byte[] getAtrArray();
	}
	/**
	 * On Windows, SCardReaderState is explicitly aligned to word boundaries.
	 * 
	 * <p>
	 * sizeof(SCARD_READERSTATE_A):<br>
	 * windows x86: 4+4+4+4+4+36 = 56<br>
	 * windows x64: 8+8+4+4+4+36 = 64
	 */
	public static class WinscardSCardReaderState extends Structure implements SCardReaderState {
		// const char *szReader;
		public String szReader;
		// void *pvUserData;
		public Pointer pvUserData;
		// uint32_t dwCurrentState;
		public int dwCurrentState;
		// uint32_t dwEventState;
		public int dwEventState;
		// uint32_t cbAtr;
		public int cbAtr;
		public byte[] rgbAtr = new byte[WinscardConstants.MAX_ATR_SIZE];
		protected WinscardSCardReaderState(int align){super(align);}
		public WinscardSCardReaderState(){super(); assert this.size() == Pointer.SIZE * 2 + 12 + 36;}
		public WinscardSCardReaderState(String szReader) {this(); this.szReader = szReader;}
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("szReader", "pvUserData", "dwCurrentState", "dwEventState", "cbAtr", "rgbAtr");
		}
		@Override public void setReaderName(String szReader) { this.szReader = szReader; }
		@Override public String getReaderName() {return this.szReader;}
		@Override public void setCurrentState(int dwCurrentState) {this.dwCurrentState = (int) dwCurrentState;}
		@Override public int getCurrentState() {return this.dwCurrentState;}
		@Override public void setEventState(int dwEventState) {this.dwEventState = (int) dwEventState;}
		@Override public int getEventState() {return this.dwEventState;}
		@Override public void toArray(SCardReaderState[] array) {super.toArray((Structure[])array);}
		@Override public int getAtrLength() {return cbAtr;}
		@Override public void setAtrLength(int cbAtr) {this.cbAtr = cbAtr;}
		@Override public byte[] getAtrArray() {return this.rgbAtr;}
	}
	
	/**
	 * On OS X, the fields of SCardReaderState are the same size as Windows, but
	 * it is not aligned to word boundaries
	 * 
	 * <p>
	 * sizeof(SCARD_READERSTATE_A):<br>
	 * osx x86: 4+4+4+4+4+33 = 53<br>
	 * osx x64: 8+8+4+4+4+33 = 61
	 */
	public static class OSXSCardReaderState extends WinscardSCardReaderState {
		public OSXSCardReaderState(){super(ALIGN_NONE); assert this.size() == Pointer.SIZE * 2 + 12 + 33;}
		public OSXSCardReaderState(String szReader) {this(); this.szReader = szReader;}
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("szReader", "pvUserData", "dwCurrentState", "dwEventState", "cbAtr", "rgbAtr");
		}
	}
	
	/**
	 * On Linux, the fields are long, and SCardReaderState is not aligned to
	 * word boundaries
	 * 
	 * <p>
	 * sizeof(SCARD_READERSTATE_A):<br>
	 * linux x86: 4+4+4+4+4+33 = 53<br>
	 * linux x64: 8+8+8+8+8+36 = 76
	 */
	public static class LinuxSCardReaderState extends Structure implements SCardReaderState {
		// const char *szReader;
		public String szReader;
		// void *pvUserData;
		public Pointer pvUserData;
		// DWORD dwCurrentState;
		public NativeLong dwCurrentState;
		// DWORD dwEventState;
		public NativeLong dwEventState;
		// DWORD cbAtr;
		public NativeLong cbAtr;
		public byte[] rgbAtr = new byte[WinscardConstants.MAX_ATR_SIZE];
		public LinuxSCardReaderState(){super(ALIGN_NONE); assert this.size() == Pointer.SIZE * 2 + NativeLong.SIZE * 3 + 33;}
		public LinuxSCardReaderState(String szReader) {this(); this.szReader = szReader;}
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("szReader", "pvUserData", "dwCurrentState", "dwEventState", "cbAtr", "rgbAtr");
		}
		@Override public void setReaderName(String szReader) { this.szReader = szReader; }
		@Override public String getReaderName() {return this.szReader;}
		@Override public void setCurrentState(int dwCurrentState) {this.dwCurrentState = new NativeLong(0xffffffffl & dwCurrentState);}
		@Override public int getCurrentState() {return this.dwCurrentState == null ? 0 : (int)this.dwCurrentState.longValue();}
		@Override public void setEventState(int dwEventState) {this.dwEventState = new NativeLong(0xffffffffl & dwEventState);}
		@Override public int getEventState() {return this.dwEventState == null ? 0 : (int)this.dwEventState.longValue();}
		@Override public void toArray(SCardReaderState[] array) {super.toArray((Structure[])array);}
		@Override public int getAtrLength() {return cbAtr == null ? 0 : cbAtr.intValue();}
		@Override public void setAtrLength(int cbAtr) {this.cbAtr = new NativeLong(cbAtr);}
		@Override public byte[] getAtrArray() {return this.rgbAtr;}
	}
	public static final String WINDOWS_PATH = "WinSCard.dll";
	public static final String MAC_PATH = "/System/Library/Frameworks/PCSC.framework/PCSC";
	public static final String PCSC_PATH = "pcsc";

	/**
	 * The winscard API, used on Windows. OS X also uses the same declarations;
	 * they forked PCSC but made sure the declarations are the same as Windows.
	 */
	public interface WinscardLibrary extends Library {
		// LONG SCardEstablishContext (DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
		NativeLong SCardEstablishContext (int dwScope, Pointer pvReserved1, Pointer pvReserved2, SCardContextByReference phContext);
		// LONG 	SCardReleaseContext (SCARDCONTEXT hContext)
		NativeLong SCardReleaseContext(SCardContext hContext);
		// LONG 	SCardConnect (SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol)
		NativeLong SCardConnect(SCardContext hContext, String szReader, int dwSharMode, int dwPreferredProtocols, SCardHandleByReference phCard, IntByReference pdwActiveProtocol);
		// LONG 	SCardReconnect (SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol)
		NativeLong SCardReconnect(SCardHandle hCard, int dwShareMode, int dwPreferredProtocols, int dwInitialization, IntByReference pdwActiveProtocol);
		// LONG 	SCardDisconnect (SCARDHANDLE hCard, DWORD dwDisposition)<commit_msg>Use the correct library name on Linux (libpcsclite.so.1).<commit_after>/*
 * To the extent possible under law, contributors have waived all
 * copyright and related or neighboring rights to work.
 */
package jnasmartcardio;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import com.sun.jna.NativeLong;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import com.sun.jna.PointerType;
import com.sun.jna.Structure;
import com.sun.jna.ptr.ByReference;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.NativeLongByReference;


class Winscard {
	public static class Scope extends Structure implements Structure.ByValue {
		public int scope;
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("scope");
		}
	}
	// typedef LONG SCARDCONTEXT;
	public static class SCardContext extends Structure implements Structure.ByValue {
		public NativeLong context;
		public SCardContext(NativeLong nativeLong) {
			this.context = nativeLong;
		}
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("context");
		}
	}
	public static class SCardContextByReference extends ByReference {
		public SCardContextByReference() {super(NativeLong.SIZE);}
		public SCardContext getValue() {
			return new SCardContext(getPointer().getNativeLong(0));
		}
		public void setValue(SCardContext context) {
			getPointer().setNativeLong(0, context.context);
		}
	}
	public static class SCardHandle extends Structure implements Structure.ByValue {
		public NativeLong scard;
		public SCardHandle(NativeLong nativeLong) {this.scard = nativeLong;}
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("scard");
		}
	}
	public static class SCardHandleByReference extends ByReference {
		public SCardHandleByReference() {super(NativeLong.SIZE);}
		public SCardHandle getValue() {
			return new SCardHandle(getPointer().getNativeLong(0));
		}
		public void setValue(SCardHandle context) {
			getPointer().setNativeLong(0, context.scard);
		}
	}
	// typedef struct _SCARD_IO_REQUEST {
	//   uint32_t dwProtocol;    /**< Protocol identifier */
	//   uint32_t cbPciLength;   /**< Protocol Control Inf Length */
	// }
	public static class ScardIoRequest extends PointerType {
		public ScardIoRequest() {super();}
		public ScardIoRequest(Pointer p) {super(p);}
	}

	/**
	 * Interface to wrap the particular SCARD_READERSTATE declaration on the
	 * platform. Unfortunately, each platform has a different type:
	 * 
	 * <ul>
	 * <li>Windows has extra padding after rgbAtr, so that the structure is
	 * aligned at word boundaries even when it is in an array
	 * SCARD_READERSTATE[]
	 * <li>OSX has no extra padding around rgbAtr, so that array elements are
	 * not word-aligned.
	 * <li>Linux pcsclite has no extra padding around rgbAtr. In addition, DWORD
	 * is typedef'd to long instead of int.
	 * </ul>
	 */
	public interface SCardReaderState {
		public void setReaderName(String szReader);
		public String getReaderName();
		public void setCurrentState(int dwCurrentState);
		public int getCurrentState();
		public void setEventState(int dwEventState);
		public int getEventState();
		public void toArray(SCardReaderState[] array);
		public int getAtrLength();
		public void setAtrLength(int cbAtr);
		public byte[] getAtrArray();
	}
	/**
	 * On Windows, SCardReaderState is explicitly aligned to word boundaries.
	 * 
	 * <p>
	 * sizeof(SCARD_READERSTATE_A):<br>
	 * windows x86: 4+4+4+4+4+36 = 56<br>
	 * windows x64: 8+8+4+4+4+36 = 64
	 */
	public static class WinscardSCardReaderState extends Structure implements SCardReaderState {
		// const char *szReader;
		public String szReader;
		// void *pvUserData;
		public Pointer pvUserData;
		// uint32_t dwCurrentState;
		public int dwCurrentState;
		// uint32_t dwEventState;
		public int dwEventState;
		// uint32_t cbAtr;
		public int cbAtr;
		public byte[] rgbAtr = new byte[WinscardConstants.MAX_ATR_SIZE];
		protected WinscardSCardReaderState(int align){super(align);}
		public WinscardSCardReaderState(){super(); assert this.size() == Pointer.SIZE * 2 + 12 + 36;}
		public WinscardSCardReaderState(String szReader) {this(); this.szReader = szReader;}
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("szReader", "pvUserData", "dwCurrentState", "dwEventState", "cbAtr", "rgbAtr");
		}
		@Override public void setReaderName(String szReader) { this.szReader = szReader; }
		@Override public String getReaderName() {return this.szReader;}
		@Override public void setCurrentState(int dwCurrentState) {this.dwCurrentState = (int) dwCurrentState;}
		@Override public int getCurrentState() {return this.dwCurrentState;}
		@Override public void setEventState(int dwEventState) {this.dwEventState = (int) dwEventState;}
		@Override public int getEventState() {return this.dwEventState;}
		@Override public void toArray(SCardReaderState[] array) {super.toArray((Structure[])array);}
		@Override public int getAtrLength() {return cbAtr;}
		@Override public void setAtrLength(int cbAtr) {this.cbAtr = cbAtr;}
		@Override public byte[] getAtrArray() {return this.rgbAtr;}
	}
	
	/**
	 * On OS X, the fields of SCardReaderState are the same size as Windows, but
	 * it is not aligned to word boundaries
	 * 
	 * <p>
	 * sizeof(SCARD_READERSTATE_A):<br>
	 * osx x86: 4+4+4+4+4+33 = 53<br>
	 * osx x64: 8+8+4+4+4+33 = 61
	 */
	public static class OSXSCardReaderState extends WinscardSCardReaderState {
		public OSXSCardReaderState(){super(ALIGN_NONE); assert this.size() == Pointer.SIZE * 2 + 12 + 33;}
		public OSXSCardReaderState(String szReader) {this(); this.szReader = szReader;}
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("szReader", "pvUserData", "dwCurrentState", "dwEventState", "cbAtr", "rgbAtr");
		}
	}
	
	/**
	 * On Linux, the fields are long, and SCardReaderState is not aligned to
	 * word boundaries
	 * 
	 * <p>
	 * sizeof(SCARD_READERSTATE_A):<br>
	 * linux x86: 4+4+4+4+4+33 = 53<br>
	 * linux x64: 8+8+8+8+8+36 = 76
	 */
	public static class LinuxSCardReaderState extends Structure implements SCardReaderState {
		// const char *szReader;
		public String szReader;
		// void *pvUserData;
		public Pointer pvUserData;
		// DWORD dwCurrentState;
		public NativeLong dwCurrentState;
		// DWORD dwEventState;
		public NativeLong dwEventState;
		// DWORD cbAtr;
		public NativeLong cbAtr;
		public byte[] rgbAtr = new byte[WinscardConstants.MAX_ATR_SIZE];
		public LinuxSCardReaderState(){super(ALIGN_NONE); assert this.size() == Pointer.SIZE * 2 + NativeLong.SIZE * 3 + 33;}
		public LinuxSCardReaderState(String szReader) {this(); this.szReader = szReader;}
		@Override protected List<String> getFieldOrder() {
			return Arrays.asList("szReader", "pvUserData", "dwCurrentState", "dwEventState", "cbAtr", "rgbAtr");
		}
		@Override public void setReaderName(String szReader) { this.szReader = szReader; }
		@Override public String getReaderName() {return this.szReader;}
		@Override public void setCurrentState(int dwCurrentState) {this.dwCurrentState = new NativeLong(0xffffffffl & dwCurrentState);}
		@Override public int getCurrentState() {return this.dwCurrentState == null ? 0 : (int)this.dwCurrentState.longValue();}
		@Override public void setEventState(int dwEventState) {this.dwEventState = new NativeLong(0xffffffffl & dwEventState);}
		@Override public int getEventState() {return this.dwEventState == null ? 0 : (int)this.dwEventState.longValue();}
		@Override public void toArray(SCardReaderState[] array) {super.toArray((Structure[])array);}
		@Override public int getAtrLength() {return cbAtr == null ? 0 : cbAtr.intValue();}
		@Override public void setAtrLength(int cbAtr) {this.cbAtr = new NativeLong(cbAtr);}
		@Override public byte[] getAtrArray() {return this.rgbAtr;}
	}
	public static final String WINDOWS_PATH = "WinSCard.dll";
	public static final String MAC_PATH = "/System/Library/Frameworks/PCSC.framework/PCSC";
	public static final String PCSC_PATH = "libpcsclite.so.1";

	/**
	 * The winscard API, used on Windows. OS X also uses the same declarations;
	 * they forked PCSC but made sure the declarations are the same as Windows.
	 */
	public interface WinscardLibrary extends Library {
		// LONG SCardEstablishContext (DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
		NativeLong SCardEstablishContext (int dwScope, Pointer pvReserved1, Pointer pvReserved2, SCardContextByReference phContext);
		// LONG 	SCardReleaseContext (SCARDCONTEXT hContext)
		NativeLong SCardReleaseContext(SCardContext hContext);
		// LONG 	SCardConnect (SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol)
		NativeLong SCardConnect(SCardContext hContext, String szReader, int dwSharMode, int dwPreferredProtocols, SCardHandleByReference phCard, IntByReference pdwActiveProtocol);
		// LONG 	SCardReconnect (SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol)
		NativeLong SCardReconnect(SCardHandle hCard, int dwShareMode, int dwPreferredProtocols, int dwInitialization, IntByReference pdwActiveProtocol);
		// LONG 	SCardDisconnect (SCARDHANDLE hCard, DWORD dwDisposition)
{'fraction_non_alphanumeric': 0.10354497354497355, 'fraction_numerical': 0.011005291005291006, 'mean_word_length': 5.150667100553205, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7380476', 'n_tokens_mistral': 6329, 'n_tokens_neox': 5799, 'n_words': 1634}