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


Python PGPMessage.new方法代码示例

本文整理汇总了Python中pgpy.PGPMessage.new方法的典型用法代码示例。如果您正苦于以下问题:Python PGPMessage.new方法的具体用法?Python PGPMessage.new怎么用?Python PGPMessage.new使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pgpy.PGPMessage的用法示例。


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

示例1: test_decrypt_unencrypted_message

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_decrypt_unencrypted_message(self, rsa_sec, recwarn):
        lit = PGPMessage.new('tests/testdata/lit', file=True)
        rsa_sec.decrypt(lit)

        w = recwarn.pop(UserWarning)
        assert str(w.message) == "This message is not encrypted"
        assert w.filename == __file__
开发者ID:escapewindow,项目名称:PGPy,代码行数:9,代码来源:test_10_exceptions.py

示例2: test_new_sensitive

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_new_sensitive(self, write_clean, gpg_print):
        msg = PGPMessage.new("This is a sensitive message!", sensitive=True)

        assert msg.type == 'literal'
        assert msg.message == "This is a sensitive message!"
        assert msg.is_sensitive
        assert msg.filename == '_CONSOLE'

        with write_clean('tests/testdata/csmsg.asc', 'w', str(msg)):
            assert gpg_print('csmsg.asc') == "This is a sensitive message!"
开发者ID:ddddavidee,项目名称:PGPy,代码行数:12,代码来源:test_05_actions.py

示例3: test_new_non_unicode_cleartext

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_new_non_unicode_cleartext(self):
        # this message text comes from http://www.columbia.edu/~fdc/utf8/
        text = u'色は匂へど 散りぬるを\n' \
               u'我が世誰ぞ 常ならむ\n' \
               u'有為の奥山 今日越えて\n' \
               u'浅き夢見じ 酔ひもせず'
        msg = PGPMessage.new(text.encode('jisx0213'), cleartext=True, encoding='jisx0213')

        assert msg.type == 'cleartext'
        assert msg.message == text
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:12,代码来源:test_05_actions.py

示例4: test_new_non_unicode

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_new_non_unicode(self, write_clean, gpg_print):
        # this message text comes from http://www.columbia.edu/~fdc/utf8/
        text = u'色は匂へど 散りぬるを\n' \
               u'我が世誰ぞ 常ならむ\n' \
               u'有為の奥山 今日越えて\n' \
               u'浅き夢見じ 酔ひもせず\n'
        msg = PGPMessage.new(text.encode('jisx0213'), encoding='jisx0213')

        assert msg.type == 'literal'
        assert msg.message == text.encode('jisx0213')
开发者ID:ddddavidee,项目名称:PGPy,代码行数:12,代码来源:test_05_actions.py

示例5: test_encrypt_bad_cipher

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_encrypt_bad_cipher(self, rsa_pub, recwarn):
        rsa_pub.subkeys['EEE097A017B979CA'].encrypt(PGPMessage.new('asdf'),
                                                    cipher=SymmetricKeyAlgorithm.CAST5)

        w = recwarn.pop(UserWarning)
        assert str(w.message) == "Selected symmetric algorithm not in key preferences"
        assert w.filename == __file__

        w = recwarn.pop(UserWarning)
        assert str(w.message) == "Selected compression algorithm not in key preferences"
        assert w.filename == __file__
开发者ID:escapewindow,项目名称:PGPy,代码行数:13,代码来源:test_10_exceptions.py

示例6: test_new

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_new(self, comp_alg, write_clean, gpg_print):
        msg = PGPMessage.new(u"This is a new message!", compression=comp_alg)

        assert msg.filename == ''
        assert msg.type == 'literal'
        assert msg.message == u"This is a new message!"
        assert msg._message.format == 'u'
        assert msg._message.filename == ''
        assert msg.is_compressed is bool(comp_alg != CompressionAlgorithm.Uncompressed)

        with write_clean('tests/testdata/cmsg.asc', 'w', str(msg)):
            assert gpg_print('cmsg.asc') == "This is a new message!"
开发者ID:ddddavidee,项目名称:PGPy,代码行数:14,代码来源:test_05_actions.py

示例7: test_encrypt_message

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_encrypt_message(self, pub, cipher):
        if pub.key_algorithm in {PubKeyAlgorithm.DSA}:
            pytest.skip('Asymmetric encryption only implemented for RSA/ECDH currently')

        if cipher in {SymmetricKeyAlgorithm.Plaintext, SymmetricKeyAlgorithm.Twofish256, SymmetricKeyAlgorithm.IDEA}:
            pytest.xfail('Symmetric cipher {} not supported for encryption'.format(cipher))

        # test encrypting a message
        mtxt = "This message will have been encrypted"
        msg = PGPMessage.new(mtxt)
        emsg = pub.encrypt(msg, cipher=cipher)
        self.msgs[(pub.fingerprint, cipher)] = emsg
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:14,代码来源:test_05_actions.py

示例8: test_new_non_unicode

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_new_non_unicode(self):
        # this message text comes from http://www.columbia.edu/~fdc/utf8/
        text = u'色は匂へど 散りぬるを\n' \
               u'我が世誰ぞ 常ならむ\n' \
               u'有為の奥山 今日越えて\n' \
               u'浅き夢見じ 酔ひもせず'
        msg = PGPMessage.new(text.encode('jisx0213'), encoding='jisx0213')

        assert msg.type == 'literal'
        assert msg.message == text.encode('jisx0213')

        # see if GPG can parse our message
        assert self.gpg_message(msg).decode('jisx0213') == text
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:15,代码来源:test_05_actions.py

示例9: test_new

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_new(self, comp_alg, sensitive):
        mtxt = u"This is a new message!"
        msg = PGPMessage.new(mtxt, compression=comp_alg, sensitive=sensitive)

        assert isinstance(msg, PGPMessage)
        assert msg.filename == ('_CONSOLE' if sensitive else '')
        assert msg.is_sensitive is sensitive
        assert msg.type == 'literal'
        assert msg.message == mtxt
        assert msg._compression == comp_alg

        # see if GPG can parse our message
        assert self.gpg_message(msg).decode('utf-8') == mtxt
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:15,代码来源:test_05_actions.py

示例10: test_new_from_file

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_new_from_file(self, comp_alg, sensitive, path):
        msg = PGPMessage.new(path, file=True, compression=comp_alg, sensitive=sensitive)

        assert isinstance(msg, PGPMessage)
        assert msg.filename == ('_CONSOLE' if sensitive else os.path.basename(path))
        assert msg.type == 'literal'
        assert msg.is_sensitive is sensitive

        with open(path, 'rb') as tf:
            mtxt = tf.read()

            # see if GPG can parse our message
            assert self.gpg_message(msg) == mtxt
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:15,代码来源:test_05_actions.py

示例11: test_encrypt_message_select_uid

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_encrypt_message_select_uid(self):
        # generate a temporary key with two UIDs, then encrypt a message
        u1 = PGPUID.new('UID One')
        u2 = PGPUID.new('UID Two')
        k = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 512)

        flags = {KeyFlags.Certify, KeyFlags.Sign, KeyFlags.EncryptCommunications, KeyFlags.EncryptStorage}

        k.add_uid(u1, usage=flags, hashes=[HashAlgorithm.SHA1], ciphers=[SymmetricKeyAlgorithm.AES128])
        k.add_uid(u2, usage=flags, hashes=[HashAlgorithm.SHA1], ciphers=[SymmetricKeyAlgorithm.Camellia128])

        emsg = k.pubkey.encrypt(PGPMessage.new('This message is about to be encrypted'), user='UID Two')

        # assert that it was encrypted with Camellia128 and that we can decrypt it normally
        assert emsg._sessionkeys[0].decrypt_sk(k._key)[0] == SymmetricKeyAlgorithm.Camellia128
        assert k.decrypt(emsg).message == 'This message is about to be encrypted'
开发者ID:ddddavidee,项目名称:PGPy,代码行数:18,代码来源:test_05_actions.py

示例12: test_new_from_file

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_new_from_file(self, file, write_clean, gpg_print):
        msg = PGPMessage.new(file, file=True)

        assert isinstance(msg, PGPMessage)
        assert msg.type == 'literal'
        assert msg.is_sensitive is False

        assert file in self.attrs
        for attr, expected in self.attrs[file]:
            val = getattr(msg, attr)
            assert val == expected

        with write_clean('tests/testdata/cmsg.asc', 'w', str(msg)):
            out = gpg_print('cmsg.asc')
            if msg._message.format == 'b':
                out = out.encode('latin-1')
            assert out == msg.message
开发者ID:ddddavidee,项目名称:PGPy,代码行数:19,代码来源:test_05_actions.py

示例13: test_encrypt_passphrase_2

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_encrypt_passphrase_2(self):
        mtxt = "This message is to be encrypted"
        msg = PGPMessage.new(mtxt)
        assert not msg.is_encrypted

        sk = SymmetricKeyAlgorithm.AES256.gen_key()
        encmsg = msg.encrypt("QwertyUiop", sessionkey=sk).encrypt("AsdfGhjkl", sessionkey=sk)

        assert isinstance(encmsg, PGPMessage)
        assert encmsg.is_encrypted
        assert encmsg.type == 'encrypted'

        # decrypt with PGPy only, since GnuPG can't do multiple passphrases
        for passwd in ["QwertyUiop", "AsdfGhjkl"]:
            decmsg = encmsg.decrypt(passwd)

            assert isinstance(decmsg, PGPMessage)
            assert decmsg.type == msg.type
            assert decmsg.is_compressed
            assert decmsg.message == mtxt
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:22,代码来源:test_05_actions.py

示例14: test_encrypt_passphrase_2

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_encrypt_passphrase_2(self, write_clean, gpg_decrypt):
        msg = PGPMessage.new("This message is to be encrypted")
        sk = SymmetricKeyAlgorithm.AES256.gen_key()
        encmsg = msg.encrypt("QwertyUiop", sessionkey=sk).encrypt("AsdfGhjkl", sessionkey=sk)

        # make sure lit was untouched
        assert not msg.is_encrypted

        # make sure encmsg is encrypted
        assert encmsg.is_encrypted
        assert encmsg.type == 'encrypted'
        assert len(encmsg._sessionkeys) == 2

        # decrypt with PGPy
        for passphrase in ["QwertyUiop", "AsdfGhjkl"]:
            decmsg = encmsg.decrypt(passphrase)
            assert isinstance(decmsg, PGPMessage)
            assert decmsg.type == msg.type
            assert decmsg.is_compressed
            assert decmsg.message == msg.message
开发者ID:ddddavidee,项目名称:PGPy,代码行数:22,代码来源:test_05_actions.py

示例15: test_encrypt_passphrase

# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import new [as 别名]
    def test_encrypt_passphrase(self, comp_alg):
        mtxt = "This message is to be encrypted"
        msg = PGPMessage.new(mtxt, compression=comp_alg)
        assert not msg.is_encrypted

        encmsg = msg.encrypt("QwertyUiop")

        assert isinstance(encmsg, PGPMessage)
        assert encmsg.is_encrypted
        assert encmsg.type == 'encrypted'

        # decrypt with PGPy
        decmsg = encmsg.decrypt("QwertyUiop")

        assert isinstance(decmsg, PGPMessage)
        assert decmsg.type == msg.type
        assert decmsg.is_compressed == msg.is_compressed
        assert decmsg.message == mtxt
        assert decmsg._compression == msg._compression

        # decrypt with GPG via python-gnupg
        assert self.gpg_decrypt(encmsg, 'QwertyUiop').decode('utf-8') == decmsg.message
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:24,代码来源:test_05_actions.py


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