Exemplo n.º 1
0
 public PcscReaderStatus(PcscContext context, IEnumerable <string> readerNames) : base(new List <PcscReaderState>())
 {
     Context = context;
     foreach (var readerName in readerNames)
     {
         Items.Add(new PcscReaderState(readerName));
     }
     _readerStates = (Provider = context.Provider).AllocateReaderStates(Items.Count);
 }
Exemplo n.º 2
0
        public unsafe static string GetReaderGroupNames(this IPcscProvider provider, SCardContext handle, PcscExceptionHandler onException)
        {
            byte *pGroupNames = null;
            var   charCount   = PcscProvider.SCardAutoAllocate;

            try
            {
                provider.SCardListReaderGroups(handle, &pGroupNames, &charCount).ThrowIfNotSuccess(onException);
                return(provider.AllocateString(pGroupNames, charCount));
            }
            finally
            {
                if (pGroupNames != null)
                {
                    provider.SCardFreeMemory(handle, pGroupNames).ThrowIfNotSuccess(onException);
                }
            }
        }
Exemplo n.º 3
0
        public unsafe static string GetReaderNames(this IPcscProvider provider, SCardContext handle, string group, PcscExceptionHandler onException)
        {
            string readerNames = null;
            byte * pReaderNames;
            var    charCount = PcscProvider.SCardAutoAllocate;
            var    err       = provider.SCardListReaders(handle, group, &pReaderNames, &charCount);

            try
            {
                switch (err)
                {
                case SCardError.NoReadersAvailable:
                    // In Windows, it seems to still return a `NULL` character with `SCardError.Success` status even none of reader names is found.
                    break;

                case SCardError.Successs:
                    /*
                     * Providers can use ANSI (e.g., WinSCard and pcsc-lite) or Unicode (e.g., WinSCard) for the encoding of characters.
                     * In ANSI, `charCount` means the byte count of string.
                     * In Unicode, `charCount` means the number of Unicode characters of string.
                     */
                    readerNames = provider.AllocateString(pReaderNames, charCount);
                    break;

                default:
                    err.Throw(onException);
                    break;
                }
            }
            finally
            {
                if (pReaderNames != null)
                {
                    provider.SCardFreeMemory(handle, pReaderNames).ThrowIfNotSuccess(onException);
                }
            }
            return(readerNames);
        }
Exemplo n.º 4
0
 public Pcsc(IPcscProvider provider)
 {
     Provider = provider;
 }
Exemplo n.º 5
0
 public PcscContext(IPcscProvider provider)
 {
     Provider = provider;
 }