本文整理匯總了Python中passpie.crypt.Cryptor.create_keys方法的典型用法代碼示例。如果您正苦於以下問題:Python Cryptor.create_keys方法的具體用法?Python Cryptor.create_keys怎麽用?Python Cryptor.create_keys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類passpie.crypt.Cryptor
的用法示例。
在下文中一共展示了Cryptor.create_keys方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_create_keys_raises_file_exist_error_when_keys_found_in_path
# 需要導入模塊: from passpie.crypt import Cryptor [as 別名]
# 或者: from passpie.crypt.Cryptor import create_keys [as 別名]
def test_create_keys_raises_file_exist_error_when_keys_found_in_path(self):
cryptor = Cryptor("path/to/database")
self.patch("passpie.crypt.os.path.exists",
self.Mock(return_value=True))
with self.assertRaises(FileExistsError):
cryptor.create_keys("passphrase")
示例2: test_create_keys_export_public_and_secret_keys_into_keyspath
# 需要導入模塊: from passpie.crypt import Cryptor [as 別名]
# 或者: from passpie.crypt.Cryptor import create_keys [as 別名]
def test_create_keys_export_public_and_secret_keys_into_keyspath(self):
cryptor = Cryptor("path/to/database")
passphrase = "passphrase"
self.patch("passpie.crypt.os.path.exists",
self.Mock(return_value=False))
keys = self.Mock(fingerprint="HEX")
cryptor._gpg.gen_key.return_value = keys
mock_open = self.patch("passpie.crypt.mkdir_open",
self.mock_open(), create=True)
mock_keyfile = self.Mock()
mock_open().__enter__.return_value = mock_keyfile
cryptor.create_keys(passphrase)
key_input = KEY_INPUT.format(passphrase)
cryptor._gpg.gen_key.assert_called_once_with(key_input)
cryptor._gpg.export_keys.assert_any_call(keys.fingerprint)
pubkey = cryptor._gpg.export_keys(keys.fingerprint)
seckey = cryptor._gpg.export_keys(keys.fingerprint, secret=True)
cryptor._gpg.export_keys.assert_any_call(keys.fingerprint, secret=True)
mock_keyfile.write.called_once_with(pubkey + seckey)