@@ -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_str = False , timeout_ms = 100 ):
341+ def read_bytes (self , n = 64 , to_bytes = 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 ]))
@@ -353,9 +353,9 @@ def read_bytes(self, n=64, to_str=False, timeout_ms=100):
353353 elif outstr .decode (errors = "ignore" ).find ("Timeout occured while waiting for confirmation on OnlyKey" ) != - 1 :
354354 raise RuntimeError ('Timeout occured while waiting for confirmation on OnlyKey' )
355355
356- if to_str :
356+ if to_bytes :
357357 # Returns the bytes a string if requested
358- return '' . join ([ bytes (c ) for c in out ] )
358+ return bytes (out )
359359
360360 # Returns the raw list
361361 return out
@@ -476,7 +476,7 @@ def get_button(byte):
476476 ok_sign1 = ''
477477 while ok_sign1 == '' :
478478 time .sleep (0.5 )
479- ok_sign1 = self .read_bytes (64 , to_str = True )
479+ ok_sign1 = self .read_bytes (64 , to_bytes = True )
480480 print (type (ok_sign1 ))
481481
482482 print ()
@@ -485,7 +485,7 @@ def get_button(byte):
485485
486486 print ('Trying to read the signature part 2...' )
487487 for _ in range (10 ):
488- ok_sign2 = self .read_bytes (64 , to_str = True )
488+ ok_sign2 = self .read_bytes (64 , to_bytes = True )
489489 if len (ok_sign2 ) == 64 :
490490 break
491491
@@ -495,7 +495,7 @@ def get_button(byte):
495495
496496 print ('Trying to read the signature part 3...' )
497497 for _ in range (10 ):
498- ok_sign3 = self .read_bytes (64 , to_str = True )
498+ ok_sign3 = self .read_bytes (64 , to_bytes = True )
499499 if len (ok_sign3 ) == 64 :
500500 break
501501
@@ -506,7 +506,7 @@ def get_button(byte):
506506
507507 print ('Trying to read the signature part 4...' )
508508 for _ in range (10 ):
509- ok_sign4 = self .read_bytes (64 , to_str = True )
509+ ok_sign4 = self .read_bytes (64 , to_bytes = True )
510510 if len (ok_sign4 ) == 64 :
511511 break
512512
@@ -517,7 +517,7 @@ def get_button(byte):
517517
518518 print ('Trying to read the signature part 5...' )
519519 for _ in range (10 ):
520- ok_sign5 = self .read_bytes (64 , to_str = True )
520+ ok_sign5 = self .read_bytes (64 , to_bytes = True )
521521 if len (ok_sign5 ) == 64 :
522522 break
523523
@@ -528,7 +528,7 @@ def get_button(byte):
528528
529529 print ('Trying to read the signature part 6...' )
530530 for _ in range (10 ):
531- ok_sign6 = self .read_bytes (64 , to_str = True )
531+ ok_sign6 = self .read_bytes (64 , to_bytes = True )
532532 if len (ok_sign6 ) == 64 :
533533 break
534534
@@ -539,7 +539,7 @@ def get_button(byte):
539539
540540 print ('Trying to read the signature part 7...' )
541541 for _ in range (10 ):
542- ok_sign7 = self .read_bytes (64 , to_str = True )
542+ ok_sign7 = self .read_bytes (64 , to_bytes = True )
543543 if len (ok_sign7 ) == 64 :
544544 break
545545
@@ -550,7 +550,7 @@ def get_button(byte):
550550
551551 print ('Trying to read the signature part 8...' )
552552 for _ in range (10 ):
553- ok_sign8 = self .read_bytes (64 , to_str = True )
553+ ok_sign8 = self .read_bytes (64 , to_bytes = True )
554554 if len (ok_sign8 ) == 64 :
555555 break
556556
@@ -593,15 +593,15 @@ def getpub(self):
593593 ok_pubkey1 = ''
594594 while ok_pubkey1 == '' :
595595 time .sleep (0.5 )
596- ok_pubkey1 = self .read_bytes (64 , to_str = True )
596+ ok_pubkey1 = self .read_bytes (64 , to_bytes = True )
597597
598598 print ()
599599
600600 print ('received=' , repr (ok_pubkey1 ))
601601
602602 print ('Trying to read the public RSA N part 2...' )
603603 for _ in range (10 ):
604- ok_pubkey2 = self .read_bytes (64 , to_str = True )
604+ ok_pubkey2 = self .read_bytes (64 , to_bytes = True )
605605 if len (ok_pubkey2 ) == 64 :
606606 break
607607
@@ -611,7 +611,7 @@ def getpub(self):
611611
612612 print ('Trying to read the public RSA N part 3...' )
613613 for _ in range (10 ):
614- ok_pubkey3 = self .read_bytes (64 , to_str = True )
614+ ok_pubkey3 = self .read_bytes (64 , to_bytes = True )
615615 if len (ok_pubkey3 ) == 64 :
616616 break
617617
@@ -622,7 +622,7 @@ def getpub(self):
622622
623623 print ('Trying to read the public RSA N part 4...' )
624624 for _ in range (10 ):
625- ok_pubkey4 = self .read_bytes (64 , to_str = True )
625+ ok_pubkey4 = self .read_bytes (64 , to_bytes = True )
626626 if len (ok_pubkey4 ) == 64 :
627627 break
628628
@@ -633,7 +633,7 @@ def getpub(self):
633633
634634 print ('Trying to read the public RSA N part 5...' )
635635 for _ in range (10 ):
636- ok_pubkey5 = self .read_bytes (64 , to_str = True )
636+ ok_pubkey5 = self .read_bytes (64 , to_bytes = True )
637637 if len (ok_pubkey5 ) == 64 :
638638 break
639639
@@ -644,7 +644,7 @@ def getpub(self):
644644
645645 print ('Trying to read the public RSA N part 6...' )
646646 for _ in range (10 ):
647- ok_pubkey6 = self .read_bytes (64 , to_str = True )
647+ ok_pubkey6 = self .read_bytes (64 , to_bytes = True )
648648 if len (ok_pubkey6 ) == 64 :
649649 break
650650
@@ -654,7 +654,7 @@ def getpub(self):
654654
655655 print ('Trying to read the public RSA N part 7...' )
656656 for _ in range (10 ):
657- ok_pubkey7 = self .read_bytes (64 , to_str = True )
657+ ok_pubkey7 = self .read_bytes (64 , to_bytes = True )
658658 if len (ok_pubkey7 ) == 64 :
659659 break
660660
@@ -664,7 +664,7 @@ def getpub(self):
664664 print ('Trying to read the public RSA N part 8...' )
665665
666666 for _ in range (10 ):
667- ok_pubkey8 = self .read_bytes (64 , to_str = True )
667+ ok_pubkey8 = self .read_bytes (64 , to_bytes = True )
668668 if len (ok_pubkey8 ) == 64 :
669669 break
670670
@@ -724,7 +724,7 @@ def get_button(byte):
724724 ok_decrypted = ''
725725 while ok_decrypted == '' :
726726 time .sleep (0.5 )
727- ok_decrypted = self .read_bytes (64 , to_str = True )
727+ ok_decrypted = self .read_bytes (64 , to_bytes = True )
728728
729729 print ('Decrypted by OnlyKey, data=' , repr (ok_decrypted ))
730730
@@ -741,7 +741,7 @@ def generate_backup_key(self):
741741
742742 log .info ('Trying to read the private key...' )
743743 for _ in range (2 ):
744- ok_priv = self .read_bytes (64 , to_str = True , timeout_ms = 10 )
744+ ok_priv = self .read_bytes (64 , to_bytes = True , timeout_ms = 10 )
745745 if len (ok_priv ) == 64 :
746746 break
747747
0 commit comments