mirror of https://github.com/nucypher/pyUmbral.git
UmbralPublicKeys allow hex serialization
parent
7568fff780
commit
2c3620249b
|
@ -133,6 +133,14 @@ def test_key_encoder_decoder(random_ec_curvebn1):
|
||||||
assert decoded_key.to_bytes() == umbral_key.to_bytes()
|
assert decoded_key.to_bytes() == umbral_key.to_bytes()
|
||||||
|
|
||||||
|
|
||||||
|
def test_public_key_as_hex(random_ec_curvebn1):
|
||||||
|
pubkey = UmbralPrivateKey(random_ec_curvebn1, default_params()).get_pubkey()
|
||||||
|
hex_string = pubkey.hex()
|
||||||
|
decoded_pubkey = UmbralPublicKey.from_hex(hex_string)
|
||||||
|
|
||||||
|
assert pubkey == decoded_pubkey
|
||||||
|
|
||||||
|
|
||||||
def test_umbral_key_to_cryptography_keys():
|
def test_umbral_key_to_cryptography_keys():
|
||||||
umbral_priv_key = UmbralPrivateKey.gen_key()
|
umbral_priv_key = UmbralPrivateKey.gen_key()
|
||||||
umbral_pub_key = umbral_priv_key.get_pubkey()
|
umbral_pub_key = umbral_priv_key.get_pubkey()
|
||||||
|
|
|
@ -321,6 +321,16 @@ class UmbralPublicKey:
|
||||||
|
|
||||||
return umbral_pubkey
|
return umbral_pubkey
|
||||||
|
|
||||||
|
def hex(self, is_compressed: bool = True) -> str:
|
||||||
|
"""
|
||||||
|
Returns an Umbral public key as hex string.
|
||||||
|
"""
|
||||||
|
return self.to_bytes(is_compressed=is_compressed).hex()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_hex(cls, hex_string: str) -> 'UmbralPublicKey':
|
||||||
|
return cls.from_bytes(key_bytes=hex_string, decoder=bytes.fromhex)
|
||||||
|
|
||||||
def to_cryptography_pubkey(self) -> _EllipticCurvePublicKey:
|
def to_cryptography_pubkey(self) -> _EllipticCurvePublicKey:
|
||||||
"""
|
"""
|
||||||
Returns a cryptography.io EllipticCurvePublicKey from the Umbral key.
|
Returns a cryptography.io EllipticCurvePublicKey from the Umbral key.
|
||||||
|
|
Loading…
Reference in New Issue