Skip to content

Commit

Permalink
Add news and update some synxtax.
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez committed Aug 17, 2023
1 parent 4ea06d3 commit 4f43bc9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
8 changes: 7 additions & 1 deletion conda_content_trust/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class MixinKey:
PrivateKey and PublicKey classes, specifically. It provides some
convenience functions.
"""

@classmethod
def to_hex(cls, key):
return hexlify(cls.to_bytes(key)).decode("utf-8")
Expand Down Expand Up @@ -219,6 +220,7 @@ class PrivateKey(MixinKey, ed25519.Ed25519PrivateKey):
value for sign() is a length 64 bytes() object, a raw ed25519
signature.
"""

@classmethod
def to_bytes(cls, key):
return key.private_bytes(
Expand Down Expand Up @@ -260,13 +262,16 @@ class PublicKey(MixinKey, ed25519.Ed25519PublicKey):
We preserve Ed25519PublicKey's verify() method unchanged.
"""

@classmethod
def to_bytes(cls, key):
"""
Pops out the nice, tidy bytes of a given ed25519 key object, public or
private.
"""
return key.public_bytes(serialization.Encoding.Raw, serialization.PublicFormat.Raw)
return key.public_bytes(
serialization.Encoding.Raw, serialization.PublicFormat.Raw
)

@classmethod
def from_bytes(cls, key_value_in_bytes):
Expand All @@ -284,6 +289,7 @@ def from_bytes(cls, key_value_in_bytes):
checkformat_byteslike(key_value_in_bytes)
return super().from_public_bytes(key_value_in_bytes)


# No.... For now, I'll stick with the raw dictionary representations.
# If function profusion makes it inconvenient for folks to use this library,
# it MAY then be time to make signatures into class objects... but it's
Expand Down
19 changes: 19 additions & 0 deletions news/56-upgrade-cryptography
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Improve compatibility with cryptography>=41. (#56)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# conda-content-trust test dependencies
# run as 'conda install -c defaults --file tests/requirements.txt'
cryptography <41.0.0
cryptography>41.0.0
pytest
pytest-cov
# securesystemslib ==0.13.1 # not available on defaults or conda-forge
8 changes: 5 additions & 3 deletions tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ def test_wrap_sign_verify_signable():

assert PrivateKey.is_equivalent_to(generated_private, loaded_new_private)
assert PublicKey.is_equivalent_to(generated_public, loaded_new_public)
assert PrivateKey.is_equivalent_to(loaded_new_private, PrivateKey.from_bytes(loaded_new_private_bytes))
assert (
PublicKey.is_equivalent_to(loaded_new_public, PublicKey.from_bytes(loaded_new_public_bytes))
assert PrivateKey.is_equivalent_to(
loaded_new_private, PrivateKey.from_bytes(loaded_new_private_bytes)
)
assert PublicKey.is_equivalent_to(
loaded_new_public, PublicKey.from_bytes(loaded_new_public_bytes)
)

# Clean up a bit for the next tests.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_metadata_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ def test_gen_and_write_keys():
loaded_new_private, loaded_new_public = keyfiles_to_keys("keytest_new")
assert PrivateKey.is_equivalent_to(generated_private, loaded_new_private)
assert PublicKey.is_equivalent_to(generated_public, loaded_new_public)
assert (
PrivateKey.is_equivalent_to(loaded_new_private, PrivateKey.from_bytes(loaded_new_private_bytes))
assert PrivateKey.is_equivalent_to(
loaded_new_private, PrivateKey.from_bytes(loaded_new_private_bytes)
)
assert (
PublicKey.is_equivalent_to(loaded_new_public, PublicKey.from_bytes(loaded_new_public_bytes))
assert PublicKey.is_equivalent_to(
loaded_new_public, PublicKey.from_bytes(loaded_new_public_bytes)
)

finally:
Expand Down

0 comments on commit 4f43bc9

Please sign in to comment.