aboutsummaryrefslogtreecommitdiff
path: root/frozen_deps/ecdsa/der.py
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2024-08-23 03:14:03 +0000
committerDeterminant <[email protected]>2024-08-22 20:34:57 -0700
commit8d1c76ec7caf247d5675e14260d20fc508977ffb (patch)
tree8fa7c8ce3b7e3f4ece150a6da5922b5eb2dc7772 /frozen_deps/ecdsa/der.py
parent258780284151d49cba1d9c0d2ce33f9a19bb058b (diff)
release v0.1.8
Diffstat (limited to 'frozen_deps/ecdsa/der.py')
-rw-r--r--frozen_deps/ecdsa/der.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/frozen_deps/ecdsa/der.py b/frozen_deps/ecdsa/der.py
index 8b27941..b291485 100644
--- a/frozen_deps/ecdsa/der.py
+++ b/frozen_deps/ecdsa/der.py
@@ -4,8 +4,8 @@ import binascii
import base64
import warnings
from itertools import chain
-from six import int2byte, b, text_type
-from ._compat import str_idx_as_int
+from six import int2byte, text_type
+from ._compat import compat26_str, str_idx_as_int
class UnexpectedDER(Exception):
@@ -20,16 +20,16 @@ def encode_integer(r):
assert r >= 0 # can't support negative numbers yet
h = ("%x" % r).encode()
if len(h) % 2:
- h = b("0") + h
+ h = b"0" + h
s = binascii.unhexlify(h)
num = str_idx_as_int(s, 0)
if num <= 0x7F:
- return b("\x02") + encode_length(len(s)) + s
+ return b"\x02" + encode_length(len(s)) + s
else:
# DER integers are two's complement, so if the first byte is
# 0x80-0xff then we need an extra 0x00 byte to prevent it from
# looking negative.
- return b("\x02") + encode_length(len(s) + 1) + b("\x00") + s
+ return b"\x02" + encode_length(len(s) + 1) + b"\x00" + s
# sentry object to check if an argument was specified (used to detect
@@ -91,11 +91,11 @@ def encode_bitstring(s, unused=_sentry):
raise ValueError("unused bits must be zeros in DER")
encoded_unused = int2byte(unused)
len_extra = 1
- return b("\x03") + encode_length(len(s) + len_extra) + encoded_unused + s
+ return b"\x03" + encode_length(len(s) + len_extra) + encoded_unused + s
def encode_octet_string(s):
- return b("\x04") + encode_length(len(s)) + s
+ return b"\x04" + encode_length(len(s)) + s
def encode_oid(first, second, *pieces):
@@ -111,7 +111,7 @@ def encode_oid(first, second, *pieces):
def encode_sequence(*encoded_pieces):
total_len = sum([len(p) for p in encoded_pieces])
- return b("\x30") + encode_length(total_len) + b("").join(encoded_pieces)
+ return b"\x30" + encode_length(total_len) + b"".join(encoded_pieces)
def encode_number(n):
@@ -122,7 +122,7 @@ def encode_number(n):
if not b128_digits:
b128_digits.append(0)
b128_digits[-1] &= 0x7F
- return b("").join([int2byte(d) for d in b128_digits])
+ return b"".join([int2byte(d) for d in b128_digits])
def is_sequence(string):
@@ -254,7 +254,7 @@ def encode_length(l):
return int2byte(l)
s = ("%x" % l).encode()
if len(s) % 2:
- s = b("0") + s
+ s = b"0" + s
s = binascii.unhexlify(s)
llen = len(s)
return int2byte(0x80 | llen) + s
@@ -389,21 +389,21 @@ def unpem(pem):
if isinstance(pem, text_type): # pragma: no branch
pem = pem.encode()
- d = b("").join(
+ d = b"".join(
[
l.strip()
- for l in pem.split(b("\n"))
- if l and not l.startswith(b("-----"))
+ for l in pem.split(b"\n")
+ if l and not l.startswith(b"-----")
]
)
return base64.b64decode(d)
def topem(der, name):
- b64 = base64.b64encode(der)
+ b64 = base64.b64encode(compat26_str(der))
lines = [("-----BEGIN %s-----\n" % name).encode()]
lines.extend(
- [b64[start : start + 64] + b("\n") for start in range(0, len(b64), 64)]
+ [b64[start : start + 76] + b"\n" for start in range(0, len(b64), 76)]
)
lines.append(("-----END %s-----\n" % name).encode())
- return b("").join(lines)
+ return b"".join(lines)