From b471559aded03342d75b6f2554d969fcd9cda2f5 Mon Sep 17 00:00:00 2001 From: Lex Gallon Date: Tue, 24 Dec 2024 10:02:53 +1100 Subject: [PATCH] Avoid deprecated encode_point() method - This allows `python-sshpubkeys` to work with `cryptography>=39.0.0`. - `ec.EllipticCurvePublicNumbers.encode_point()` had been deprecated for a long time, and was removed in commit pyca/cryptography@2b6e463 , or `cryptography==39.0.0`. - I manually tested to confirm that for all of the existing test cases that called `to_string()`, this new `public_bytes()` method yielded the same bytes as the old `encode_point()`. - Since the "compressed" `to_string()` was already using `public_bytes()` with `Encoding` and `PublicFormat`, it seems unlikely that this change will break support for any versions of `cryptography` --- sshpubkeys/keys.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sshpubkeys/keys.py b/sshpubkeys/keys.py index 2e2066f..ea90fd3 100644 --- a/sshpubkeys/keys.py +++ b/sshpubkeys/keys.py @@ -57,9 +57,10 @@ def __repr__(self): def to_string(self, encoding="raw"): """Pub key as bytes string""" if encoding == "raw": - return self.pubkey.public_numbers().encode_point()[1:] + # Omit first char because it is an unwanted '\x04' + return self.pubkey.public_bytes(Encoding.OpenSSH, PublicFormat.OpenSSH)[1:] if encoding == "uncompressed": - return self.pubkey.public_numbers().encode_point() + return self.pubkey.public_bytes(Encoding.X962, PublicFormat.UncompressedPoint) if encoding == "compressed": return self.pubkey.public_bytes(Encoding.X962, PublicFormat.CompressedPoint) raise ValueError(encoding)