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 ecdsa
11
12 if sys.version_info >= (3,0):
13
15
16
17
18
19
21
24
25
26
27
28
30 try:
31 b = bytearray(binascii.a2b_hex(bytearray(s, "ascii")))
32 except Exception as e:
33 raise SyntaxError("base16 error: %s" % e)
34 return b
35
37 try:
38 b = bytearray(binascii.a2b_base64(bytearray(s, "ascii")))
39 except Exception as e:
40 raise SyntaxError("base64 error: %s" % e)
41 return b
42
44 return binascii.b2a_hex(b).decode("ascii")
45
48
50 return sys.stdin.buffer.read()
51
54
55 else:
56
57
58 if sys.version_info < (2,7):
60 else:
62
63
64
66
68 try:
69 b = bytearray(binascii.a2b_hex(s))
70 except Exception as e:
71 raise SyntaxError("base16 error: %s" % e)
72 return b
73
75 try:
76 b = bytearray(binascii.a2b_base64(s))
77 except Exception as e:
78 raise SyntaxError("base64 error: %s" % e)
79 return b
80
83
86
89
90 import traceback
94
95 try:
96
97 getattr(ecdsa, 'NIST192p')
98 except AttributeError:
99 ecdsaAllCurves = False
100 else:
101 ecdsaAllCurves = True
102