Skip to content

Commit

Permalink
new black, not quite the same as the old black (#624)
Browse files Browse the repository at this point in the history
* new black, not quite the same as the old black

* remove a pointless line
  • Loading branch information
reaperhulk committed Aug 27, 2020
1 parent 383cdcc commit 732c484
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 32 deletions.
8 changes: 5 additions & 3 deletions docs/vectors/python/argondriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ def __init__(self, args):
self.count = 0

def _runOnce(self, passwd, salt, dgst_len, maxmem, iters):
"""
"""
argv = [
self.exe,
salt.encode("ascii"),
Expand Down Expand Up @@ -112,7 +110,11 @@ def __iter__(self):
)
p.add_argument("-v", "--version", dest="version", type=str, default="13")
p.add_argument(
"-e", "--encoded", dest="encoded", default=False, action="store_true",
"-e",
"--encoded",
dest="encoded",
default=False,
action="store_true",
)
p.add_argument(
"-s", "--min-salt-len", dest="mnsaltlen", type=int, default=8
Expand Down
4 changes: 3 additions & 1 deletion release.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def download_artifacts_github_actions(session, token, run_url):
continue
p = z.open(name)
out_path = os.path.join(
os.path.dirname(__file__), "dist", os.path.basename(name),
os.path.dirname(__file__),
"dist",
os.path.basename(name),
)
with open(out_path, "wb") as f:
f.write(p.read())
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ def run(self):
os.path.join(build_clib.build_clib, "include"),
)
self.library_dirs.insert(
0, os.path.join(build_clib.build_clib, "lib64"),
0,
os.path.join(build_clib.build_clib, "lib64"),
)
self.library_dirs.insert(
0, os.path.join(build_clib.build_clib, "lib"),
0,
os.path.join(build_clib.build_clib, "lib"),
)

return _build_ext.run(self)
Expand Down
24 changes: 19 additions & 5 deletions src/nacl/bindings/crypto_secretstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def crypto_secretstream_xchacha20poly1305_keygen():
"""
keybuf = ffi.new(
"unsigned char[]", crypto_secretstream_xchacha20poly1305_KEYBYTES,
"unsigned char[]",
crypto_secretstream_xchacha20poly1305_KEYBYTES,
)
lib.crypto_secretstream_xchacha20poly1305_keygen(keybuf)
return ffi.buffer(keybuf)[:]
Expand Down Expand Up @@ -112,7 +113,8 @@ def crypto_secretstream_xchacha20poly1305_init_push(state, key):
)

headerbuf = ffi.new(
"unsigned char []", crypto_secretstream_xchacha20poly1305_HEADERBYTES,
"unsigned char []",
crypto_secretstream_xchacha20poly1305_HEADERBYTES,
)

rc = lib.crypto_secretstream_xchacha20poly1305_init_push(
Expand All @@ -124,7 +126,10 @@ def crypto_secretstream_xchacha20poly1305_init_push(state, key):


def crypto_secretstream_xchacha20poly1305_push(
state, m, ad=None, tag=crypto_secretstream_xchacha20poly1305_TAG_MESSAGE,
state,
m,
ad=None,
tag=crypto_secretstream_xchacha20poly1305_TAG_MESSAGE,
):
"""
Add an encrypted message to the secret stream.
Expand Down Expand Up @@ -173,7 +178,14 @@ def crypto_secretstream_xchacha20poly1305_push(
adlen = len(ad)

rc = lib.crypto_secretstream_xchacha20poly1305_push(
state.statebuf, state.rawbuf, ffi.NULL, m, len(m), ad, adlen, tag,
state.statebuf,
state.rawbuf,
ffi.NULL,
m,
len(m),
ad,
adlen,
tag,
)
ensure(rc == 0, "Unexpected failure", raising=exc.RuntimeError)

Expand Down Expand Up @@ -260,7 +272,9 @@ def crypto_secretstream_xchacha20poly1305_pull(state, c, ad=None):
raising=exc.ValueError,
)
ensure(
isinstance(c, bytes), "Ciphertext is not bytes", raising=exc.TypeError,
isinstance(c, bytes),
"Ciphertext is not bytes",
raising=exc.TypeError,
)
ensure(
len(c) >= crypto_secretstream_xchacha20poly1305_ABYTES,
Expand Down
12 changes: 9 additions & 3 deletions src/nacl/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def encrypt(self, plaintext, nonce=None, encoder=encoding.RawEncoder):
)

ciphertext = nacl.bindings.crypto_box_afternm(
plaintext, nonce, self._shared_key,
plaintext,
nonce,
self._shared_key,
)

encoded_nonce = encoder.encode(nonce)
Expand Down Expand Up @@ -267,7 +269,9 @@ def decrypt(self, ciphertext, nonce=None, encoder=encoding.RawEncoder):
)

plaintext = nacl.bindings.crypto_box_open_afternm(
ciphertext, nonce, self._shared_key,
ciphertext,
nonce,
self._shared_key,
)

return plaintext
Expand Down Expand Up @@ -364,7 +368,9 @@ def decrypt(self, ciphertext, encoder=encoding.RawEncoder):
ciphertext = encoder.decode(ciphertext)

plaintext = nacl.bindings.crypto_box_seal_open(
ciphertext, self._public_key, self._private_key,
ciphertext,
self._public_key,
self._private_key,
)

return plaintext
4 changes: 3 additions & 1 deletion tests/test_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def test_secretbox():

with pytest.raises(CryptoError):
c.crypto_secretbox_open(
msg + b"!", nonce, key,
msg + b"!",
nonce,
key,
)


Expand Down
14 changes: 10 additions & 4 deletions tests/test_kx.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def test_crypto_kx_keypair():


@given(
binary(min_size=32, max_size=32), binary(min_size=32, max_size=32),
binary(min_size=32, max_size=32),
binary(min_size=32, max_size=32),
)
@settings(max_examples=100)
def test_crypto_kx_seed_keypair(seed1, seed2):
Expand All @@ -43,22 +44,27 @@ def test_crypto_kx_seed_keypair(seed1, seed2):
assert seeded == seeded_other


@given(binary(min_size=33, max_size=128),)
@given(
binary(min_size=33, max_size=128),
)
@settings(max_examples=20, suppress_health_check=[HealthCheck.too_slow])
def test_crypto_kx_seed_keypair_seed_too_large(seed):
with pytest.raises(exc.TypeError):
b.crypto_kx_seed_keypair(seed)


@given(binary(min_size=0, max_size=31),)
@given(
binary(min_size=0, max_size=31),
)
@settings(max_examples=20)
def test_crypto_kx_seed_keypair_seed_too_small(seed):
with pytest.raises(exc.TypeError):
b.crypto_kx_seed_keypair(seed)


@given(
binary(min_size=32, max_size=32), binary(min_size=32, max_size=32),
binary(min_size=32, max_size=32),
binary(min_size=32, max_size=32),
)
@settings(max_examples=100)
def test_crypto_kx_session_keys(seed1, seed2):
Expand Down
28 changes: 24 additions & 4 deletions tests/test_pwhash.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ def test_wrong_salt_length(size, password, salt, opslimit, memlimit):
)
@pytest.mark.parametrize(
("passwd_hash", "password"),
[(b"Too short (and wrong) hash", b"a password",)],
[
(
b"Too short (and wrong) hash",
b"a password",
)
],
)
def test_wrong_hash_length(passwd_hash, password):
with pytest.raises(exc.ValueError):
Expand Down Expand Up @@ -232,7 +237,12 @@ def test_kdf_wrong_salt_length(size, password, salt, opslimit, memlimit):
)
@pytest.mark.parametrize(
("passwd_hash", "password"),
[(b"Too short (and wrong) hash", b"another password",)],
[
(
b"Too short (and wrong) hash",
b"another password",
)
],
)
def test_str_verify_wrong_hash_length(passwd_hash, password):
with pytest.raises(exc.ValueError):
Expand Down Expand Up @@ -325,7 +335,12 @@ def test_wrong_scrypt_salt_length(size, password, salt, opslimit, memlimit):
)
@pytest.mark.parametrize(
("passwd_hash", "password"),
[(b"Too short (and wrong) hash", b"a password",)],
[
(
b"Too short (and wrong) hash",
b"a password",
)
],
)
def test_wrong_scrypt_hash_length(passwd_hash, password):
with pytest.raises(exc.ValueError):
Expand Down Expand Up @@ -378,7 +393,12 @@ def test_variable_limits(opslimit, memlimit, n, r, p):
)
@pytest.mark.parametrize(
("passwd_hash", "password"),
[(b"Too short (and wrong) hash", b"another password",)],
[
(
b"Too short (and wrong) hash",
b"another password",
)
],
)
def test_scrypt_str_verify_wrong_hash_length(passwd_hash, password):
with pytest.raises(exc.ValueError):
Expand Down
18 changes: 14 additions & 4 deletions tests/test_sealed_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,19 @@ def test_sealed_box_encryption(privalice, pubalice, plaintext, _encrypted):
privalice = PrivateKey(privalice, encoder=HexEncoder)

box = SealedBox(pubalice)
encrypted = box.encrypt(binascii.unhexlify(plaintext), encoder=HexEncoder,)
encrypted = box.encrypt(
binascii.unhexlify(plaintext),
encoder=HexEncoder,
)

assert encrypted != _encrypted
# since SealedBox.encrypt uses an ephemeral sender's keypair

box2 = SealedBox(privalice)
decrypted = box2.decrypt(encrypted, encoder=HexEncoder,)
decrypted = box2.decrypt(
encrypted,
encoder=HexEncoder,
)
assert binascii.hexlify(decrypted) == plaintext
assert bytes(box) == bytes(box2)

Expand All @@ -85,7 +91,10 @@ def test_sealed_box_decryption(privalice, pubalice, plaintext, encrypted):
privalice = PrivateKey(privalice, encoder=HexEncoder)

box = SealedBox(privalice)
decrypted = box.decrypt(encrypted, encoder=HexEncoder,)
decrypted = box.decrypt(
encrypted,
encoder=HexEncoder,
)
assert binascii.hexlify(decrypted) == plaintext


Expand Down Expand Up @@ -123,7 +132,8 @@ def test_sealed_box_public_key_cannot_decrypt(
box = SealedBox(pubalice)
with pytest.raises(TypeError):
box.decrypt(
encrypted, encoder=HexEncoder,
encrypted,
encoder=HexEncoder,
)


Expand Down
3 changes: 2 additions & 1 deletion tests/test_secretstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def read_secretstream_vectors():


@pytest.mark.parametrize(
("key", "header", "chunks"), read_secretstream_vectors(),
("key", "header", "chunks"),
read_secretstream_vectors(),
)
def test_vectors(key, header, chunks):
state = crypto_secretstream_xchacha20poly1305_state()
Expand Down
17 changes: 13 additions & 4 deletions tests/test_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ def test_initialization_with_seed(self, seed):
def test_message_signing(
self, seed, _public_key, message, signature, expected
):
signing_key = SigningKey(seed, encoder=HexEncoder,)
signing_key = SigningKey(
seed,
encoder=HexEncoder,
)
signed = signing_key.sign(
binascii.unhexlify(message), encoder=HexEncoder,
binascii.unhexlify(message),
encoder=HexEncoder,
)

assert signed == expected
Expand Down Expand Up @@ -148,10 +152,15 @@ def test_different_keys_are_not_equal(self, k2):
def test_valid_signed_message(
self, _seed, public_key, message, signature, signed
):
key = VerifyKey(public_key, encoder=HexEncoder,)
key = VerifyKey(
public_key,
encoder=HexEncoder,
)

assert (
binascii.hexlify(key.verify(signed, encoder=HexEncoder),)
binascii.hexlify(
key.verify(signed, encoder=HexEncoder),
)
== message
)
assert (
Expand Down

0 comments on commit 732c484

Please sign in to comment.