@@ -338,7 +338,7 @@ def send_large_message3(self, payload=None, msg=None, slot_id=101, key_type=1):
338338 self .send_message (payload = current_payload , msg = msg )
339339 return
340340
341- def read_bytes (self , n = 64 , to_bytes = False , timeout_ms = 100 ):
341+ def read_bytes (self , n = 64 , to_str = False , timeout_ms = 100 ):
342342 """Read n bytes and return an array of uint8 (int)."""
343343 out = self ._hid .read (n , timeout_ms = timeout_ms )
344344 logging .debug ('read="%s"' , '' .join ([chr (c ) for c in out ]))
@@ -367,9 +367,9 @@ def read_bytes(self, n=64, to_bytes=False, timeout_ms=100):
367367 elif outstr .decode (errors = "ignore" ).find ("Error no key set in this slot" ) != - 1 :
368368 raise RuntimeError ('Error no key set in this slot' )
369369
370- if to_bytes :
370+ if to_str :
371371 # Returns the bytes a string if requested
372- return bytes (out )
372+ return '' . join ([ bytes (c ) for c in out ] )
373373
374374 # Returns the raw list
375375 return out
@@ -490,7 +490,7 @@ def get_button(byte):
490490 ok_sign1 = ''
491491 while ok_sign1 == '' :
492492 time .sleep (0.5 )
493- ok_sign1 = self .read_bytes (64 , to_bytes = True )
493+ ok_sign1 = self .read_bytes (64 , to_str = True )
494494 print (type (ok_sign1 ))
495495
496496 print ()
@@ -499,7 +499,7 @@ def get_button(byte):
499499
500500 print ('Trying to read the signature part 2...' )
501501 for _ in range (10 ):
502- ok_sign2 = self .read_bytes (64 , to_bytes = True )
502+ ok_sign2 = self .read_bytes (64 , to_str = True )
503503 if len (ok_sign2 ) == 64 :
504504 break
505505
@@ -509,7 +509,7 @@ def get_button(byte):
509509
510510 print ('Trying to read the signature part 3...' )
511511 for _ in range (10 ):
512- ok_sign3 = self .read_bytes (64 , to_bytes = True )
512+ ok_sign3 = self .read_bytes (64 , to_str = True )
513513 if len (ok_sign3 ) == 64 :
514514 break
515515
@@ -520,7 +520,7 @@ def get_button(byte):
520520
521521 print ('Trying to read the signature part 4...' )
522522 for _ in range (10 ):
523- ok_sign4 = self .read_bytes (64 , to_bytes = True )
523+ ok_sign4 = self .read_bytes (64 , to_str = True )
524524 if len (ok_sign4 ) == 64 :
525525 break
526526
@@ -531,7 +531,7 @@ def get_button(byte):
531531
532532 print ('Trying to read the signature part 5...' )
533533 for _ in range (10 ):
534- ok_sign5 = self .read_bytes (64 , to_bytes = True )
534+ ok_sign5 = self .read_bytes (64 , to_str = True )
535535 if len (ok_sign5 ) == 64 :
536536 break
537537
@@ -542,7 +542,7 @@ def get_button(byte):
542542
543543 print ('Trying to read the signature part 6...' )
544544 for _ in range (10 ):
545- ok_sign6 = self .read_bytes (64 , to_bytes = True )
545+ ok_sign6 = self .read_bytes (64 , to_str = True )
546546 if len (ok_sign6 ) == 64 :
547547 break
548548
@@ -553,7 +553,7 @@ def get_button(byte):
553553
554554 print ('Trying to read the signature part 7...' )
555555 for _ in range (10 ):
556- ok_sign7 = self .read_bytes (64 , to_bytes = True )
556+ ok_sign7 = self .read_bytes (64 , to_str = True )
557557 if len (ok_sign7 ) == 64 :
558558 break
559559
@@ -564,7 +564,7 @@ def get_button(byte):
564564
565565 print ('Trying to read the signature part 8...' )
566566 for _ in range (10 ):
567- ok_sign8 = self .read_bytes (64 , to_bytes = True )
567+ ok_sign8 = self .read_bytes (64 , to_str = True )
568568 if len (ok_sign8 ) == 64 :
569569 break
570570
@@ -607,15 +607,15 @@ def getpub(self):
607607 ok_pubkey1 = ''
608608 while ok_pubkey1 == '' :
609609 time .sleep (0.5 )
610- ok_pubkey1 = self .read_bytes (64 , to_bytes = True )
610+ ok_pubkey1 = self .read_bytes (64 , to_str = True )
611611
612612 print ()
613613
614614 print ('received=' , repr (ok_pubkey1 ))
615615
616616 print ('Trying to read the public RSA N part 2...' )
617617 for _ in range (10 ):
618- ok_pubkey2 = self .read_bytes (64 , to_bytes = True )
618+ ok_pubkey2 = self .read_bytes (64 , to_str = True )
619619 if len (ok_pubkey2 ) == 64 :
620620 break
621621
@@ -625,7 +625,7 @@ def getpub(self):
625625
626626 print ('Trying to read the public RSA N part 3...' )
627627 for _ in range (10 ):
628- ok_pubkey3 = self .read_bytes (64 , to_bytes = True )
628+ ok_pubkey3 = self .read_bytes (64 , to_str = True )
629629 if len (ok_pubkey3 ) == 64 :
630630 break
631631
@@ -636,7 +636,7 @@ def getpub(self):
636636
637637 print ('Trying to read the public RSA N part 4...' )
638638 for _ in range (10 ):
639- ok_pubkey4 = self .read_bytes (64 , to_bytes = True )
639+ ok_pubkey4 = self .read_bytes (64 , to_str = True )
640640 if len (ok_pubkey4 ) == 64 :
641641 break
642642
@@ -647,7 +647,7 @@ def getpub(self):
647647
648648 print ('Trying to read the public RSA N part 5...' )
649649 for _ in range (10 ):
650- ok_pubkey5 = self .read_bytes (64 , to_bytes = True )
650+ ok_pubkey5 = self .read_bytes (64 , to_str = True )
651651 if len (ok_pubkey5 ) == 64 :
652652 break
653653
@@ -658,7 +658,7 @@ def getpub(self):
658658
659659 print ('Trying to read the public RSA N part 6...' )
660660 for _ in range (10 ):
661- ok_pubkey6 = self .read_bytes (64 , to_bytes = True )
661+ ok_pubkey6 = self .read_bytes (64 , to_str = True )
662662 if len (ok_pubkey6 ) == 64 :
663663 break
664664
@@ -668,7 +668,7 @@ def getpub(self):
668668
669669 print ('Trying to read the public RSA N part 7...' )
670670 for _ in range (10 ):
671- ok_pubkey7 = self .read_bytes (64 , to_bytes = True )
671+ ok_pubkey7 = self .read_bytes (64 , to_str = True )
672672 if len (ok_pubkey7 ) == 64 :
673673 break
674674
@@ -678,7 +678,7 @@ def getpub(self):
678678 print ('Trying to read the public RSA N part 8...' )
679679
680680 for _ in range (10 ):
681- ok_pubkey8 = self .read_bytes (64 , to_bytes = True )
681+ ok_pubkey8 = self .read_bytes (64 , to_str = True )
682682 if len (ok_pubkey8 ) == 64 :
683683 break
684684
@@ -738,7 +738,7 @@ def get_button(byte):
738738 ok_decrypted = ''
739739 while ok_decrypted == '' :
740740 time .sleep (0.5 )
741- ok_decrypted = self .read_bytes (64 , to_bytes = True )
741+ ok_decrypted = self .read_bytes (64 , to_str = True )
742742
743743 print ('Decrypted by OnlyKey, data=' , repr (ok_decrypted ))
744744
@@ -755,7 +755,7 @@ def generate_backup_key(self):
755755
756756 log .info ('Trying to read the private key...' )
757757 for _ in range (2 ):
758- ok_priv = self .read_bytes (64 , to_bytes = True , timeout_ms = 10 )
758+ ok_priv = self .read_bytes (64 , to_str = True , timeout_ms = 10 )
759759 if len (ok_priv ) == 64 :
760760 break
761761
0 commit comments