<s> from __future__ import absolute_import , division , print_function <EOL> import pytest <EOL> from cryptography . exceptions import ( <EOL> AlreadyFinalized , InvalidKey , _Reasons <EOL> ) <EOL> from cryptography . hazmat . backends import default_backend <EOL> from cryptography . hazmat . primitives import hashes <EOL> from cryptography . hazmat . primitives . kdf . pbkdf2 import PBKDF2HMAC <EOL> from ... doubles import DummyHashAlgorithm <EOL> from ... utils import raises_unsupported_algorithm <EOL> class TestPBKDF2HMAC ( object ) : <EOL> def test_already_finalized ( self ) : <EOL> kdf = PBKDF2HMAC ( hashes . SHA1 ( ) , <NUM_LIT:20> , b"<STR_LIT>" , <NUM_LIT:10> , default_backend ( ) ) <EOL> kdf . derive ( b"<STR_LIT:password>" ) <EOL> with pytest . raises ( AlreadyFinalized ) : <EOL> kdf . derive ( b"<STR_LIT>" ) <EOL> kdf = PBKDF2HMAC ( hashes . SHA1 ( ) , <NUM_LIT:20> , b"<STR_LIT>" , <NUM_LIT:10> , default_backend ( ) ) <EOL> key = kdf . derive ( b"<STR_LIT:password>" ) <EOL> with pytest . raises ( AlreadyFinalized ) : <EOL> kdf . verify ( b"<STR_LIT:password>" , key ) <EOL> kdf = PBKDF2HMAC ( hashes . SHA1 ( ) , <NUM_LIT:20> , b"<STR_LIT>" , <NUM_LIT:10> , default_backend ( ) ) <EOL> kdf . verify ( b"<STR_LIT:password>" , key ) <EOL> with pytest . raises ( AlreadyFinalized ) : <EOL> kdf . verify ( b"<STR_LIT:password>" , key ) <EOL> def test_unsupported_algorithm ( self ) : <EOL> with raises_unsupported_algorithm ( _Reasons . UNSUPPORTED_HASH ) : <EOL> PBKDF2HMAC ( <EOL> DummyHashAlgorithm ( ) , <NUM_LIT:20> , b"<STR_LIT>" , <NUM_LIT:10> , default_backend ( ) <EOL> ) <EOL> def test_invalid_key ( self ) : <EOL> kdf = PBKDF2HMAC ( hashes . SHA1 ( ) , <NUM_LIT:20> , b"<STR_LIT>" , <NUM_LIT:10> , default_backend ( ) ) <EOL> key = kdf . derive ( b"<STR_LIT:password>" ) <EOL> kdf = PBKDF2HMAC ( hashes . SHA1 ( ) , <NUM_LIT:20> , b"<STR_LIT>" , <NUM_LIT:10> , default_backend ( ) ) <EOL> with pytest . raises ( InvalidKey ) : <EOL> kdf . verify ( b"<STR_LIT>" , key ) <EOL> def test_unicode_error_with_salt ( self ) : <EOL> with pytest . raises ( TypeError ) : <EOL> PBKDF2HMAC ( hashes . SHA1 ( ) , <NUM_LIT:20> , u"<STR_LIT>" , <NUM_LIT:10> , default_backend ( ) ) <EOL> def test_unicode_error_with_key_material ( self ) : <EOL> kdf = PBKDF2HMAC ( hashes . SHA1 ( ) , <NUM_LIT:20> , b"<STR_LIT>" , <NUM_LIT:10> , default_backend ( ) ) <EOL> with pytest . raises ( TypeError ) : <EOL> kdf . derive ( u"<STR_LIT>" ) <EOL> def test_invalid_backend ( ) : <EOL> pretend_backend = object ( ) <EOL> with raises_unsupported_algorithm ( _Reasons . BACKEND_MISSING_INTERFACE ) : <EOL> PBKDF2HMAC ( hashes . SHA1 ( ) , <NUM_LIT:20> , b"<STR_LIT>" , <NUM_LIT:10> , pretend_backend ) </s>
