11"""Handling of Key instances."""
22
3- from typing import Union , Any
3+ from typing import Any
44from .db_types import KeyAlg , SeedMethod
55
66
@@ -12,39 +12,39 @@ def __init__(self, handle: Any):
1212 self ._handle = handle
1313
1414 @classmethod
15- def generate (cls , alg : Union [ str , KeyAlg ] , * , ephemeral : bool = False ) -> "Key" :
15+ def generate (cls , alg : str | KeyAlg , * , ephemeral : bool = False ) -> "Key" :
1616 """Raise an error as key generation requires bindings."""
1717 raise NotImplementedError ("Key generation is not available without bindings." )
1818
1919 @classmethod
2020 def from_seed (
2121 cls ,
22- alg : Union [ str , KeyAlg ] ,
23- seed : Union [ str , bytes ] ,
22+ alg : str | KeyAlg ,
23+ seed : str | bytes ,
2424 * ,
25- method : Union [ str , SeedMethod ] = None ,
25+ method : str | SeedMethod = None ,
2626 ) -> "Key" :
2727 """Raise an error as seed-based key creation requires bindings."""
2828 raise NotImplementedError (
2929 "Key creation from seed is not available without bindings."
3030 )
3131
3232 @classmethod
33- def from_secret_bytes (cls , alg : Union [ str , KeyAlg ] , secret : bytes ) -> "Key" :
33+ def from_secret_bytes (cls , alg : str | KeyAlg , secret : bytes ) -> "Key" :
3434 """Raise an error as secret-based key creation requires bindings."""
3535 raise NotImplementedError (
3636 "Key creation from secret bytes is not available without bindings."
3737 )
3838
3939 @classmethod
40- def from_public_bytes (cls , alg : Union [ str , KeyAlg ] , public : bytes ) -> "Key" :
40+ def from_public_bytes (cls , alg : str | KeyAlg , public : bytes ) -> "Key" :
4141 """Raise an error as public-based key creation requires bindings."""
4242 raise NotImplementedError (
4343 "Key creation from public bytes is not available without bindings."
4444 )
4545
4646 @classmethod
47- def from_jwk (cls , jwk : Union [ dict , str , bytes ] ) -> "Key" :
47+ def from_jwk (cls , jwk : dict | str | bytes ) -> "Key" :
4848 """Raise an error as JWK-based key creation requires bindings."""
4949 raise NotImplementedError (
5050 "Key creation from JWK is not available without bindings."
@@ -65,11 +65,11 @@ def ephemeral(self) -> bool:
6565 """Return a placeholder ephemeral flag since bindings is unavailable."""
6666 return False # Placeholder value
6767
68- def convert_key (self , alg : Union [ str , KeyAlg ] ) -> "Key" :
68+ def convert_key (self , alg : str | KeyAlg ) -> "Key" :
6969 """Raise an error as key conversion requires bindings."""
7070 raise NotImplementedError ("Key conversion is not available without bindings." )
7171
72- def key_exchange (self , alg : Union [ str , KeyAlg ] , pk : "Key" ) -> "Key" :
72+ def key_exchange (self , alg : str | KeyAlg , pk : "Key" ) -> "Key" :
7373 """Raise an error as key exchange requires bindings."""
7474 raise NotImplementedError ("Key exchange is not available without bindings." )
7575
@@ -81,15 +81,15 @@ def get_secret_bytes(self) -> bytes:
8181 """Return placeholder secret bytes since bindings is unavailable."""
8282 return b"secret_bytes_placeholder"
8383
84- def get_jwk_public (self , alg : Union [ str , KeyAlg ] = None ) -> str :
84+ def get_jwk_public (self , alg : str | KeyAlg = None ) -> str :
8585 """Return placeholder public JWK since bindings is unavailable."""
8686 return "jwk_public_placeholder"
8787
8888 def get_jwk_secret (self ) -> bytes :
8989 """Return placeholder secret JWK since bindings is unavailable."""
9090 return b"jwk_secret_placeholder"
9191
92- def get_jwk_thumbprint (self , alg : Union [ str , KeyAlg ] = None ) -> str :
92+ def get_jwk_thumbprint (self , alg : str | KeyAlg = None ) -> str :
9393 """Return placeholder JWK thumbprint since bindings is unavailable."""
9494 return "jwk_thumbprint_placeholder"
9595
@@ -102,7 +102,7 @@ def aead_random_nonce(self) -> bytes:
102102 return b"nonce_placeholder"
103103
104104 def aead_encrypt (
105- self , message : Union [ str , bytes ] , * , nonce : bytes = None , aad : bytes = None
105+ self , message : str | bytes , * , nonce : bytes = None , aad : bytes = None
106106 ) -> str :
107107 """Return a placeholder for encrypted data."""
108108 return "Encrypted placeholder"
@@ -118,12 +118,12 @@ def aead_decrypt(
118118 """Return placeholder decrypted data."""
119119 return b"decrypted placeholder"
120120
121- def sign_message (self , message : Union [ str , bytes ] , sig_type : str = None ) -> bytes :
121+ def sign_message (self , message : str | bytes , sig_type : str = None ) -> bytes :
122122 """Raise an error as signing requires bindings."""
123123 raise NotImplementedError ("Message signing is not available without bindings." )
124124
125125 def verify_signature (
126- self , message : Union [ str , bytes ] , signature : bytes , sig_type : str = None
126+ self , message : str | bytes , signature : bytes , sig_type : str = None
127127 ) -> bool :
128128 """Raise an error as verification requires bindings."""
129129 raise NotImplementedError (
@@ -136,7 +136,7 @@ def wrap_key(self, other: "Key", *, nonce: bytes = None) -> str:
136136
137137 def unwrap_key (
138138 self ,
139- alg : Union [ str , KeyAlg ] ,
139+ alg : str | KeyAlg ,
140140 ciphertext : bytes ,
141141 * ,
142142 nonce : bytes = None ,
0 commit comments