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
61
62 else:
63
64
65
66 if sys.version_info < (2, 7) or sys.version_info < (2, 7, 4):
68 else:
70
71
72
74
76 try:
77 b = bytearray(binascii.a2b_hex(s))
78 except Exception as e:
79 raise SyntaxError("base16 error: %s" % e)
80 return b
81
83 try:
84 b = bytearray(binascii.a2b_base64(s))
85 except Exception as e:
86 raise SyntaxError("base64 error: %s" % e)
87 return b
88
91
94
97
98
99
100
107
108
109 try:
110
111 getattr(ecdsa, 'NIST192p')
112 except AttributeError:
113 ecdsaAllCurves = False
114 else:
115 ecdsaAllCurves = True
116