### C# Basic PC/SC Smart Card Communication Source: https://github.com/wsct/wsct-core/blob/master/docs/articles/intro.html This C# example demonstrates fundamental operations for interacting with smart cards via PC/SC. It covers establishing a PC/SC context, listing available readers, connecting to an ISO7816-4 compliant card, sending an APDU (Application Protocol Data Unit) command, and properly disconnecting from the card and PC/SC subsystem. ```C# // Connect to PC/SC var context = new CardContext(); context.Establish(); // Get installed readers context.ListReaders(""); var allReaders = context.Readers; // Connect to an ISO7816-4 card in the last reader found var rawChannel = new CardChannel(context, context.Readers.Last()); var channel = new CardChannelIso7816(rawChannel); channel.Connect(ShareMode.Exclusive, Protocol.Any); // Build a SELECT command var capdu = new SelectCommand( SelectCommand.SelectionMode.SelectDFName, SelectCommand.FileOccurrence.FirstOrOnly, SelectCommand.FileControlInformation.ReturnFci, "A0 00 00 01 51".FromHexa() ); // Send it in a CRP an get the response back var crp = new CommandResponsePair(capdu); crp.Transmit(channel); var rapdu = crp.RApdu; // Unpower the card channel.Disconnect(Disposition.UnpowerCard); // Disconnect from PC/SC context.Release(); ``` -------------------------------- ### Prototyping Smart Card Communication with WSCT.Core.Fluent Extensions Source: https://github.com/wsct/wsct-core/blob/master/README.md This C# example showcases the use of fluent extension methods from WSCT.Core.Fluent.Helpers to simplify and chain operations for connecting to PC/SC, listing readers, transmitting APDU commands, and handling responses with error checking, all within a try-finally block for proper resource disposal. ```csharp CardContext? cardContext = null; CardChannel? cardChannel = null; try { // Connect to PC/SC cardContext = new new CardContext(); cardContext .Establish() .ThrowIfNotSuccess(); cardContext .ListReaderGroups() .ThrowIfNotSuccess(); cardContext .ListReaders(cardContext.Groups[0]) .ThrowIfNotSuccess(); cardChannel = new CardChannel(cardContext, cardContext.Readers[0]); new CommandAPDU("00 A4 04 00 07 F0 57 53 43 54 2E 30") .Transmit(cardChannel) .ThrowIfNotSuccess() .ThrowIfSWNot9000() .If(r => r.Sw1 == 0x61, (c, r) => Console.WriteLine($"{r.Sw2} bytes are waiting to be retrieved")); new CommandAPDU("00 C0 00 00 08") .Transmit(cardChannel) .ThrowIfNotSuccess() .ThrowIfSWNot9000(); } finally { cardChannel? .Disconnect(Disposition.UnpowerCard); cardContext? .Release(); } ``` -------------------------------- ### Connect to PC/SC and Transmit APDU with WSCT.Core Source: https://github.com/wsct/wsct-core/blob/master/README.md This C# example demonstrates how to establish a connection to a PC/SC smart card reader, list available readers, connect to an ISO7816-4 card, build and transmit a SELECT APDU command, and then disconnect from the card and PC/SC context. ```csharp // Connect to PC/SC var context = new CardContext(); context.Establish(); // Get installed readers context.ListReaders(""); var allReaders = context.Readers; // Connect to an ISO7816-4 card in the last reader found var channel = new CardChannel(context, context.Readers.Last()); channel.Connect(ShareMode.Exclusive, Protocol.Any); // Build a SELECT command var capdu = new SelectCommand( SelectCommand.SelectionMode.SelectDFName, SelectCommand.FileOccurrence.FirstOrOnly, SelectCommand.FileControlInformation.ReturnFci, "A0 00 00 01 51".FromHexa() ); // Send it in a CRP an get the response back var crp = new CommandResponsePair(capdu); crp.Transmit(channel); var rapdu = crp.RApdu; // Unpower the card channel.Disconnect(Disposition.UnpowerCard); // Disconnect from PC/SC context.Release(); ``` -------------------------------- ### Initialize CardContext and CardChannel in C# Source: https://github.com/wsct/wsct-core/blob/master/docs/index.html This example demonstrates how to initialize `CardContext` and `CardChannel` objects using the `WSCT.Wrapper.Desktop.Core` namespace, which provides concrete implementations for `ICardContext` and `ICardChannel` observables. ```C# using WSCT.Wrapper.Desktop.Core; var context = new CardContext(); // ... var cardChannel = new CardChannel(context, "Some reader name"); // ... ``` -------------------------------- ### Connect to PC/SC and Interact with an ISO7816-4 Card in C# Source: https://github.com/wsct/wsct-core/blob/master/WSCT.DocFx/articles/intro.md This C# code snippet demonstrates the complete lifecycle of interacting with a smart card via PC/SC. It initializes a card context, enumerates available readers, connects to an ISO7816-4 compliant card on the last found reader, constructs and transmits a SELECT APDU command, processes the response, and finally disconnects from the card and releases the PC/SC context. ```csharp // Connect to PC/SC var context = new CardContext(); context.Establish(); // Get installed readers context.ListReaders(""); var allReaders = context.Readers; // Connect to an ISO7816-4 card in the last reader found var rawChannel = new CardChannel(context, context.Readers.Last()); var channel = new CardChannelIso7816(rawChannel); channel.Connect(ShareMode.Exclusive, Protocol.Any); // Build a SELECT command var capdu = new SelectCommand( SelectCommand.SelectionMode.SelectDFName, SelectCommand.FileOccurrence.FirstOrOnly, SelectCommand.FileControlInformation.ReturnFci, "A0 00 00 01 51".FromHexa() ); // Send it in a CRP an get the response back var crp = new CommandResponsePair(capdu); crp.Transmit(channel); var rapdu = crp.RApdu; // Unpower the card channel.Disconnect(Disposition.UnpowerCard); // Disconnect from PC/SC context.Release(); ``` -------------------------------- ### Instantiate WSCT CardContext and CardChannel for Desktop Source: https://github.com/wsct/wsct-core/blob/master/WSCT.DocFx/index.md This C# example demonstrates how to initialize `CardContext` and `CardChannel` objects using the `WSCT.Wrapper.Desktop.Core` namespace. These classes provide concrete, observable implementations of the core `ICardContext` and `ICardChannel` interfaces, facilitating interaction with smart card readers in desktop environments. Further operations would typically involve connecting to a specific reader and performing APDU exchanges. ```csharp using WSCT.Wrapper.Desktop.Core; var context = new CardContext(); // ... var cardChannel = new CardChannel(context, "Some reader name"); // ... ``` -------------------------------- ### Convert Single TlvData to XML String with Example Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvDataHelper.html Documents an API method that converts a single TlvData object into its XML string representation. Includes an example of usage and the resulting XML structure. ```APIDOC Method: ToXmlString Description: Converts a List into an XML representation System.String Declaration: public static string ToXmlString(this TlvData tlv) Parameters: tlv: WSCT.Helpers.BasicEncodingRules.TlvData - Source data to convert Returns: Type: System.String - A new string Remarks: TLVData tlv = "70 03 88 01 02".toTLVData(); string xmltlv = tlv.toXmlString(); // now xmltlv is // // // // // // ``` -------------------------------- ### C# Example: Convert BCD String to Digits with Length Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BytesHelpers.html This C# example demonstrates the `fromBcd` extension method, converting a string containing BCD digits into a new byte array, extracting only a specified number of digits. This is useful for partial conversions. ```C# string value = "1234567890"; byte[] data = value.fromBcd(7); // Now data = { 1, 2, 3, 4, 5, 6, 7 } ``` -------------------------------- ### WSCT.ISO7816.CommandAPDU Class API Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.ISO7816.CommandAPDU.html Detailed API documentation for the `CommandAPDU` class, including its constructors for various initialization scenarios and properties for accessing command components like CLA, INS, P1, P2, Lc, Le, and the full binary command. ```APIDOC WSCT.ISO7816.CommandAPDU Class Constructors: CommandAPDU(cla: System.Byte, ins: System.Byte, p1: System.Byte, p2: System.Byte, lc: System.UInt32, udc: System.Byte[], le: System.UInt32) Initializes a new instance for CC4 C-APDU. cla: CLA byte of the C-APDU. ins: INS byte of the C-APDU. p1: P1 byte of the C-APDU. p2: P2 byte of the C-APDU. lc: Lc value of the C-APDU. udc: UDC of the C-APDU. le: Le value of the C-APDU. CommandAPDU(cAPDU: System.Byte[]) Initializes a new instance for arbitrary C-APDU. cAPDU: C-APDU to be assigned as a byte array. CommandAPDU(cAPDU: System.String) Initializes a new instance for arbitrary C-APDU. cAPDU: C-APDU to be assigned as a string container (each byte is coded in hexa). Properties: BinaryCommand: System.Byte[] Accessor to the entire C-APDU in byte array format. Accessors: get Cla: System.Byte Accessor to the CLA byte of the C-APDU. Accessors: get, set CommandCase: System.Byte Accessors: get, set ``` ```C# public CommandAPDU(byte cla, byte ins, byte p1, byte p2, uint lc, byte[] udc, uint le) ``` ```C# public CommandAPDU(byte[] cAPDU) ``` ```C# public CommandAPDU(string cAPDU) ``` ```C# public byte[] BinaryCommand { get; } ``` ```C# public byte Cla { get; set; } ``` ```C# public byte CommandCase { get; set; } ``` -------------------------------- ### API Reference for WSCT.Wrapper.Desktop.Core Namespace Classes Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.Desktop.Core.html This section provides a structured overview of the classes available within the WSCT.Wrapper.Desktop.Core namespace, including their names and brief descriptions, outlining their roles in smartcard interaction and resource management. ```APIDOC Namespace: WSCT.Wrapper.Desktop.Core Classes: - CardChannel - CardChannelCore: Represents a basic object capable of managing access to a smartcard. - CardContext: Represents an enhanced CardContextCore allowing to observe activity by using delegates. - CardContextCore: Represents a basic object capable of managing smartcard resources. - OnCardInsertionEventArgs - OnCardRemovalEventArgs - StatusChangeMonitor: Object monitoring status change (see GetStatusChange(UInt32, AbstractReaderState[])). ``` -------------------------------- ### Instantiate TLVData with String Representation (C#) Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvData.html This example demonstrates how to create a new `TLVData` instance by providing a string representation of the TLV data. The string is expected to be a space-separated sequence of hexadecimal bytes. The example then prints the formatted output of the TLVData object. ```C# TLVData tlvData = new TLVData("88 01 0A"); Console.WriteLine(String.Format("{0}")); ``` -------------------------------- ### C# Example: Convert BCD String to Digits Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BytesHelpers.html This C# example demonstrates the `fromBcd` extension method, converting a string containing BCD digits into a new byte array where each byte represents a single decimal digit. This version processes the entire string. ```C# string value = "1234567890"; byte[] data = value.fromBcd(); // Now data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 } ``` -------------------------------- ### WSCT.Wrapper.Desktop Namespace API Reference Source: https://github.com/wsct/wsct-core/blob/master/docs/index.html Provides an implementation of WSCT abstractions tailored for desktop operating systems (MacOS, Linux, Windows), offering concrete classes for card context and channel management, including observable versions. ```APIDOC WSCT.Wrapper.Desktop Namespace: Implementations of WSCT abstractions for desktop OS: - Core.CardContextCore (implements ICardContext) - Core.CardChannelCore (implements ICardChannel) - Core.CardContext (implements ICardContextObservable) - Core.CardChannel (implements ICardChannelObservable) ``` -------------------------------- ### C# Example: Convert BCD Byte Array to Digits Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BytesHelpers.html This C# example demonstrates the `fromBcd` extension method, converting a BCD-encoded byte array into a new byte array where each byte represents a single decimal digit. It shows how to extract a specific number of digits. ```C# byte[] value = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90 }; byte[] data = value.fromBcd(7); // Now data = { 1, 2, 3, 4, 5, 6, 7 } ``` -------------------------------- ### API Documentation for WSCT.Helpers.BasicEncodingRules.TlvDictionary.CreateInstance(TlvDescription) Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvDictionary.html Documents the static method for creating a new instance of the TLV description described by `tlvDesc`. ```APIDOC Method: CreateInstance(TlvDescription tlvDesc) Description: Creates a new instance of the TLV description described by `tlvDesc` Declaration: public static AbstractTlvObject CreateInstance(TlvDescription tlvDesc) Parameters: tlvDesc: Type: TlvDescription Description: Description of the tag Returns: Type: AbstractTlvObject Description: A new instance of the TLV object ``` -------------------------------- ### TlvData.ToString(String, IFormatProvider) Usage Examples (C#) Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvData.html Examples demonstrating how to use the `ToString(string, IFormatProvider)` method with different format specifiers ('T' for tag, 'L' for length, 'V' for interpreted value, and 'Vh' for raw value) to control the output of a `TlvData` object. ```C# TLVData tlv = new TLVData("6F 1A 84 0E 31 50 41 59 2E 53 59 53 2E 44 44 46 30 31 A5 08 88 01 02 5F 2D 02 66 72"); // Default format: String.Format("{0}", tlv); // output: `T:6F L:1A V:( T:84 L:0E V:31 50 41 59 2E 53 59 53 2E 44 44 46 30 31 )( T:A5 L:08 V:( T:88 L:01 V:02 )( T:5F2D L:02 V:66 72 ) )` // Format "T": tag only String.Format("{0:T}", tlv); // output: `6F` // Format "L": length only String.Format("{0:L}", tlv); // output: `1A` // Format "V": value only; value is interpreted as TLV if its a complex tag String.Format("{0:V}", tlv); // output: `( T:84 L:0E V:31 50 41 59 2E 53 59 53 2E 44 44 46 30 31 )( T:A5 L:08 V:( T:88 L:01 V:02 )( T:5F2D L:02 V:66 72 ) )` // Format "Vh": raw value, no interpretation String.Format("{0:Vh}", tlv); // output: `84 0E 31 50 41 59 2E 53 59 53 2E 44 44 46 30 31 A5 08 88 01 02 5F 2D 02 66 72` ``` -------------------------------- ### C# Example: Convert Byte Array to ASCII String using ToAsciiString Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BytesHelpers.html Demonstrates how to use the `ToAsciiString` extension method in C# to convert a byte array containing ASCII character codes into its corresponding string representation. The example shows initialization of a byte array and the resulting string. ```C# byte[] value = new byte[] { 0x31, 0x32, 0x33 }; string data = value.ToAsciiString(); // Now data = "123" ``` -------------------------------- ### WSCT.Wrapper.Desktop API Primitives Source: https://github.com/wsct/wsct-core/blob/master/docs/api/toc.html Provides the desktop-specific primitive implementations for smart card interactions within the WSCT.Wrapper.Desktop namespace. ```APIDOC WSCT.Wrapper.Desktop: - Primitives ``` -------------------------------- ### WSCT.Wrapper.Desktop.Core API Classes Source: https://github.com/wsct/wsct-core/blob/master/docs/api/toc.html Lists core desktop-specific classes for managing smart card channels and contexts, including event arguments for card insertion and removal. ```APIDOC WSCT.Wrapper.Desktop.Core: - CardChannel - CardChannelCore - CardContext - CardContextCore - OnCardInsertionEventArgs - OnCardRemovalEventArgs - StatusChangeMonitor ``` -------------------------------- ### API Documentation for WSCT.Helpers.BasicEncodingRules.TlvDictionary.GetEnumerator() Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvDictionary.html Documents the method for getting an enumerator of the registered TlvDescriptions. ```APIDOC Method: GetEnumerator() Description: Enumerator of the registered TlvDescriptions Declaration: public IEnumerator GetEnumerator() Returns: Type: System.Collections.IEnumerator Description: The enumerator ``` -------------------------------- ### WSCT.Wrapper.Desktop.Core Namespace Implementations API Source: https://github.com/wsct/wsct-core/blob/master/WSCT.DocFx/index.md This section outlines the concrete implementations of WSCT core abstractions provided by the `WSCT.Wrapper.Desktop.Core` namespace. These classes are designed to adapt to various desktop operating systems (MacOS, Linux, Windows) and include both basic and observable versions of `ICardContext` and `ICardChannel` implementations. ```APIDOC WSCT.Wrapper.Desktop.Core: CardContextCore (implements ICardContext) CardChannelCore (implements ICardChannel) CardContext (implements ICardContextObservable) CardChannel (implements ICardChannelObservable) ``` -------------------------------- ### IPrimitives Interface API Documentation Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.IPrimitives.html Comprehensive API documentation for the `IPrimitives` interface, outlining its properties and methods for interacting with PC/SC API wrappers. ```APIDOC Interface IPrimitives Namespace: WSCT.Wrapper Assembly: WSCT.dll Syntax: public interface IPrimitives Properties: AutoAllocate: Description: Value used by PC/SC API to ask for auto allocation. Declaration: uint AutoAllocate { get; } Property Value: System.UInt32 DefaultBufferSize: Description: Default maximum buffer size used to fetch PC/SC responses. Declaration: uint DefaultBufferSize { get; set; } Property Value: System.UInt32 Methods: CreateIoRequestInstance(Protocol protocol): Description: Builds an AbstractIoRequest for the current OS. Declaration: AbstractIoRequest CreateIoRequestInstance(Protocol protocol) Parameters: protocol: Type: Protocol Description: T Protocol. Returns: Type: AbstractIoRequest Description: The concrete AbstractIoRequest object. CreateReaderStateInstance(String, EventState, EventState): Description: Build an AbstractReaderState for the current OS. Declaration: AbstractReaderState CreateReaderStateInstance(string readerName, EventState currentState, EventState eventState) Parameters: readerName: Type: System.String Description: Name of the reader. currentState: Type: EventState Description: Current state. eventState: Type: EventState Description: Expected state. Returns: Type: AbstractReaderState Description: The concrete AbstractReaderState object. SCardCancel(System.IntPtr): ``` -------------------------------- ### CardChannelObservable Property: Protocol Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Core.CardChannelObservable.html Gets the protocol associated with the observed card channel. ```C# public Protocol Protocol { get; } ``` ```APIDOC Property: Protocol Description: Protocol T Type: Protocol ``` -------------------------------- ### WSCT.ISO7816.Commands.SelectCommand Constructors Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.ISO7816.Commands.SelectCommand.html Documents the available constructors for the `SelectCommand` class, allowing for instantiation with default settings or specific parameters related to selection mode, file occurrence, file control information, and user data content. ```APIDOC Constructors: SelectCommand() Description: Initializes a new instance. Declaration: public SelectCommand() SelectCommand(SelectCommand.SelectionMode selection, SelectCommand.FileOccurrence occurence, SelectCommand.FileControlInformation fci, byte[] udc) Description: Initializes a new instance. Parameters: selection: SelectCommand.SelectionMode occurence: SelectCommand.FileOccurrence fci: SelectCommand.FileControlInformation udc: System.Byte[] Declaration: public SelectCommand(SelectCommand.SelectionMode selection, SelectCommand.FileOccurrence occurence, SelectCommand.FileControlInformation fci, byte[] udc) ``` -------------------------------- ### CardChannelObservable Property: ReaderName Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Core.CardChannelObservable.html Gets the name of the reader associated with the observed card channel. ```C# public string ReaderName { get; } ``` ```APIDOC Property: ReaderName Type: System.String ``` -------------------------------- ### Get All TLVData Subfields (Recursive) Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvData.html Obtains and returns all TLVData objects found in subfields. The search is always recursive. ```APIDOC WSCT.Helpers.BasicEncodingRules.TlvData.GetTags(): Description: Obtains and returns all TLVData found in subfields Search is recursive Declaration: public IEnumerable GetTags() Returns: Type: System.Collections.IEnumerable Description: IEnumerable ``` -------------------------------- ### Get Smart Card Channel Status Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.Desktop.Core.CardChannelCore.html Queries and returns the current operational state of the smart card channel. ```APIDOC WSCT.Wrapper.Desktop.Core.CardChannelCore.GetStatus() Declaration: public virtual State GetStatus() Returns: State ``` -------------------------------- ### WSCT.Wrapper.Desktop.Stack Namespace API Reference Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.Desktop.Stack.html Detailed API documentation for the WSCT.Wrapper.Desktop.Stack namespace, outlining its constituent classes and their implemented interfaces. ```APIDOC Namespace: WSCT.Wrapper.Desktop.Stack Description: Provides core components for desktop-specific stack implementations within the WSCT framework. Classes: CardChannelLayer: Description: Implements CardChannel as a CardChannelLayer. Implements: WSCT.Wrapper.Desktop.Core.CardChannel CardContextLayer: Description: Implements CardContext as a CardContextLayer. Implements: WSCT.Wrapper.Desktop.Core.CardContext ``` -------------------------------- ### Get All TLVData by Tag (Recursive) Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvData.html Obtains and returns all TLVData objects found with the specified tag. The search is performed recursively in subfields. ```APIDOC WSCT.Helpers.BasicEncodingRules.TlvData.GetTags(uint tagSearched): Description: Obtains and returns all TLVData found having tag `tagSearched` Search is recursive in subfields Declaration: public IEnumerable GetTags(uint tagSearched) Parameters: tagSearched: Type: System.UInt32 Description: Number of the tag to search Returns: Type: System.Collections.Generic.IEnumerable ``` -------------------------------- ### Establish() Method for CardContextCore Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.Desktop.Core.CardContextCore.html Documents the `Establish()` method of the `CardContextCore` class, used to establish a new smart card context. ```APIDOC Establish(): Declaration: public virtual ErrorCode Establish() Returns: Type: ErrorCode ``` -------------------------------- ### Get XML Schema for TLVData Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvData.html Retrieves the XML schema definition for the TLVData object. This method is part of the `System.Xml.Serialization.IXmlSerializable` interface implementation. ```APIDOC WSCT.Helpers.BasicEncodingRules.TlvData.GetSchema(): Declaration: public XmlSchema GetSchema() Returns: Type: System.Xml.Schema.XmlSchema ``` -------------------------------- ### ResponseAPDU Class Properties API Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.ISO7816.ResponseAPDU.html Details the properties available in the `ResponseAPDU` class, such as `BufferSize`, which allows getting or setting the buffer size. ```APIDOC Properties: BufferSize Declaration: public int BufferSize { get; set; } ``` -------------------------------- ### WSCT.Helpers.Json.JsonHelpers Class API Reference Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.ISO7816.Commands.SelectCommand.html Detailed API documentation for the `JsonHelpers` class, providing methods to convert .NET objects into JSON formatted strings or write them directly to files. Overloads allow for pretty-printing the output. ```APIDOC WSCT.Helpers.Json.JsonHelpers: WriteToJsonFile(Object obj, String filePath) WriteToJsonFile(Object obj, String filePath, Boolean prettyPrint) WriteToJsonString(Object obj) WriteToJsonString(Object obj, Boolean prettyPrint) ``` -------------------------------- ### Get Smartcard Status: GetStatus() Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Core.ICardChannel.html Retrieves the current status of the smartcard inserted in the reader. This can indicate if a card is present, absent, or if there are any issues. ```APIDOC State GetStatus() Returns: State (Success if succeeded.) ``` ```C# State GetStatus() ``` -------------------------------- ### WSCT.Wrapper.PCSCLite64 API Primitives Source: https://github.com/wsct/wsct-core/blob/master/docs/api/toc.html Provides 64-bit PCSCLite-specific primitive implementations for smart card interactions. ```APIDOC WSCT.Wrapper.PCSCLite64: - Primitives ``` -------------------------------- ### Get Smart Card Status Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Stack.CardChannelStack.html Retrieves the current status of the smart card. This method provides information about the card's presence and state. ```APIDOC GetStatus() -> State ``` -------------------------------- ### CardChannel Class Parameterized Constructor Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.Desktop.Core.CardChannel.html Documents the constructor for the `CardChannel` class that initializes a new instance with a specified card context and reader name. It outlines the types and names of the required parameters. ```APIDOC CardChannel(ICardContext context, string readerName) Declaration: public CardChannel(ICardContext context, string readerName) Parameters: context: ICardContext readerName: System.String ``` -------------------------------- ### Get Smart Card Attributes Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Stack.CardChannelStack.html Retrieves specific attributes from the smart card. This method allows querying card properties or state information. ```APIDOC GetAttrib(attrib: Attrib, buffer: ref byte[]) -> ErrorCode attrib: The specific attribute to retrieve. buffer: A byte array to receive the attribute data. This parameter is passed by reference. ``` -------------------------------- ### AfterGetStatusEvent Declaration Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Core.CardChannelObservable.html Documents the `AfterGetStatusEvent`, an event exposed by `WSCT.Core.CardChannelObservable`. This event is triggered after getting the card status, providing `AfterGetStatusEventArgs` to its subscribers. ```APIDOC Event: AfterGetStatusEvent Declaration: public event EventHandler AfterGetStatusEvent Event Type: System.EventHandler ``` -------------------------------- ### WSCT.Core Namespace Classes Overview Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Core.html Documentation for the core classes within the WSCT.Core namespace, providing functionalities for observing existing smartcard channels and contexts by wrapping them with delegate-based observation mechanisms. ```APIDOC Namespace WSCT.Core Classes: CardChannelObservable: Description: Allows an existing ICardChannel instance to be observed by using delegates and wrapping it. CardContextObservable: Description: Allows an existing ICardContext instance to be observed by using delegates and wrapping it. ``` -------------------------------- ### WSCT.Core.CardContextObservable.BeforeGetStatusChangeEvent Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Core.CardContextObservable.html Documents the `BeforeGetStatusChangeEvent` event, which is triggered before getting smart card status changes. This event provides a hook for pre-processing or validation before querying status changes. ```APIDOC Event: BeforeGetStatusChangeEvent Declaration: public event EventHandler BeforeGetStatusChangeEvent Type: System.EventHandler ``` -------------------------------- ### Initialize SelectCommand Constructor Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.ISO7816.Commands.SelectCommand.html Initializes a new instance of the `SelectCommand` class with specified selection mode, file occurrence, file control information, user data content, and expected length of response data. ```APIDOC SelectCommand(SelectCommand.SelectionMode selection, SelectCommand.FileOccurrence occurence, SelectCommand.FileControlInformation fci, Byte[], UInt32 le) Description: Initializes a new instance. Declaration: public SelectCommand(SelectCommand.SelectionMode selection, SelectCommand.FileOccurrence occurence, SelectCommand.FileControlInformation fci, byte[] udc, uint le) Parameters: selection: Type: WSCT.ISO7816.Commands.SelectCommand.SelectionMode occurence: Type: WSCT.ISO7816.Commands.SelectCommand.FileOccurrence fci: Type: WSCT.ISO7816.Commands.SelectCommand.FileControlInformation udc: Type: System.Byte[] le: Type: System.UInt32 ``` ```C# public SelectCommand(SelectCommand.SelectionMode selection, SelectCommand.FileOccurrence occurence, SelectCommand.FileControlInformation fci, byte[] udc, uint le) ``` -------------------------------- ### Establish Smart Card Resource Manager Context Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Core.ICardContext.html Documents the `Establish()` method of the ICardContext interface, which is used to initialize the smart card resource manager context. ```APIDOC ICardContext.Establish(): Description: Establishes the resource manager context. Declaration: ErrorCode Establish() Returns: Type: ErrorCode Description: Success if succeeded. ``` -------------------------------- ### C# Example: Convert Byte Array to TLVData Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvDataHelper.html Illustrates how to use the `ToTlvData` extension method on a `byte[]` to parse it into a `TlvData` object, demonstrating a common conversion scenario. ```C# byte[] source = new byte[] {0x88, 0x01, 0x0A}; TLVData tlv = source.toTLVData(); // Now tlv is T:88 L:01 V:0A ``` -------------------------------- ### Get AutoAllocate Property of Primitives Class Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.MacOSX.Primitives.html Documents the `AutoAllocate` property of the `Primitives` class. This read-only property provides a `System.UInt32` value, likely related to memory allocation behavior. ```APIDOC Property: AutoAllocate Declaration: public uint AutoAllocate { get; } Type: System.UInt32 ``` -------------------------------- ### WSCT.Wrapper Namespace Classes Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.html Lists the abstract classes available in the WSCT.Wrapper namespace, providing base structures for PC/SC wrapper implementations. ```APIDOC Classes: AbstractIoRequest: Abstract IoRequest structure to be implemented by PC/SC wrapper. AbstractReaderState: Abstract ReaderState structure to be implemented by PC/SC wrapper. ``` -------------------------------- ### Parse TLV Data from Byte Array with Offset Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvData.html Parses an array of Bytes as TLV data, starting from a specified offset. This method returns the new offset after consuming the TLV data. ```APIDOC WSCT.Helpers.BasicEncodingRules.TlvData.Parse(byte[] data, uint offset): Declaration: public uint Parse(byte[] data, uint offset) Parameters: data: System.Byte[] - Array of Bytes to be parsed offset: System.UInt32 - Offset to begin parsing Returns: System.UInt32 - New value of the offset (`offset`+number of bytes consumed) ``` -------------------------------- ### WSCT.Wrapper.PCSCLite32 API Primitives Source: https://github.com/wsct/wsct-core/blob/master/docs/api/toc.html Provides 32-bit PCSCLite-specific primitive implementations for smart card interactions. ```APIDOC WSCT.Wrapper.PCSCLite32: - Primitives ``` -------------------------------- ### C# Example: Convert Byte Array to Hex String Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BytesHelpers.html Demonstrates how to use the `ToHexa` extension method to convert a byte array to a hexadecimal string, specifying the length and a custom separator character. ```C# byte[] value = new byte[] { 0x31, 0x32, 0x33 }; string data = value.toHexa(2, '-'); // Now data = "31-32" ``` -------------------------------- ### API Documentation for BeforeGetStatusEventArgs Class Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Core.Events.BeforeGetStatusEventArgs.html Detailed API documentation for the `BeforeGetStatusEventArgs` class, outlining its full inheritance chain, members inherited from base classes, and a list of extension methods that can be applied to instances of this class. ```APIDOC Class: BeforeGetStatusEventArgs Inheritance: System.Object System.EventArgs BeforeGetStatusEventArgs Inherited Members: System.EventArgs.Empty System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone() System.Object.ReferenceEquals(System.Object, System.Object) System.Object.ToString() Namespace: WSCT.Core.Events Assembly: WSCT.dll Extension Methods: JsonHelpers.WriteToJsonFile(Object, String) JsonHelpers.WriteToJsonFile(Object, String, Boolean) JsonHelpers.WriteToJsonString(Object) JsonHelpers.WriteToJsonString(Object, Boolean) ``` -------------------------------- ### Primitives.DefaultBufferSize Property API Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.WinSCard.Primitives.html API documentation for the `DefaultBufferSize` property of the `Primitives` class. This property allows both getting and setting a `System.UInt32` value, which represents the default buffer size used in operations. ```APIDOC Primitives.DefaultBufferSize: Declaration: public uint DefaultBufferSize { get; set; } Property Value: Type: System.UInt32 Description: (No description provided in source) ``` -------------------------------- ### SCardConnect Method API Documentation Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.PCSCLite32.Primitives.html Documents the `SCardConnect` method, used to establish a connection to a smart card reader. It requires a valid context, reader name, share mode, and preferred protocol, returning a card handle and the active protocol established. ```APIDOC SCardConnect(IntPtr, String, ShareMode, Protocol, ref IntPtr, ref Protocol) Declaration: public ErrorCode SCardConnect(IntPtr context, string readerName, ShareMode shareMode, Protocol preferedProtocol, ref IntPtr card, ref Protocol activeProtocol) Parameters: context: System.IntPtr readerName: System.String shareMode: WSCT.Wrapper.ShareMode preferedProtocol: WSCT.Wrapper.Protocol card: ref System.IntPtr activeProtocol: ref System.IntPtr Returns: Type: WSCT.Wrapper.ErrorCode ``` -------------------------------- ### WSCT.Core Namespace Interfaces Overview Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Core.html Documentation for the core interfaces within the WSCT.Core namespace, defining contracts for managing smartcard access and context, along with their observable counterparts for event-driven programming. ```APIDOC Namespace WSCT.Core Interfaces: ICardChannel: Description: Interface for card channels, ie objects capable of managing access to a smartcard. ICardChannelObservable: Description: Interface to be implemented by all observable ICardChannel instance. ICardContext: Description: Interface for card contexts, ie objects capable of managing the resources to access to readers. ICardContextObservable: Description: Interface to be implemented by all observable ICardContext instance. ``` -------------------------------- ### Get/Set DefaultBufferSize Property of Primitives Class Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.MacOSX.Primitives.html Documents the `DefaultBufferSize` property of the `Primitives` class. This property allows both getting and setting a `System.UInt32` value, defining the default buffer size for operations. ```APIDOC Property: DefaultBufferSize Declaration: public uint DefaultBufferSize { get; set; } Type: System.UInt32 ``` -------------------------------- ### CardContextStackObservable.Layers Property Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Stack.CardContextStackObservable.html Gets a list of `ICardContextLayer` objects currently managed by this observable stack. This property provides read-only access to the collection of layers, allowing inspection of the current stack configuration. ```APIDOC CardContextStackObservable.Layers: Type: System.Collections.Generic.List Access: get ``` -------------------------------- ### WSCT.Helpers.Security.Ssh1PublicKeyBody Class API Reference Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.Security.Ssh1PublicKeyBody.html Detailed API documentation for the `WSCT.Helpers.Security.Ssh1PublicKeyBody` class, including its static factory methods and instance methods. ```APIDOC WSCT.Helpers.Security.Ssh1PublicKeyBody Class Methods: Create(byte[] bodyKey) Description: Creates a new Ssh1PublicKeyBody instance using the byte array. Declaration: public static Ssh1PublicKeyBody Create(byte[] bodyKey) Parameters: bodyKey: System.Byte[] Returns: WSCT.Helpers.Security.Ssh1PublicKeyBody Create(string base64BodyKey) Description: Creates a new Ssh1PublicKeyBody instance using the base64 encoded public key. Declaration: public static Ssh1PublicKeyBody Create(string base64BodyKey) Parameters: base64BodyKey: System.String Returns: WSCT.Helpers.Security.Ssh1PublicKeyBody ToString() Description: Returns a string that represents the current object. Declaration: public override string ToString() Returns: System.String Overrides: System.Object.ToString() Extension Methods (Referenced): JsonHelpers.WriteToJsonFile(Object, String) JsonHelpers.WriteToJsonFile(Object, String, Boolean) JsonHelpers.WriteToJsonString(Object) JsonHelpers.WriteToJsonString(Object, Boolean) ``` -------------------------------- ### API Reference for WSCT.Helpers.BasicEncodingRules.TlvDescription Properties and JsonHelpers Extension Methods Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvDescription.html Detailed API documentation for the properties of the `WSCT.Helpers.BasicEncodingRules.TlvDescription` class and the `WSCT.Helpers.Json.JsonHelpers` static extension methods, including their types, parameters, and descriptions. ```APIDOC WSCT.Helpers.BasicEncodingRules.TlvDescription: Properties: LongName: Type: System.String Description: Represents the long name of the TLV description. Name: Type: System.String Description: Accessor to the (short) name of the tag. PathToDll: Type: System.String Description: Accessor to the path to dll file on disk. Source: Type: System.String Description: Accessor to the source of the tag (ICC/Terminal/Issuer/...). Value: Type: TlvDescription.ValueType Description: Accessor to the format of the field. WSCT.Helpers.Json.JsonHelpers (Extension Methods): WriteToJsonFile(obj: System.Object, filePath: System.String): Description: Writes an object to a JSON file. WriteToJsonFile(obj: System.Object, filePath: System.String, indented: System.Boolean): Description: Writes an object to a JSON file with optional indentation. WriteToJsonString(obj: System.Object): Description: Converts an object to a JSON string. WriteToJsonString(obj: System.Object, indented: System.Boolean): Description: Converts an object to a JSON string with optional indentation. ``` -------------------------------- ### Get/Set DefaultBufferSize Property Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.PCSCLite32.Primitives.html This property allows getting and setting the default buffer size used by the `Primitives` class. It is an unsigned 32-bit integer that influences the size of data buffers for various operations. ```APIDOC Primitives.DefaultBufferSize: Declaration: public uint DefaultBufferSize { get; set; } Type: System.UInt32 ``` -------------------------------- ### API Documentation for Primitives Class Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.PCSCLite64.Primitives.html Detailed API documentation for the WSCT.Wrapper.PCSCLite64.Primitives class, which wraps PC/SC (pcsclite) for 64-bit Linux. This includes its inheritance hierarchy, implemented interfaces, public properties, and methods with their respective parameters and return types. ```APIDOC Class: Primitives Description: Wrapper of PC/SC (pcsclite) for 64 bits linux. Namespace: WSCT.Wrapper.PCSCLite64 Assembly: WSCT.Wrapper.PCSCLite64.dll Inheritance: - System.Object - Primitives Implements: - IPrimitives Syntax: public class Primitives : IPrimitives Properties: - Name: AutoAllocate Declaration: public uint AutoAllocate { get; } Type: System.UInt32 - Name: DefaultBufferSize Declaration: public uint DefaultBufferSize { get; set; } Type: System.UInt32 Methods: - Name: CreateIoRequestInstance Declaration: public AbstractIoRequest CreateIoRequestInstance(Protocol protocol) Parameters: - Name: protocol Type: Protocol Returns: Type: AbstractIoRequest - Name: CreateReaderStateInstance Declaration: public AbstractReaderState CreateReaderStateInstance(string readerName, EventState currentState, EventState eventState) Parameters: - Name: readerName Type: System.String - Name: currentState Type: EventState - Name: eventState Type: EventState Returns: Type: AbstractReaderState - Name: SCardCancel Declaration: public ErrorCode SCardCancel(IntPtr context) Parameters: - Name: context Type: System.IntPtr Returns: Type: ErrorCode ``` -------------------------------- ### Get AutoAllocate Property Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.PCSCLite32.Primitives.html This property provides access to the `AutoAllocate` setting within the `Primitives` class. It is a read-only property that returns an unsigned 32-bit integer, typically used to determine allocation behavior. ```APIDOC Primitives.AutoAllocate: Declaration: public uint AutoAllocate { get; } Type: System.UInt32 ``` -------------------------------- ### WSCT.Wrapper.MacOSX API Primitives Source: https://github.com/wsct/wsct-core/blob/master/docs/api/toc.html Provides MacOSX-specific primitive implementations for smart card interactions. ```APIDOC WSCT.Wrapper.MacOSX: - Primitives ``` -------------------------------- ### Parse TLV Tag (T) from Byte Array with Offset Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvData.html Parses only the T (tag) part of a TLV data structure from an array of bytes, starting from a specified offset. It returns the new offset after consuming the tag bytes. ```APIDOC WSCT.Helpers.BasicEncodingRules.TlvData.ParseT(byte[] data, uint offset): Declaration: public uint ParseT(byte[] data, uint offset) Parameters: data: System.Byte[] - Array of Bytes to be parsed offset: System.UInt32 - Offset to begin parsing Returns: System.UInt32 - New value of the offset (`offset`+number of bytes consumed) ``` -------------------------------- ### WSCT.Stack.Generic Namespace Classes Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Stack.Generic.html API documentation for the WSCT.Stack.Generic namespace, listing its core classes and their functionalities related to generic layer and stack descriptions for dynamic loading. ```APIDOC Namespace WSCT.Stack.Generic Classes: GenericLayerDescription: Description: Generic layer description (by its name, assembly and class name) for dynamic load. GenericStackDescription: Description: Generic layer description (by its name, assembly and class name) for dynamic load. ``` -------------------------------- ### C# Example: Convert BCD byte array to digits with length Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BytesHelpers.html Demonstrates how to use the `FromBcd` extension method with a `ReadOnlySpan` and a specified length to convert a BCD-coded byte array into an array of individual digits. ```C# byte[] source = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90 }; byte[] data = source.fromBcd(9); // Now data = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ``` -------------------------------- ### SCardReconnect Method API Documentation Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Wrapper.MacOSX.Primitives.html Provides the API specification for the SCardReconnect function, which allows re-establishing a connection to a smart card with specified share mode, preferred protocol, and initialization disposition, returning the active protocol. ```C# public ErrorCode SCardReconnect(IntPtr card, ShareMode shareMode, Protocol preferedProtocol, Disposition initialisation, ref Protocol activeProtocol) ``` ```APIDOC SCardReconnect( card: System.IntPtr, shareMode: ShareMode, preferedProtocol: Protocol, initialisation: Disposition, activeProtocol: ref Protocol ) Parameters: card: System.IntPtr shareMode: ShareMode preferedProtocol: Protocol initialisation: Disposition activeProtocol: ref Protocol Returns: ErrorCode ``` -------------------------------- ### C# P2 Property Declaration Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.ISO7816.CommandAPDU.html Declares the 'P2' property for the CommandAPDU class. This property allows getting and setting the second parameter byte (P2) of an ISO/IEC 7816-4 Command APDU, represented as a byte. ```C# public byte P2 { get; set; } ``` -------------------------------- ### API Documentation for CardChannelLayerDescription Class Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Stack.CardChannelLayerDescription.html Comprehensive API documentation for the `CardChannelLayerDescription` class, detailing its inheritance hierarchy, inherited members from `System.Object` and `GenericLayerDescription`, its namespace, assembly, and available extension methods from `JsonHelpers`. ```APIDOC Class: CardChannelLayerDescription Namespace: WSCT.Stack Assembly: WSCT.dll Inheritance: - System.Object - GenericLayerDescription - CardChannelLayerDescription Inherited Members: - GenericLayerDescription.Name - GenericLayerDescription.DllName - GenericLayerDescription.ClassName - GenericLayerDescription.PathToDll - GenericLayerDescription.IsValid - System.Object.Equals(System.Object) - System.Object.Equals(System.Object, System.Object) - System.Object.GetHashCode() - System.Object.GetType() - System.Object.MemberwiseClone() - System.Object.ReferenceEquals(System.Object, System.Object) - System.Object.ToString() Extension Methods: - JsonHelpers.WriteToJsonFile(Object, String) - JsonHelpers.WriteToJsonFile(Object, String, Boolean) - JsonHelpers.WriteToJsonString(Object) - JsonHelpers.WriteToJsonString(Object, Boolean) ``` -------------------------------- ### Parse TLV Value (V) from Byte Array with Offset Source: https://github.com/wsct/wsct-core/blob/master/docs/api/WSCT.Helpers.BasicEncodingRules.TlvData.html Parses only the V (value) part of a TLV data structure from an array of bytes, starting from a specified offset. It returns the new offset after consuming the value bytes. ```APIDOC WSCT.Helpers.BasicEncodingRules.TlvData.ParseV(byte[] data, uint offset): Declaration: public uint ParseV(byte[] data, uint offset) Parameters: data: System.Byte[] - Array of Bytes to be parsed offset: System.UInt32 - Offset to begin parsing Returns: System.UInt32 - New value of the offset (`offset`+number of bytes consumed) ```