20
20
21
21
from digi .xbee .util import utils
22
22
23
+
23
24
@unique
24
25
class HAType (Enum ):
25
26
"""
@@ -78,6 +79,7 @@ def get(cls, code):
78
79
79
80
HAType .__doc__ += utils .doc_enum (HAType )
80
81
82
+
81
83
@unique
82
84
class NgGroupParams (Enum ):
83
85
"""
@@ -286,11 +288,11 @@ def get(cls, code):
286
288
287
289
288
290
def create_salted_verification_key (user , password , hash_alg = HAType .SHA256 ,
289
- ng_type = NgGroupParams .NG_1024 , salt_len = 4 ):
291
+ ng_type = NgGroupParams .NG_1024 , salt_len = 4 ):
290
292
"""
291
293
Generates a salted verification key for the provided username and password.
292
294
293
- Params :
295
+ Args :
294
296
user (String): Username string.
295
297
password (String): Plain text password.
296
298
hash_alg (:class:`.HAType`, optional, default=`HAType.SHA256`): Hash algorithm.
@@ -301,39 +303,39 @@ def create_salted_verification_key(user, password, hash_alg=HAType.SHA256,
301
303
Returns:
302
304
Tuple (bytes, bytes): Tuple with salt and verifier.
303
305
"""
304
- s = generate_salt (l = salt_len )
306
+ s = generate_salt (length = salt_len )
305
307
v = generate_verifier (user , password , hash_alg = hash_alg , ng_type = ng_type ,
306
308
salt = s , sep = ":" )
307
309
308
310
return s , v
309
311
310
312
311
- def generate_salt (l = 4 ):
313
+ def generate_salt (length = 4 ):
312
314
"""
313
315
Generates new salt.
314
316
315
- Params :
316
- l (Integer, optional, default=`4`): Number of bytes.
317
+ Args :
318
+ length (Integer, optional, default=`4`): Number of bytes.
317
319
318
320
Returns:
319
321
Bytes: The generated salt.
320
322
"""
321
- return os .urandom (l )
323
+ return os .urandom (length )
322
324
323
325
324
326
def generate_verifier (user , password , salt , hash_alg = HAType .SHA256 ,
325
327
ng_type = NgGroupParams .NG_1024 , sep = ":" ):
326
328
"""
327
329
Calculates a verifier for the provided salt and configured password.
328
330
329
- Params :
331
+ Args :
330
332
user (String): Username string.
331
333
password (String): Plain text password.
332
334
salt (bytes): Salt to generate a verifier.
333
335
hash_alg (:class:`.HAType`, optional, default=`HAType.SHA256`): Hash algorithm.
334
336
ng_type (:class:`.NgGroupParams`, optional, default=`NgGroupParams.NG_1024`):
335
337
Prime generator type.
336
- sep (String, optional, default= `:` ): Separator string.
338
+ sep (String, optional): Separator string.
337
339
338
340
Returns:
339
341
Bytes: The generated verifier.
@@ -352,12 +354,12 @@ def __calculate_x(user, password, salt, hash_alg=HAType.SHA256, sep=":"):
352
354
"""
353
355
Calculates the user secret parameter.
354
356
355
- Params :
357
+ Args :
356
358
user (String): Username string.
357
359
password (String): Plain text password.
358
360
salt (bytes): Salt byte array.
359
361
hash_alg (:class:`.HAType`, optional, default=`HAType.SHA256`): Hash algorithm.
360
- sep (String, optional, default= `:` ): Separator string.
362
+ sep (String, optional): Separator string.
361
363
362
364
Returns:
363
365
Integer: The user secret value.
@@ -376,7 +378,7 @@ def __hash(hash_alg, *args):
376
378
"""
377
379
Calculates the hash of the provided arguments.
378
380
379
- Params :
381
+ Args :
380
382
args: Variable argument list of object to use for hash.
381
383
382
384
Returns:
@@ -393,7 +395,7 @@ def __to_bytes(obj):
393
395
"""
394
396
Converts object to byte array, with optional context.
395
397
396
- Params :
398
+ Args :
397
399
obj: Object to convert.
398
400
399
401
Returns:
0 commit comments