File tree Expand file tree Collapse file tree 2 files changed +15
-12
lines changed
Expand file tree Collapse file tree 2 files changed +15
-12
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,14 @@ class RSABinding(CryptographyBinding):
4343 ssh_type = b"ssh-rsa"
4444 _cryptography_key_types = (RSAPrivateKey , RSAPublicKey )
4545
46+ @staticmethod
47+ def generate_private_key (size : int ) -> RSAPrivateKey :
48+ return generate_private_key (
49+ public_exponent = 65537 ,
50+ key_size = size ,
51+ backend = default_backend (),
52+ )
53+
4654 @staticmethod
4755 def import_private_key (obj : RSADictKey ) -> RSAPrivateKey :
4856 if "oth" in obj : # pragma: no cover
@@ -170,17 +178,13 @@ def generate_key(
170178 key_size = 2048
171179
172180 if key_size % 8 != 0 :
173- raise ValueError ("Invalid key_size for RSAKey " )
181+ raise ValueError ("A bit size must be a multiple of 8 " )
174182
175183 if key_size < 2048 :
176184 # https://csrc.nist.gov/publications/detail/sp/800-131a/rev-2/final
177185 warnings .warn ("Key size should be >= 2048 bits" , SecurityWarning )
178186
179- raw_key = generate_private_key (
180- public_exponent = 65537 ,
181- key_size = key_size ,
182- backend = default_backend (),
183- )
187+ raw_key = cls .binding .generate_private_key (key_size )
184188 if private :
185189 key = cls (raw_key , raw_key , parameters )
186190 else :
Original file line number Diff line number Diff line change @@ -63,6 +63,8 @@ class OKPBinding(CryptographyBinding):
6363
6464 @staticmethod
6565 def generate_private_key (crv : LiteralCurves ) -> PrivateOKPKey :
66+ if crv not in PRIVATE_KEYS_MAP :
67+ raise InvalidKeyCurveError (f"Invalid curve value: '{ crv } '" )
6668 crv_key : t .Type [PrivateOKPKey ] = PRIVATE_KEYS_MAP [crv ]
6769 return crv_key .generate ()
6870
@@ -190,12 +192,9 @@ def generate_key(
190192 :param auto_kid: add ``kid`` automatically
191193 """
192194 if crv is None :
193- crv = "Ed25519"
194-
195- if crv not in PRIVATE_KEYS_MAP :
196- raise InvalidKeyCurveError (f"Invalid curve value: '{ crv } '" )
197-
198- raw_key = cls .binding .generate_private_key (crv )
195+ raw_key = cls .binding .generate_private_key ("Ed25519" )
196+ else :
197+ raw_key = cls .binding .generate_private_key (crv )
199198 if private :
200199 key = cls (raw_key , raw_key , parameters )
201200 else :
You can’t perform that action at this time.
0 commit comments