1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
From: shixuantong <sxt1001@foxmail.com>
Date: Wed, 13 Apr 2022 00:04:12 +0800
Subject: [PATCH] drop six
Forwarded: https://github.com/tlsfuzzer/python-ecdsa/pull/294
---
.travis.yml | 1 -
setup.py | 2 +-
src/ecdsa/__init__.py | 6 +-----
src/ecdsa/_compat.py | 4 +---
src/ecdsa/curves.py | 3 +--
src/ecdsa/der.py | 5 +++--
src/ecdsa/ecdsa.py | 3 ++-
src/ecdsa/ellipticcurve.py | 2 --
src/ecdsa/keys.py | 3 +--
src/ecdsa/numbertheory.py | 11 ++++-------
src/ecdsa/test_pyecdsa.py | 8 ++++----
src/ecdsa/util.py | 10 ++++------
tox.ini | 3 ---
13 files changed, 22 insertions(+), 39 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 8729ca8..1c5b8f6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -87,7 +87,6 @@ matrix:
env: PATH=/c/Python38:/c/Python38/Scripts:$PATH
install:
- pip list
- - pip install six
- pip install -r build-requirements.txt
- pip list
script:
diff --git a/setup.py b/setup.py
index 618f5e6..590e5c6 100755
--- a/setup.py
+++ b/setup.py
@@ -44,6 +44,6 @@ setup(
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
],
- install_requires=["six>=1.9.0"],
+ install_requires=[],
extras_require={"gmpy2": "gmpy2", "gmpy": "gmpy"},
)
diff --git a/src/ecdsa/__init__.py b/src/ecdsa/__init__.py
index 342538e..b2da298 100644
--- a/src/ecdsa/__init__.py
+++ b/src/ecdsa/__init__.py
@@ -1,6 +1,3 @@
-# while we don't use six in this file, we did bundle it for a long time, so
-# keep as part of module in a virtual way (through __all__)
-import six
from .keys import (
SigningKey,
VerifyingKey,
@@ -56,7 +53,6 @@ __all__ = [
"numbertheory",
"test_pyecdsa",
"util",
- "six",
]
_hush_pyflakes = [
@@ -90,7 +86,7 @@ _hush_pyflakes = [
SECP160r1,
Ed25519,
Ed448,
- six.b(""),
+ b"",
BRAINPOOLP160t1,
BRAINPOOLP192t1,
BRAINPOOLP224t1,
diff --git a/src/ecdsa/_compat.py b/src/ecdsa/_compat.py
index 4558e33..dd5ab78 100644
--- a/src/ecdsa/_compat.py
+++ b/src/ecdsa/_compat.py
@@ -4,13 +4,11 @@ Common functions for providing cross-python version compatibility.
import sys
import re
import binascii
-from six import integer_types
-
def str_idx_as_int(string, index):
"""Take index'th byte from string, return as integer"""
val = string[index]
- if isinstance(val, integer_types):
+ if isinstance(val, int):
return val
return ord(val)
diff --git a/src/ecdsa/curves.py b/src/ecdsa/curves.py
index 38e3a75..7662185 100644
--- a/src/ecdsa/curves.py
+++ b/src/ecdsa/curves.py
@@ -1,6 +1,5 @@
from __future__ import division
-from six import PY2
from . import der, ecdsa, ellipticcurve, eddsa
from .util import orderlen, number_to_string, string_to_number
from ._compat import normalise_bytes, bit_length
@@ -269,7 +268,7 @@ class Curve:
and ``explicit``
:type valid_encodings: :term:`set-like object`
"""
- if not PY2 and isinstance(string, str): # pragma: no branch
+ if isinstance(string, str): # pragma: no branch
string = string.encode()
ec_param_index = string.find(b"-----BEGIN EC PARAMETERS-----")
diff --git a/src/ecdsa/der.py b/src/ecdsa/der.py
index 7a06b68..fab1e0b 100644
--- a/src/ecdsa/der.py
+++ b/src/ecdsa/der.py
@@ -4,9 +4,10 @@ import binascii
import base64
import warnings
from itertools import chain
-from six import int2byte, text_type
from ._compat import compat26_str, str_idx_as_int
+import struct
+int2byte = struct.Struct(">B").pack
class UnexpectedDER(Exception):
pass
@@ -455,7 +456,7 @@ def remove_bitstring(string, expect_unused=_sentry):
def unpem(pem):
- if isinstance(pem, text_type): # pragma: no branch
+ if isinstance(pem, str): # pragma: no branch
pem = pem.encode()
d = b"".join(
diff --git a/src/ecdsa/ecdsa.py b/src/ecdsa/ecdsa.py
index f710965..7e1da5e 100644
--- a/src/ecdsa/ecdsa.py
+++ b/src/ecdsa/ecdsa.py
@@ -65,12 +65,13 @@ modified as part of the python-ecdsa package.
"""
import warnings
-from six import int2byte
from . import ellipticcurve
from . import numbertheory
from .util import bit_length
from ._compat import remove_whitespace
+import struct
+int2byte = struct.Struct(">B").pack
class RSZeroError(RuntimeError):
pass
diff --git a/src/ecdsa/ellipticcurve.py b/src/ecdsa/ellipticcurve.py
index a982c1e..0e9db2e 100644
--- a/src/ecdsa/ellipticcurve.py
+++ b/src/ecdsa/ellipticcurve.py
@@ -47,14 +47,12 @@ except ImportError: # pragma: no branch
GMPY = False
-from six import python_2_unicode_compatible
from . import numbertheory
from ._compat import normalise_bytes, int_to_bytes, bit_length, bytes_to_int
from .errors import MalformedPointError
from .util import orderlen, string_to_number, number_to_string
-@python_2_unicode_compatible
class CurveFp(object):
"""
:term:`Short Weierstrass Elliptic Curve <short Weierstrass curve>` over a
diff --git a/src/ecdsa/keys.py b/src/ecdsa/keys.py
index f74252c..75e059f 100644
--- a/src/ecdsa/keys.py
+++ b/src/ecdsa/keys.py
@@ -5,7 +5,6 @@ Primary classes for performing signing and verification operations.
import binascii
from hashlib import sha1
import os
-from six import PY2
from . import ecdsa, eddsa
from . import der, ssh
from . import rfc6979
@@ -963,7 +962,7 @@ class SigningKey(object):
:return: Initialised SigningKey object
:rtype: SigningKey
"""
- if not PY2 and isinstance(string, str): # pragma: no branch
+ if isinstance(string, str): # pragma: no branch
string = string.encode()
# The privkey pem may have multiple sections, commonly it also has
diff --git a/src/ecdsa/numbertheory.py b/src/ecdsa/numbertheory.py
index fe974f8..3a9b213 100644
--- a/src/ecdsa/numbertheory.py
+++ b/src/ecdsa/numbertheory.py
@@ -12,8 +12,9 @@
from __future__ import division
import sys
-from six import integer_types, PY2
-from six.moves import reduce
+from functools import reduce
+
+integer_types = int,
try:
xrange
@@ -218,11 +219,7 @@ def square_root_mod_prime(a, p):
assert d == p - 1
return (2 * a * pow(4 * a, (p - 5) // 8, p)) % p
- if PY2:
- # xrange on python2 can take integers representable as C long only
- range_top = min(0x7FFFFFFF, p)
- else:
- range_top = p
+ range_top = p
for b in xrange(2, range_top): # pragma: no branch
if jacobi(b * b - 4 * a, p) == -1:
f = (a, -b, 1)
diff --git a/src/ecdsa/test_pyecdsa.py b/src/ecdsa/test_pyecdsa.py
index 7a16d65..6a9e736 100644
--- a/src/ecdsa/test_pyecdsa.py
+++ b/src/ecdsa/test_pyecdsa.py
@@ -16,7 +16,6 @@ from functools import partial
from hypothesis import given, settings
import hypothesis.strategies as st
-from six import binary_type
from .keys import SigningKey, VerifyingKey
from .keys import BadSignatureError, MalformedPointError, BadDigestError
from . import util
@@ -70,6 +69,7 @@ from . import der
from . import rfc6979
from . import ecdsa
+binary_type = bytes
class SubprocessError(Exception):
pass
@@ -293,7 +293,7 @@ class ECDSA(unittest.TestCase):
priv1 = SigningKey.generate()
pub1 = priv1.get_verifying_key()
s1 = pub1.to_string()
- self.assertEqual(type(s1), binary_type)
+ self.assertEqual(type(s1), bytes)
self.assertEqual(len(s1), NIST192p.verifying_key_length)
pub2 = VerifyingKey.from_string(s1)
self.assertTruePubkeysEqual(pub1, pub2)
@@ -345,13 +345,13 @@ class ECDSA(unittest.TestCase):
priv1 = SigningKey.generate(curve=BRAINPOOLP512r1)
pub1 = priv1.get_verifying_key()
s1 = pub1.to_string()
- self.assertEqual(type(s1), binary_type)
+ self.assertEqual(type(s1), bytes)
self.assertEqual(len(s1), BRAINPOOLP512r1.verifying_key_length)
pub2 = VerifyingKey.from_string(s1, curve=BRAINPOOLP512r1)
self.assertTruePubkeysEqual(pub1, pub2)
pub1_der = pub1.to_der()
- self.assertEqual(type(pub1_der), binary_type)
+ self.assertEqual(type(pub1_der), bytes)
pub2 = VerifyingKey.from_der(pub1_der)
self.assertTruePubkeysEqual(pub1, pub2)
diff --git a/src/ecdsa/util.py b/src/ecdsa/util.py
index 1aff5bf..3dcb4d0 100644
--- a/src/ecdsa/util.py
+++ b/src/ecdsa/util.py
@@ -18,10 +18,11 @@ import math
import binascii
import sys
from hashlib import sha256
-from six import PY2, int2byte, next
from . import der
from ._compat import normalise_bytes
+import struct
+int2byte = struct.Struct(">B").pack
# RFC5480:
# The "unrestricted" algorithm identifier is:
@@ -111,10 +112,7 @@ class PRNG:
def __call__(self, numbytes):
a = [next(self.generator) for i in range(numbytes)]
- if PY2: # pragma: no branch
- return "".join(a)
- else:
- return bytes(a)
+ return bytes(a)
def block_generator(self, seed):
counter = 0
@@ -185,7 +183,7 @@ def randrange_from_seed__truncate_bits(seed, order, hashmod=sha256):
base = "\x00" * (maxbytes - len(base)) + base
topbits = 8 * maxbytes - bits
if topbits:
- base = int2byte(ord(base[0]) & lsb_of_ones(topbits)) + base[1:]
+ base = bytes((ord(base[0]) & lsb_of_ones(topbits),)) + base[1:]
number = 1 + int(binascii.hexlify(base), 16)
assert 1 <= number < order
return number
diff --git a/tox.ini b/tox.ini
index 19c0317..19b235c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -12,8 +12,6 @@ deps =
gmpypy{27,39,310,311,312,313}: gmpy
gmpy{2py27,2py39,2py310,2py311,2py312,2py313,py27,py39,py310,py311,py312,py313}: pytest
gmpy{2py27,2py39,2py310,2py311,2py312,2py313,py27,py39,py310,py311,py312,py313}: hypothesis
-# six==1.9.0 comes from setup.py install_requires
- py27_old_six: six==1.9.0
py27_old_six: pytest
py27_old_six: hypothesis
# those are the oldest versions of gmpy and gmpy2 on PyPI (i.e. oldest we can
@@ -82,7 +80,6 @@ deps =
hypothesis
pytest>=4.6.0
coverage
- six
commands =
instrumental -t ecdsa -i '.*test_.*|.*_version|.*_compat|.*_sha3' {envbindir}/pytest {posargs:src/ecdsa}
instrumental -f .instrumental.cov -sr
|