1
2
3
4 """Miscellaneous functions to mask Python version differences."""
5
6 import sys
7 import os
8 import math
9 import binascii
10 import traceback
11 import ecdsa
12
13 if sys.version_info >= (3,0):
14
16
17
18
19
20
22
25
26
27
28
29
31 try:
32 b = bytearray(binascii.a2b_hex(bytearray(s, "ascii")))
33 except Exception as e:
34 raise SyntaxError("base16 error: %s" % e)
35 return b
36
38 try:
39 if isinstance(s, str):
40 s = bytearray(s, "ascii")
41 b = bytearray(binascii.a2b_base64(s))
42 except Exception as e:
43 raise SyntaxError("base64 error: %s" % e)
44 return b
45
47 return binascii.b2a_hex(b).decode("ascii")
48
51
53 return sys.stdin.buffer.read()
54
57
58 int_types = tuple([int])
59
63
64 else:
65
66
67
68 if sys.version_info < (2, 7) or sys.version_info < (2, 7, 4):
70 else:
72
73
74
76
78 try:
79 b = bytearray(binascii.a2b_hex(s))
80 except Exception as e:
81 raise SyntaxError("base16 error: %s" % e)
82 return b
83
85 try:
86 b = bytearray(binascii.a2b_base64(s))
87 except Exception as e:
88 raise SyntaxError("base64 error: %s" % e)
89 return b
90
93
96
99
100 int_types = (int, long)
101
102
103
104
111
112
113 try:
114
115 getattr(ecdsa, 'NIST192p')
116 except AttributeError:
117 ecdsaAllCurves = False
118 else:
119 ecdsaAllCurves = True
120