@@ -662,7 +662,10 @@ def create_signature(key_dict, data):
662662 The public and private keys are strings in PEM format.
663663
664664 data:
665- Data object used by create_signature() to generate the signature.
665+ Data to be signed. This should be a bytes object; data should be
666+ encoded/serialized before it is passed here. The same value can be be
667+ passed into securesystemslib.verify_signature() (along with the public
668+ key) to later verify the signature.
666669
667670 <Exceptions>
668671 securesystemslib.exceptions.FormatError, if 'key_dict' is improperly
@@ -702,17 +705,11 @@ def create_signature(key_dict, data):
702705 keyid = key_dict ['keyid' ]
703706 sig = None
704707
705- # Convert 'data' to canonical JSON format so that repeatable signatures are
706- # generated across different platforms and Python key dictionaries. The
707- # resulting 'data' is a string encoded in UTF-8 and compatible with the input
708- # expected by the cryptography functions called below.
709- data = securesystemslib .formats .encode_canonical (data )
710-
711708 if keytype == 'rsa' :
712709 if scheme == 'rsassa-pss-sha256' :
713710 private = private .replace ('\r \n ' , '\n ' )
714- sig , scheme = securesystemslib .pyca_crypto_keys .create_rsa_signature (private ,
715- data . encode ( 'utf-8' ) , scheme )
711+ sig , scheme = securesystemslib .pyca_crypto_keys .create_rsa_signature (
712+ private , data , scheme )
716713
717714 else :
718715 raise securesystemslib .exceptions .UnsupportedAlgorithmError ('Unsupported'
@@ -721,12 +718,12 @@ def create_signature(key_dict, data):
721718 elif keytype == 'ed25519' :
722719 public = binascii .unhexlify (public .encode ('utf-8' ))
723720 private = binascii .unhexlify (private .encode ('utf-8' ))
724- sig , scheme = securesystemslib .ed25519_keys .create_signature (public ,
725- private , data . encode ( 'utf-8' ) , scheme )
721+ sig , scheme = securesystemslib .ed25519_keys .create_signature (
722+ public , private , data , scheme )
726723
727724 elif keytype == 'ecdsa-sha2-nistp256' :
728- sig , scheme = securesystemslib .ecdsa_keys .create_signature (public , private ,
729- data . encode ( 'utf-8' ) , scheme )
725+ sig , scheme = securesystemslib .ecdsa_keys .create_signature (
726+ public , private , data , scheme )
730727
731728 # 'securesystemslib.formats.ANYKEY_SCHEMA' should have detected invalid key
732729 # types. This is a defensive check against an invalid key type.
@@ -795,8 +792,10 @@ def verify_signature(key_dict, signature, data):
795792 Conformant to 'securesystemslib.formats.SIGNATURE_SCHEMA'.
796793
797794 data:
798- Data object used by securesystemslib.rsa_key.create_signature() to
799- generate 'signature'. 'data' is needed here to verify the signature.
795+ Data that the signature is expected to be over. This should be a bytes
796+ object; data should be encoded/serialized before it is passed here.)
797+ This is the same value that can be passed into
798+ securesystemslib.create_signature() in order to create the signature.
800799
801800 <Exceptions>
802801 securesystemslib.exceptions.FormatError, raised if either 'key_dict' or
@@ -846,11 +845,6 @@ def verify_signature(key_dict, signature, data):
846845 scheme = key_dict ['scheme' ]
847846 valid_signature = False
848847
849- # Convert 'data' to canonical JSON format so that repeatable signatures are
850- # generated across different platforms and Python key dictionaries. The
851- # resulting 'data' is a string encoded in UTF-8 and compatible with the input
852- # expected by the cryptography functions called below.
853- data = securesystemslib .formats .encode_canonical (data ).encode ('utf-8' )
854848
855849 if keytype == 'rsa' :
856850 if scheme == 'rsassa-pss-sha256' :
0 commit comments