1
1
from .utils .compatibility import *
2
- from .utils .compatibility import intTypes
3
2
from .utils .base import Base64
4
3
from .utils .binary import BinaryAscii
5
4
from .utils .der import encodeSequence , encodeInteger , removeSequence , removeInteger
@@ -10,16 +9,16 @@ class Signature:
10
9
def __init__ (self , r , s , recoveryId = None ):
11
10
self .r = r
12
11
self .s = s
13
- self .recid = recoveryId
12
+ self .recoveryId = recoveryId
14
13
15
14
def toDer (self , withRecoveryId = False ):
16
15
encodedSequence = encodeSequence (encodeInteger (self .r ), encodeInteger (self .s ))
17
16
if not withRecoveryId :
18
17
return encodedSequence
19
- return chr (27 + self .recid ) + encodedSequence
18
+ return chr (27 + self .recoveryId ) + encodedSequence
20
19
21
20
def toBase64 (self , withRecoveryId = False ):
22
- return toString (Base64 .encode (toBytes (self .toDer (withRecoveryId ))))
21
+ return toString (Base64 .encode (toBytes (self .toDer (withRecoveryId = withRecoveryId ))))
23
22
24
23
@classmethod
25
24
def fromDer (cls , string , recoveryByte = False ):
@@ -28,6 +27,7 @@ def fromDer(cls, string, recoveryByte=False):
28
27
recoveryId = string [0 ] if isinstance (string [0 ], intTypes ) else ord (string [0 ])
29
28
recoveryId -= 27
30
29
string = string [1 :]
30
+
31
31
rs , empty = removeSequence (string )
32
32
if len (empty ) != 0 :
33
33
raise Exception ("trailing junk after DER signature: %s" % BinaryAscii .hexFromBinary (empty ))
@@ -36,7 +36,8 @@ def fromDer(cls, string, recoveryByte=False):
36
36
s , empty = removeInteger (rest )
37
37
if len (empty ) != 0 :
38
38
raise Exception ("trailing junk after DER numbers: %s" % BinaryAscii .hexFromBinary (empty ))
39
- return Signature (r , s , recoveryId )
39
+
40
+ return Signature (r = r , s = s , recoveryId = recoveryId )
40
41
41
42
@classmethod
42
43
def fromBase64 (cls , string , recoveryByte = False ):
0 commit comments