@@ -276,112 +276,156 @@ def to_dict(self):
276
276
return payload
277
277
278
278
@classmethod
279
- def _hmac (cls , name , key ):
279
+ def _hmac (cls , name , key , input_order = None ):
280
+ """Creates a new HMAC based algorithm instance.
281
+
282
+ Args:
283
+ name: The HMAC algorithm name.
284
+ key: Signer key as a byte sequence.
285
+ input_order: The salt + password order, either SALT_FIRST or PASSWORD_FIRST.
286
+
287
+ Returns:
288
+ UserImportHash: A new ``UserImportHash``.
289
+ """
290
+
291
+ password_hash_order = None
292
+ if input_order is 'SALT_FIRST' :
293
+ password_hash_order = 'SALT_AND_PASSWORD'
294
+ elif input_order is 'PASSWORD_FIRST' :
295
+ password_hash_order = 'PASSWORD_AND_SALT'
280
296
data = {
281
- 'signerKey' : b64_encode (_auth_utils .validate_bytes (key , 'key' , required = True ))
297
+ 'signerKey' : b64_encode (_auth_utils .validate_bytes (key , 'key' , required = True )),
298
+ 'passwordHashOrder' : password_hash_order
282
299
}
283
300
return UserImportHash (name , data )
284
301
285
302
@classmethod
286
- def _basic_hash (cls , name , rounds ):
287
- data = {'rounds' : _auth_utils .validate_int (rounds , 'rounds' , 0 , 120000 )}
303
+ def _basic_hash (cls , name , rounds , input_order = None ):
304
+ """Creates a new basic hash algorithm instance.
305
+
306
+ Args:
307
+ name: The basic algorithm name.
308
+ rounds: Number of rounds. This differs depending on the algorithm used.
309
+ input_order: The salt + password order, either SALT_FIRST or PASSWORD_FIRST.
310
+
311
+ Returns:
312
+ UserImportHash: A new ``UserImportHash``.
313
+ """
314
+
315
+ password_hash_order = None
316
+ if input_order is 'SALT_FIRST' :
317
+ password_hash_order = 'SALT_AND_PASSWORD'
318
+ elif input_order is 'PASSWORD_FIRST' :
319
+ password_hash_order = 'PASSWORD_AND_SALT'
320
+ data = {
321
+ 'rounds' : _auth_utils .validate_int (rounds , 'rounds' , 0 , 120000 ),
322
+ 'passwordHashOrder' : password_hash_order
323
+ }
288
324
return UserImportHash (name , data )
289
325
290
326
@classmethod
291
- def hmac_sha512 (cls , key ):
327
+ def hmac_sha512 (cls , key , input_order = None ):
292
328
"""Creates a new HMAC SHA512 algorithm instance.
293
329
294
330
Args:
295
331
key: Signer key as a byte sequence.
332
+ input_order: The salt + password order, either SALT_FIRST or PASSWORD_FIRST.
296
333
297
334
Returns:
298
335
UserImportHash: A new ``UserImportHash``.
299
336
"""
300
- return cls ._hmac ('HMAC_SHA512' , key )
337
+ return cls ._hmac ('HMAC_SHA512' , key , input_order )
301
338
302
339
@classmethod
303
- def hmac_sha256 (cls , key ):
340
+ def hmac_sha256 (cls , key , input_order = None ):
304
341
"""Creates a new HMAC SHA256 algorithm instance.
305
342
306
343
Args:
307
344
key: Signer key as a byte sequence.
345
+ input_order: The salt + password order, either SALT_FIRST or PASSWORD_FIRST.
308
346
309
347
Returns:
310
348
UserImportHash: A new ``UserImportHash``.
311
349
"""
312
- return cls ._hmac ('HMAC_SHA256' , key )
350
+ return cls ._hmac ('HMAC_SHA256' , key , input_order )
313
351
314
352
@classmethod
315
- def hmac_sha1 (cls , key ):
353
+ def hmac_sha1 (cls , key , input_order = None ):
316
354
"""Creates a new HMAC SHA1 algorithm instance.
317
355
318
356
Args:
319
357
key: Signer key as a byte sequence.
358
+ input_order: The salt + password order, either SALT_FIRST or PASSWORD_FIRST.
320
359
321
360
Returns:
322
361
UserImportHash: A new ``UserImportHash``.
323
362
"""
324
- return cls ._hmac ('HMAC_SHA1' , key )
363
+ return cls ._hmac ('HMAC_SHA1' , key , input_order )
325
364
326
365
@classmethod
327
- def hmac_md5 (cls , key ):
366
+ def hmac_md5 (cls , key , input_order = None ):
328
367
"""Creates a new HMAC MD5 algorithm instance.
329
368
330
369
Args:
331
370
key: Signer key as a byte sequence.
371
+ input_order: The salt + password order, either SALT_FIRST or PASSWORD_FIRST.
332
372
333
373
Returns:
334
374
UserImportHash: A new ``UserImportHash``.
335
375
"""
336
- return cls ._hmac ('HMAC_MD5' , key )
376
+ return cls ._hmac ('HMAC_MD5' , key , input_order )
337
377
338
378
@classmethod
339
- def md5 (cls , rounds ):
379
+ def md5 (cls , rounds , input_order = None ):
340
380
"""Creates a new MD5 algorithm instance.
341
381
342
382
Args:
343
383
rounds: Number of rounds. Must be an integer between 0 and 120000.
384
+ input_order: The salt + password order, either SALT_FIRST or PASSWORD_FIRST.
344
385
345
386
Returns:
346
387
UserImportHash: A new ``UserImportHash``.
347
388
"""
348
- return cls ._basic_hash ('MD5' , rounds )
389
+ return cls ._basic_hash ('MD5' , rounds , input_order )
349
390
350
391
@classmethod
351
- def sha1 (cls , rounds ):
392
+ def sha1 (cls , rounds , input_order = None ):
352
393
"""Creates a new SHA1 algorithm instance.
353
394
354
395
Args:
355
396
rounds: Number of rounds. Must be an integer between 0 and 120000.
397
+ input_order: The salt + password order, either SALT_FIRST or PASSWORD_FIRST.
356
398
357
399
Returns:
358
400
UserImportHash: A new ``UserImportHash``.
359
401
"""
360
- return cls ._basic_hash ('SHA1' , rounds )
402
+ return cls ._basic_hash ('SHA1' , rounds , input_order )
361
403
362
404
@classmethod
363
- def sha256 (cls , rounds ):
405
+ def sha256 (cls , rounds , input_order = None ):
364
406
"""Creates a new SHA256 algorithm instance.
365
407
366
408
Args:
367
409
rounds: Number of rounds. Must be an integer between 0 and 120000.
410
+ input_order: The salt + password order, either SALT_FIRST or PASSWORD_FIRST.
368
411
369
412
Returns:
370
413
UserImportHash: A new ``UserImportHash``.
371
414
"""
372
- return cls ._basic_hash ('SHA256' , rounds )
415
+ return cls ._basic_hash ('SHA256' , rounds , input_order )
373
416
374
417
@classmethod
375
- def sha512 (cls , rounds ):
418
+ def sha512 (cls , rounds , input_order = None ):
376
419
"""Creates a new SHA512 algorithm instance.
377
420
378
421
Args:
379
422
rounds: Number of rounds. Must be an integer between 0 and 120000.
423
+ input_order: The salt + password order, either SALT_FIRST or PASSWORD_FIRST.
380
424
381
425
Returns:
382
426
UserImportHash: A new ``UserImportHash``.
383
427
"""
384
- return cls ._basic_hash ('SHA512' , rounds )
428
+ return cls ._basic_hash ('SHA512' , rounds , input_order )
385
429
386
430
@classmethod
387
431
def pbkdf_sha1 (cls , rounds ):
0 commit comments