当前位置: 首页>>代码示例>>Python>>正文


Python util.toHexString函数代码示例

本文整理汇总了Python中smartcard.util.toHexString函数的典型用法代码示例。如果您正苦于以下问题:Python toHexString函数的具体用法?Python toHexString怎么用?Python toHexString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了toHexString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testcase_CardRequestNewCardInReaderNotPresentInfiniteTimeOut

    def testcase_CardRequestNewCardInReaderNotPresentInfiniteTimeOut(self):
        """Test smartcard.CardRequest for any new card in a specific
        reader not present without time-out."""

        print 'please remove a smart card reader'
        _readerz = readers()
        while True:
            readerz = readers()
            if len(_readerz) > len(readerz):
                break
            time.sleep(.1)

        for reader in readerz:
            _readerz.remove(reader)

        cardtype = AnyCardType()
        cardrequest = CardRequest(
            timeout=None,
            readers=[_readerz[0]],
            cardType=cardtype,
            newcardonly=True)
        print 'Re-insert reader ', _readerz[0], 'with a card inside'
        cardservice = cardrequest.waitforcard()
        cardservice.connection.connect()
        print toHexString(
            cardservice.connection.getATR()), \
            'in', cardservice.connection.getReader()
        cardservice.connection.disconnect()
开发者ID:317070,项目名称:drapri,代码行数:28,代码来源:testcase_manualCardRequest.py

示例2: _process_card

    def _process_card(self, connection):
        """This is where the magic happens"""
        self.reader.busy_signal(connection)
        self.logger.info(self.reader.card_description + ' card detected')
        self.logger.debug('ATR: ' + toHexString(self.reader.card_ATR))
        card_serial_number = self.reader.get_serial_number(connection)
        if card_serial_number:
            self.logger.debug('UID: ' + toHexString(card_serial_number))
        else:
            card_serial_number = []
            self.logger.warn('No UID read!')

        # parse data definition and read data accordingly
        data_list = self._read_defined_data(connection)

        output_string = self.head + self.start1 + self.track1 + self.end
        if self.track2 != "": output_string += self.start2 + self.track2 + self.end
        if self.track3 != "": output_string += self.start3 + self.track3 + self.end
        output_string += self.tail

        self.key_stroker.send_string(
            self._process_output_string(output_string, card_serial_number, data_list))

        self.reader.ready_signal(connection)
        connection.disconnect()
开发者ID:Sam-Hall,项目名称:ACR122-HID-Emulate,代码行数:25,代码来源:hidemu.py

示例3: case_3e

    def case_3e(self, full):
        # send data to the card
        # >  80 12 01 80 00 00 07 00 01 02 03 04 05 06
        # <  []  90 0
        CASE_3 = toBytes("80 12 01 80 00 00 00")

        print "Case 3 extended"
        print

        if toHexString(self.ATR) != "3B D6 18 00 81 B1 80 7D 1F 03 80 51 00 61 10 30 8F":
            print_error("Wrong card inserted!")
            print "Got ATR:", toHexString(self.ATR)
            return

        end = 65535
        step = 100
        if full:
            start = 1
        else:
            start = end

        expected = ([], 0x90, 0x00)
        for length in range(start, end + 1, step):
            print self.BOL, "length:", length
            APDU = list(CASE_3)
            APDU[5] = (length & 0xFF00) >> 8
            APDU[6] = length & 0x00FF
            APDU += [i for i in range(0, length)]

            self.transmitAndCompare(APDU, expected)
开发者ID:LudovicRousseau,项目名称:HandlerTest,代码行数:30,代码来源:validation.py

示例4: read

    def read(self):
	# keyword to ask card id
	SELECT = [0xFF, 0xCA, 0x00, 0x00, 0x00]

        if debug: print "reading data"
        try:
	    self.connection.connect()
	    data, sw1, sw2 = self.connection.transmit( SELECT )
	    if debug: print "%x %x" % (sw1, sw2)
	    #90 0
	    if debug: print data
	    if format == 'hex' and reverse == 0:
		cardid = toHexString(data).replace(' ','')
	    elif format == 'hex' and reverse == 1:
		cardid = toHexString(data[::-1]).replace(' ','')
	    elif format == 'dec' and reverse == 0:
		cardid = toHexString(data).replace(' ','')
		cardid = int(cardid, 16)
	    elif format == 'dec' and reverse == 1:
		cardid = toHexString(data[::-1]).replace(' ','')
		cardid = int(cardid, 16)
	    if debug: print "cardid: %s" % cardid
	    return cardid
	except:
	    if debug: print "no card data"
	    return False
开发者ID:Thomas-Tsai,项目名称:kl.ucard,代码行数:26,代码来源:ucardreader.py

示例5: case_2e

    def case_2e(self, full):
        # gets (1 to 256) data from the card
        # >  80 00 04 2A 00 00 07
        # <  2A 2A 2A 2A 2A 2A 2A 90 0
        magic_value = 42
        CASE_2 = toBytes("80 00 04 00 00 00 00")
        CASE_2[3] = magic_value

        print "Case 2 extended"
        print

        # ATRs of the Athena test cards
        Athena_ATRs = ["3B D6 18 00 80 B1 80 6D 1F 03 80 51 00 61 10 30 9E",
                       "3F 96 18 80 01 80 51 00 61 10 30 9F"]

        if toHexString(self.ATR) not in Athena_ATRs:
            print_error("Wrong card inserted!")
            print "Got ATR:", toHexString(self.ATR)
            return

        step = 100
        end = 65535
        if full:
            start = 1
        else:
            start = end

        for length in range(start, end + 1, step):
            print self.BOL, "length:", length
            APDU = list(CASE_2)
            APDU[5] = (length & 0xFF00) >> 8
            APDU[6] = length & 0x00FF

            expected = ([magic_value] * length, 0x90, 0x00)
            self.transmitAndCompare(APDU, expected)
开发者ID:LudovicRousseau,项目名称:HandlerTest,代码行数:35,代码来源:validation.py

示例6: send_to_tag

    def send_to_tag(self, tag, apdu):
        if tag is not None:
            raise ValueError('Multiple tags not supported')

        HResult(smartcard.scard.SCardBeginTransaction(self.hcard))

        if DEBUG:
            print '> %s' % toHexString(list(apdu))

        response = HResult(smartcard.scard.SCardTransmit(self.hcard, smartcard.scard.SCARD_PCI_T0, list(apdu)))
        if DEBUG:
            print '< %s' % toHexString(response)

        sw1, sw2 = response[0:2]
        if sw1 == 0x61:  # More data
            apdu2 = APDU(0, 0xc0, lc=sw2)
            if DEBUG:
                print '> %s' % toHexString(list(apdu2))

            response = HResult(smartcard.scard.SCardTransmit(self.hcard, smartcard.scard.SCARD_PCI_T0, list(apdu2)))
            if DEBUG:
                print '< %s' % toHexString(response)

        HResult(smartcard.scard.SCardEndTransaction(self.hcard, smartcard.scard.SCARD_LEAVE_CARD))

        return response
开发者ID:marksteward,项目名称:RFUID,代码行数:26,代码来源:rfid.py

示例7: printExchange

def printExchange(query, response, sw1, sw2):
    """Affiche un échange query-response."""
    print ">> ",
    if type(query) == type([]):
         print toHexString(query)
    else:
        print query
    print "<< ", toHexString(response), " / ", "%x %x" % (sw1, sw2)
开发者ID:SecretTarget,项目名称:Tatami,代码行数:8,代码来源:display.py

示例8: print_details

def print_details(debug, apdu, result, t, n):
  (data, sw1, sw2) = result

  if debug == 1:
    print "C =", toHexString(apdu)
    print "D =",toHexString(data)
    print "R = %x %x" % (sw1, sw2)
    print '%s took %0.3f ms.' % (n, t*1000.)
开发者ID:adelapie,项目名称:irma_phase_2,代码行数:8,代码来源:irma_util.py

示例9: printExchange

def printExchange(query, response, sw1, sw2):
    """Prints an APDU exchange (query-response)."""
    print ">> ",
    if type(query) is types.ListType:
         print toHexString(query)
    else:
        print query
    print "<< ", toHexString(response), " / ", "%x %x" % (sw1, sw2)
开发者ID:317070,项目名称:drapri,代码行数:8,代码来源:display.py

示例10: update

 def update(self, observable, actions):
     (addedcards, removedcards) = actions
     foundcards = {}
     self.testcase.assertEqual(removedcards, [])
     for card in addedcards:
         foundcards[toHexString(card.atr)] = 1
     for atr in expectedATRs:
         if [] != atr and {} != foundcards:
             self.testcase.assertTrue(toHexString(atr) in foundcards)
开发者ID:AnnePieter,项目名称:P4Pkoffiekaart,代码行数:9,代码来源:testcase_CardMonitor.py

示例11: _send_apdu

	def _send_apdu(self, apdu):
		if self.debug == True:
			print("--> {0}".format(toHexString(apdu)))
		data, sw1, sw2 = self.connection.transmit(apdu)
		self.last_sent = apdu
		self.last_received = data + [sw1, sw2]
		if self.debug == True:
			print("<-- {0}".format(toHexString(data)))
			print("<-- {0}".format(toHexString([sw1, sw2])))
			print("")
		return data, sw1, sw2
开发者ID:dudemcbacon,项目名称:MaximAPI,代码行数:11,代码来源:maxim.py

示例12: evtLogKeyDown

 def evtLogKeyDown(self, event):
     code = event.GetKeyCode()
     if wx.WXK_RETURN == code or wx.WXK_NUMPAD_ENTER == code:
         linenum = len(self.txtLog.GetRange(0, self.txtLog.GetInsertionPoint()).split("\n"))
         linetext = self.txtLog.GetLineText(linenum - 1)
         self.history.append(linetext)
         self.history_index = len(self.history)
         cmd = map(ord, linetext.decode("hex"))
         self.txtLog.AppendText("\n")
         if self.card:
             try:
                 data, sw1, sw2 = self.card.transmit(cmd)
             except Exceptions.CardConnectionException as ex:
                 self.txtLog.SetDefaultStyle(wx.TextAttr("RED"))
                 self.txtLog.AppendText("{0}\n\n".format(ex.message))
                 self.txtLog.SetDefaultStyle(wx.TextAttr("BLACK"))
             if sw1 == 0x61:
                 data, sw1, sw2 = self.card.transmit([0x00, 0xC0, 0x00, 0x00, sw2])
             self.txtLog.SetDefaultStyle(wx.TextAttr("BROWN"))
             if data:
                 self.txtLog.AppendText("> Data:\n")
                 for octet in [data[i : i + 8] for i in xrange(0, len(data), 8)]:
                     txtform = "".join(map(logchr, octet))
                     txtform = "{0}{1}{2}\n".format(toHexString(octet), " " * ((8 - len(octet)) * 3 + 5), txtform)
                     self.txtLog.AppendText(txtform)
             self.txtLog.SetDefaultStyle(wx.TextAttr("BLUE"))
             self.txtLog.AppendText("> SW: " + toHexString([sw1, sw2]) + "\n\n")
             self.txtLog.SetDefaultStyle(wx.TextAttr("BLACK"))
         self.lastpos = self.txtLog.GetLastPosition()
     elif wx.WXK_UP == code:
         if not len(self.history):
             return
         if self.history_index:
             self.history_index -= 1
         self.txtLog.Remove(self.lastpos, self.txtLog.GetLastPosition())
         self.txtLog.SetInsertionPoint(self.lastpos)
         self.txtLog.WriteText(self.history[self.history_index])
     elif wx.WXK_DOWN == code:
         if not len(self.history):
             return
         if self.history_index + 1 < len(self.history):
             self.history_index += 1
         self.txtLog.Remove(self.lastpos, self.txtLog.GetLastPosition())
         self.txtLog.SetInsertionPoint(self.lastpos)
         self.txtLog.WriteText(self.history[self.history_index])
     elif wx.WXK_BACK == code:
         if self.lastpos < self.txtLog.GetInsertionPoint():
             event.Skip()
     else:
         event.Skip()
         return
开发者ID:harm7,项目名称:ScardCmd,代码行数:51,代码来源:scardcmd.py

示例13: _card_connection_observer_update

    def _card_connection_observer_update(self, card_connection, event):
        """CardConnectionObserver interface implementation"""

        if 'connect' == event.type:
            print 'Card inserted\n'

        elif 'disconnect' == event.type:
            print 'Card removed\n'

        elif 'command' == event.type:
            print '> ', toHexString(event.args[0])

        elif 'response' == event.type:
            print '< ', '[{}]\n<  {:02X} {:02X}\n'.format(toHexString(event.args[0]), *event.args[1:])
开发者ID:12019,项目名称:python-apducmd,代码行数:14,代码来源:apducmd.py

示例14: update

    def update(self, observable, actions):
        (addedcards, removedcards) = actions
        for card in addedcards:
            print("+Inserted: ", toHexString(card.atr))
            card.connection = card.createConnection()
            card.connection.connect()
            card.connection.addObserver(self.observer)
            apdu = SELECT + DF_TELECOM
            response, sw1, sw2 = card.connection.transmit(apdu)
            if sw1 == 0x9F:
                apdu = GET_RESPONSE + [sw2]
                response, sw1, sw2 = card.connection.transmit(apdu)

        for card in removedcards:
            print("-Removed: ", toHexString(card.atr))
开发者ID:shoaly,项目名称:pyscard,代码行数:15,代码来源:sample_MonitorCardsAndTransmit.py

示例15: get_smartcard_atr

def get_smartcard_atr(logger):
    """return the atr of the current device"""
    if logger is None:
        raise AttributeError

    try:
        readers_list = smartcard.System.readers()  # ottengo la lista dei lettori
    except pcsc.PCSCExceptions.EstablishContextException:
        logger.error("demone pcscd not attivo")  # il lettore di smartcard potrebbe non essere inserito
        return None

    # non sono riuscito a trovare nessun lettore
    if len(readers_list) == 0:
        logger.error("nessun lettore riconosciuto")
        return None

    reader = readers_list[0]  # di default prendo il primo lettore
    connection = reader.createConnection()
    try:
        # Mi connetto e ottengo l'ATR dalla carta
        connection.connect()
        atr_str = toHexString(connection.getATR()).replace(" ", ":").lower()
        connection.disconnect()
    except smartcard.Exceptions.CardConnectionException, errmsg:
        logger.error(errmsg)
        return None
开发者ID:libersoft,项目名称:firmapiu,代码行数:26,代码来源:SmartcardFetcher.py


注:本文中的smartcard.util.toHexString函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。