当前位置: 首页>>代码示例>>Python>>正文


Python crypt.Cryptor类代码示例

本文整理汇总了Python中passpie.crypt.Cryptor的典型用法代码示例。如果您正苦于以下问题:Python Cryptor类的具体用法?Python Cryptor怎么用?Python Cryptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cryptor类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_decrypt_returns_gpg_decrypted_data

    def test_decrypt_returns_gpg_decrypted_data(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        decrypted = "decrypted data"
        cryptor._gpg.decrypt.return_value = self.Mock(data=decrypted)

        self.assertEqual(cryptor.decrypt("data", "passphrase"), str(decrypted))
开发者ID:UtahDave,项目名称:passpie,代码行数:7,代码来源:test_crypt.py

示例2: test_encrypt_returns_gpg_encrypted_data

    def test_encrypt_returns_gpg_encrypted_data(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        encrypted = "encrypted data"
        cryptor._gpg.encrypt.return_value = self.Mock(data=encrypted)

        self.assertEqual(cryptor.encrypt("data"), str(encrypted))
开发者ID:UtahDave,项目名称:passpie,代码行数:7,代码来源:test_crypt.py

示例3: test_create_keys_raises_file_exist_error_when_keys_found_in_path

    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")
开发者ID:UtahDave,项目名称:passpie,代码行数:7,代码来源:test_crypt.py

示例4: test_passprase_check_with_ensure_raises_value_error_with_ensure

    def test_passprase_check_with_ensure_raises_value_error_with_ensure(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        cryptor._gpg.sign.return_value = None
        passphrase = "passphrase"

        with self.assertRaises(ValueError):
            cryptor.check(passphrase, ensure=True)
开发者ID:UtahDave,项目名称:passpie,代码行数:8,代码来源:test_crypt.py

示例5: test_import_keys_opens_keys_path_and_import_to_gpg

    def test_import_keys_opens_keys_path_and_import_to_gpg(self):
        to_patch = 'passpie.crypt.open'
        mock_open = self.patch(to_patch, self.mock_open(), create=True)
        mock_open().read.return_value = "key data"

        cryptor = Cryptor("path/to/database")
        cryptor._import_keys()
        cryptor._gpg.import_keys.assert_called_once_with(
            mock_open().read()
        )
开发者ID:UtahDave,项目名称:passpie,代码行数:10,代码来源:test_crypt.py

示例6: test_passphrase_check_raises_value_error_when_bad_passphrase

    def test_passphrase_check_raises_value_error_when_bad_passphrase(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        passphrase = "passphrase"
        result = cryptor.check(passphrase)

        self.assertTrue(result)
        self.assertTrue(cryptor._gpg.sign.called)
        cryptor._gpg.sign.assert_called_once_with(
            "testing",
            default_key=cryptor.current_key,
            passphrase=passphrase
        )
开发者ID:UtahDave,项目名称:passpie,代码行数:13,代码来源:test_crypt.py

示例7: test_import_keys_raises_file_not_found_when_keys_not_found

    def test_import_keys_raises_file_not_found_when_keys_not_found(self):
        to_patch = 'passpie.crypt.open'
        mock_open = self.patch(to_patch, self.mock_open(), create=True)
        cryptor = Cryptor("path/to/database")

        mock_open.side_effect = OSError(2, "File Not Found")
        with self.assertRaises(FileNotFoundError):
            cryptor._import_keys()

        mock_open.side_effect = OSError(17, "File exists")
        try:
            cryptor._import_keys()
        except Exception as exc:
            self.assertNotIsInstance(exc, FileNotFoundError)
开发者ID:UtahDave,项目名称:passpie,代码行数:14,代码来源:test_crypt.py

示例8: test_create_keys_export_public_and_secret_keys_into_keyspath

    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)
开发者ID:UtahDave,项目名称:passpie,代码行数:22,代码来源:test_crypt.py

示例9: test_cryptor__enter__returns_self

 def test_cryptor__enter__returns_self(self):
     cryptor = Cryptor("path/to/database")
     self.assertEqual(Cryptor.__enter__(cryptor), cryptor)
开发者ID:UtahDave,项目名称:passpie,代码行数:3,代码来源:test_crypt.py


注:本文中的passpie.crypt.Cryptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。