/// <summary> /// Locate the smartcard type with the identified ATR bytes /// </summary> /// <param name="atr">ATR byte array</param> /// <returns>Cardname matching the ATR</returns> private string FindCardWithAtr(byte[] atr) { var cardLen = 1024; var cards = new char[cardLen]; var result = SmartcardInterop.SCardListCardsW(IntPtr.Zero, atr, IntPtr.Zero, 0, cards, out cardLen); if (result != SmartcardException.SCardSuccess) { this.logger.DebugFormat("Failed to find smartcard by ATR: error 0x{0}", result); throw new SmartcardException(result); } var card = SmartcardInterop.MultiStringToArray(cards); if (card.Count == 0) { throw new SmartcardException(SmartcardException.SCardECardUnsupported); } if (card.Count > 1) { throw new SmartcardException(SmartcardException.SCardEUnexpected); } return(card[0]); }
/// <summary> /// Find all supported smartcard types /// </summary> /// <returns>List of supported card types</returns> private List <string> FetchCards() { var cardLen = 16384; var cards = new char[cardLen]; var result = SmartcardInterop.SCardListCardsW(this.readerContext, null, IntPtr.Zero, 0, cards, out cardLen); if (result != SmartcardException.SCardSuccess) { this.logger.ErrorFormat("Failed to fetch smartcard names, result = 0x{0:X}", result); throw new SmartcardException(result); } var c = SmartcardInterop.MultiStringToArray(cards); if (this.logger.IsDebugEnabled) { this.logger.DebugFormat("Known cards; count = {0}", c.Count); foreach (var card in c) { this.logger.DebugFormat(" {0}", card); } } return(c.ToList()); }