本文整理匯總了Python中pgpdump.BinaryData.packets方法的典型用法代碼示例。如果您正苦於以下問題:Python BinaryData.packets方法的具體用法?Python BinaryData.packets怎麽用?Python BinaryData.packets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pgpdump.BinaryData
的用法示例。
在下文中一共展示了BinaryData.packets方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_parse_linus_binary
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_linus_binary(self):
with open('linus.gpg', 'rb') as keyfile:
rawdata = keyfile.read()
data = BinaryData(rawdata)
packets = list(data.packets())
self.assertEqual(44, len(packets))
seen = 0
for packet in packets:
# all 44 packets are of the known 'old' variety
self.assertFalse(packet.new)
if isinstance(packet, SignaturePacket):
# a random signature plucked off the key
if packet.key_id == 0xE7BFC8EC95861109:
seen += 1
self.check_sig_packet(packet, 540, 4, 0x10, 1319560576,
0xE7BFC8EC95861109, 1, 8)
self.assertEqual(2, len(packet.subpackets))
# a particularly dastardly sig- a ton of hashed sub parts,
# this is the "positive certification packet"
elif packet.key_id == 0x79BE3E4300411886 and \
packet.raw_sig_type == 0x13:
seen += 1
self.check_sig_packet(packet, 312, 4, 0x13, 1316554898,
0x79BE3E4300411886, 1, 2)
self.assertEqual(8, len(packet.subpackets))
# another sig from key above, the "subkey binding sig"
elif packet.key_id == 0x79BE3E4300411886 and \
packet.raw_sig_type == 0x18:
seen += 1
self.check_sig_packet(packet, 287, 4, 0x18, 1316554898,
0x79BE3E4300411886, 1, 2)
self.assertEqual(3, len(packet.subpackets))
self.assertEqual(3, seen)
示例2: test_parse_v3_pubkeys
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_v3_pubkeys(self):
'''Two older version 3 public keys.'''
rawdata = self.load_data('v3pubkeys.gpg')
data = BinaryData(rawdata)
packets = list(data.packets())
self.assertEqual(2, len(packets))
packet = packets[0]
self.assertTrue(isinstance(packet, PublicKeyPacket))
self.assertEqual(1, packet.raw_pub_algorithm)
self.assertEqual("rsa", packet.pub_algorithm_type)
self.assertEqual(944849149, packet.raw_creation_time)
self.assertIsNone(packet.expiration_time)
self.assertIsNotNone(packet.modulus)
self.assertEqual(2048, packet.modulus_bitlen)
self.assertIsNotNone(packet.exponent)
self.assertEqual(b"3FC0BF6B", packet.key_id)
self.assertEqual(b"7D263C88A1AB7737E31150CB4F3A211A",
packet.fingerprint)
packet = packets[1]
self.assertTrue(isinstance(packet, PublicKeyPacket))
self.assertEqual(1, packet.raw_pub_algorithm)
self.assertEqual("rsa", packet.pub_algorithm_type)
self.assertEqual(904151571, packet.raw_creation_time)
self.assertIsNone(packet.expiration_time)
self.assertIsNotNone(packet.modulus)
self.assertEqual(1024, packet.modulus_bitlen)
self.assertIsNotNone(packet.exponent)
self.assertEqual(b"3DDE776D", packet.key_id)
self.assertEqual(b"48A4F9F891F093019BC7FC532A3C5692",
packet.fingerprint)
示例3: test_parse_encrypted
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_encrypted(self):
rawdata = self.load_data("v4_secret_encrypted.gpg")
data = BinaryData(rawdata)
packets = list(data.packets())
self.assertEqual(7, len(packets))
subs_seen = 0
for packet in packets:
self.assertFalse(packet.new)
if isinstance(packet, SecretSubkeyPacket):
subs_seen += 1
if subs_seen == 1: # elg packet
self.assertEqual("elg", packet.pub_algorithm_type)
self.assertEqual(254, packet.s2k_id)
self.assertEqual("Iterated and Salted S2K", packet.s2k_type)
self.assertEqual("8d 89 bd df 01 0e 22 cd", packet.s2k_iv)
elif subs_seen == 2: # rsa packet
self.assertEqual("rsa", packet.pub_algorithm_type)
self.assertEqual(254, packet.s2k_id)
self.assertEqual("Iterated and Salted S2K", packet.s2k_type)
self.assertEqual("09 97 6b f5 d4 28 41 1d", packet.s2k_iv)
elif isinstance(packet, SecretKeyPacket):
self.assertEqual("dsa", packet.pub_algorithm_type)
self.assertEqual(254, packet.s2k_id)
self.assertEqual("Iterated and Salted S2K", packet.s2k_type)
self.assertEqual("CAST5", packet.s2k_cipher)
self.assertEqual("SHA1", packet.s2k_hash)
self.assertEqual("c3 87 eb ca 9b ce bc 78", packet.s2k_iv)
示例4: signature
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def signature(self):
try:
data = b64decode(self.pgp_signature)
except TypeError:
return None
data = BinaryData(data)
packets = list(data.packets())
return packets[0]
示例5: test_parse_partial_length
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_partial_length(self):
'''This file contains an encrypted message with a Partial Body Length header
Reference: http://tools.ietf.org/html/rfc4880#section-4.2.2.4
'''
rawdata = self.load_data('partial_length.gpg')
data = BinaryData(rawdata)
packets = list(data.packets())
self.assertEqual(2, len(packets))
示例6: test_parse_plain
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_plain(self):
""" The raw values below were extracted from the c version of pgpdump.
The hex strings it outputs were converted to base 10 by running the
following function over the hex strings:
def to_int(x):
return int(x.replace(' ', ''), 16)
"""
rawdata = self.load_data("v4_secret_plain.gpg")
data = BinaryData(rawdata)
packets = list(data.packets())
self.assertEqual(7, len(packets))
subs_seen = 0
for packet in packets:
self.assertFalse(packet.new)
if isinstance(packet, SecretSubkeyPacket):
subs_seen += 1
if subs_seen == 1: # elg packet
self.assertEqual("elg", packet.pub_algorithm_type)
self.assertEqual(0, packet.s2k_id)
self.assertEqual(None, packet.s2k_type)
self.assertEqual(None, packet.s2k_iv)
self.assertEqual(
245799026332407193298181926223748572866928987611495184689013385965880161244176879821250061522687647728L,
packet.exponent_x,
)
elif subs_seen == 2: # rsa packet
self.assertEqual("rsa", packet.pub_algorithm_type)
self.assertEqual(0, packet.s2k_id)
self.assertEqual(None, packet.s2k_type)
self.assertEqual(None, packet.s2k_iv)
self.assertEqual(
107429307998432888320715351604215972074903508478185926034856042440678824041847327442082101397552291647796540657257050768251344941490371163761048934745124363183224819621105784780195398083026664006729876758821509430352212953204518272377415915285011886868211417421097179985188014641310204357388385968166040278287L,
packet.multiplicative_inverse,
)
self.assertEqual(
139930219416447408374822893460828502304441966752753468842648203646336195082149424690339775194932419616945814365656771053789999508162542355224095838373016952414720809190039261860912609841054241835835137530162417625471114503804567967161522096406622711734972153324109508774000862492521907132111400296639152885151L,
packet.prime_p,
)
self.assertEqual(
141774976438365791329330227605232641244334061384594969589427240157587195987726021563323880620442249788289724672124037112182500862823754846020398652238714637523098123565121790819658975965315629614215592460191153065569430777288475743983312129144619017542854009503581558744199305796137178366407180728113362644607L,
packet.prime_q,
)
self.assertEqual(
5830467418164177455383939797360032476940913805978768568081128075462505586965694225559897974113088818228809697270431492119090365699278285350171676334156873270109344274747057694689185206358606371235913423003163252354603704380371252575866102476793736443620998412227609599802054206292004785471167177881398711806191315950196087041018693839148033680564198494910540148825273531803832541184563811332315506727878483469747798396155096313345751606322830230368849084875744911041500024805242117661173352379509490605300753957220916597285056567409410296154792321206401452887335121085203916552891062930596871199021743741984622581173L,
packet.exponent_d,
)
elif isinstance(packet, SecretKeyPacket):
self.assertEqual("dsa", packet.pub_algorithm_type)
self.assertEqual(254, packet.s2k_id)
self.assertEqual("GnuPG S2K", packet.s2k_type)
self.assertEqual("CAST5", packet.s2k_cipher)
self.assertEqual("SHA1", packet.s2k_hash)
self.assertEqual(None, packet.s2k_iv)
示例7: test_parse_linus_binary
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_linus_binary(self):
rawdata = self.load_data("linus.gpg")
data = BinaryData(rawdata)
packets = list(data.packets())
self.assertEqual(44, len(packets))
seen = 0
for packet in packets:
# all 44 packets are of the known 'old' variety
self.assertFalse(packet.new)
if isinstance(packet, SignaturePacket):
# a random signature plucked off the key
if packet.key_id == b"E7BFC8EC95861109":
seen += 1
self.check_sig_packet(packet, 540, 4, 0x10, 1319560576, b"E7BFC8EC95861109", 1, 8)
self.assertEqual(2, len(packet.subpackets))
# a particularly dastardly sig- a ton of hashed sub parts,
# this is the "positive certification packet"
elif packet.key_id == b"79BE3E4300411886" and packet.raw_sig_type == 0x13:
seen += 1
self.check_sig_packet(packet, 312, 4, 0x13, 1316554898, b"79BE3E4300411886", 1, 2)
self.assertEqual(8, len(packet.subpackets))
# another sig from key above, the "subkey binding sig"
elif packet.key_id == b"79BE3E4300411886" and packet.raw_sig_type == 0x18:
seen += 1
self.check_sig_packet(packet, 287, 4, 0x18, 1316554898, b"79BE3E4300411886", 1, 2)
self.assertEqual(3, len(packet.subpackets))
elif isinstance(packet, PublicSubkeyPacket):
seen += 1
self.assertEqual(4, packet.pubkey_version)
self.assertEqual(1316554898, packet.raw_creation_time)
self.assertEqual(1, packet.raw_pub_algorithm)
self.assertIsNotNone(packet.modulus)
self.assertEqual(65537, packet.exponent)
self.assertEqual(b"012F54CA", packet.fingerprint[32:])
elif isinstance(packet, PublicKeyPacket):
seen += 1
self.assertEqual(4, packet.pubkey_version)
self.assertEqual(1316554898, packet.raw_creation_time)
self.assertEqual(1, packet.raw_pub_algorithm)
self.assertEqual("RSA Encrypt or Sign", packet.pub_algorithm)
self.assertIsNotNone(packet.modulus)
self.assertEqual(65537, packet.exponent)
self.assertEqual(b"ABAF11C65A2970B130ABE3C479BE3E4300411886", packet.fingerprint)
self.assertEqual(b"79BE3E4300411886", packet.key_id)
elif isinstance(packet, UserIDPacket):
seen += 1
self.assertEqual("Linus Torvalds", packet.user_name)
self.assertEqual("[email protected]", packet.user_email)
self.assertEqual(6, seen)
示例8: test_parse_single_sig_packet
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_single_sig_packet(self):
base64_sig = b"iEYEABECAAYFAk6A4a4ACgkQXC5GoPU6du1ATACgodGyQne3Rb7"\
b"/eHBMRdau1KNSgZYAoLXRWt2G2wfp7haTBjJDFXMGsIMi"
sig = base64.b64decode(base64_sig)
data = BinaryData(sig)
packets = list(data.packets())
self.assertEqual(1, len(packets))
sig_packet = packets[0]
self.assertFalse(sig_packet.new)
self.check_sig_packet(sig_packet, 70, 4, 0, 1317069230,
0x5C2E46A0F53A76ED, 17, 2)
self.assertEqual(2, len(sig_packet.subpackets))
示例9: test_parse_single_sig_packet
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_single_sig_packet(self):
base64_sig = (
b"iEYEABECAAYFAk6A4a4ACgkQXC5GoPU6du1ATACgodGyQne3Rb7" b"/eHBMRdau1KNSgZYAoLXRWt2G2wfp7haTBjJDFXMGsIMi"
)
sig = base64.b64decode(base64_sig)
data = BinaryData(sig)
packets = list(data.packets())
self.assertEqual(1, len(packets))
sig_packet = packets[0]
self.assertFalse(sig_packet.new)
self.check_sig_packet(sig_packet, 70, 4, 0, 1317069230, b"5C2E46A0F53A76ED", 17, 2)
self.assertEqual(2, len(sig_packet.subpackets))
self.assertEqual(["Signature Creation Time", "Issuer"], [sp.name for sp in sig_packet.subpackets])
示例10: test_parse_mode_1002
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_mode_1002(self):
rawdata = self.load_data('secret_key_mode_1002.bin')
data = BinaryData(rawdata)
packets = list(data.packets())
self.assertEqual(7, len(packets))
for packet in packets:
self.assertFalse(packet.new)
if isinstance(packet, SecretKeyPacket):
# this block matches both top-level and subkeys
self.assertEqual("rsa", packet.pub_algorithm_type)
self.assertEqual(255, packet.s2k_id)
self.assertEqual("GnuPG S2K", packet.s2k_type)
self.assertEqual("Plaintext or unencrypted", packet.s2k_cipher)
self.assertEqual("Unknown", packet.s2k_hash)
self.assertEqual(None, packet.s2k_iv)
示例11: test_parse_junio
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_junio(self):
'''This key has a single user attribute packet, which also uses the new
size format on the outer packet, which is rare.'''
rawdata = self.load_data('junio.gpg')
data = BinaryData(rawdata)
packets = list(data.packets())
self.assertEqual(13, len(packets))
# 3 user ID packets
self.assertEqual(4, sum(1 for p in packets if p.raw == 13))
# 4 signature packets
self.assertEqual(6, sum(1 for p in packets if p.raw == 2))
# 1 public subkey packet
self.assertEqual(1, sum(1 for p in packets if p.raw == 14))
# 1 user attribute packet
self.assertEqual(1, sum(1 for p in packets if p.raw == 17))
# check the user attribute packet
ua_packet = [p for p in packets if p.raw == 17][0]
self.assertEqual("jpeg", ua_packet.image_format)
self.assertEqual(1513, len(ua_packet.image_data))
示例12: test_parse_dan
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_dan(self):
'''This key has DSA and ElGamal keys, which Linus' does not have.'''
rawdata = self.load_data('dan.gpg')
data = BinaryData(rawdata)
packets = list(data.packets())
self.assertEqual(9, len(packets))
# 3 user ID packets
self.assertEqual(3, sum(1 for p in packets if p.raw == 13))
# 4 signature packets
self.assertEqual(4, sum(1 for p in packets if p.raw == 2))
seen = 0
for packet in packets:
self.assertFalse(packet.new)
if isinstance(packet, PublicSubkeyPacket):
seen += 1
self.assertEqual(16, packet.raw_pub_algorithm)
self.assertEqual("elg", packet.pub_algorithm_type)
self.assertIsNotNone(packet.prime)
self.assertIsNone(packet.group_order)
self.assertIsNotNone(packet.group_gen)
self.assertIsNotNone(packet.key_value)
self.assertEqual(b"C3751D38", packet.fingerprint[32:])
elif isinstance(packet, PublicKeyPacket):
seen += 1
self.assertEqual(17, packet.raw_pub_algorithm)
self.assertEqual("dsa", packet.pub_algorithm_type)
self.assertIsNotNone(packet.prime)
self.assertIsNotNone(packet.group_order)
self.assertIsNotNone(packet.group_gen)
self.assertIsNotNone(packet.key_value)
self.assertEqual(b"A5CA9D5515DC2CA73DF748CA5C2E46A0F53A76ED",
packet.fingerprint)
self.assertEqual(2, seen)
示例13: test_parse_encrypted
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def test_parse_encrypted(self):
rawdata = self.load_data('v4_secret_encrypted.gpg')
data = BinaryData(rawdata)
packets = list(data.packets())
self.assertEqual(7, len(packets))
subs_seen = 0
for packet in packets:
self.assertFalse(packet.new)
if isinstance(packet, SecretSubkeyPacket):
subs_seen += 1
if subs_seen == 1:
# elg packet
self.assertEqual("elg", packet.pub_algorithm_type)
self.assertEqual(254, packet.s2k_id)
self.assertEqual("Iterated and Salted S2K", packet.s2k_type)
self.assertEqual(
bytearray(b"\x8d\x89\xbd\xdf\x01\x0e\x22\xcd"),
packet.s2k_iv)
elif subs_seen == 2:
# rsa packet
self.assertEqual("rsa", packet.pub_algorithm_type)
self.assertEqual(254, packet.s2k_id)
self.assertEqual("Iterated and Salted S2K", packet.s2k_type)
self.assertEqual(
bytearray(b"\x09\x97\x6b\xf5\xd4\x28\x41\x1d"),
packet.s2k_iv)
elif isinstance(packet, SecretKeyPacket):
self.assertEqual("dsa", packet.pub_algorithm_type)
self.assertEqual(254, packet.s2k_id)
self.assertEqual("Iterated and Salted S2K", packet.s2k_type)
self.assertEqual("CAST5", packet.s2k_cipher)
self.assertEqual("SHA1", packet.s2k_hash)
self.assertEqual(
bytearray(b"\xc3\x87\xeb\xca\x9b\xce\xbc\x78"),
packet.s2k_iv)
示例14: signature
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def signature(self):
if not self.signature_bytes:
return None
data = BinaryData(self.signature_bytes)
packets = list(data.packets())
return packets[0]
示例15: get_pubkey_id_from_binary
# 需要導入模塊: from pgpdump import BinaryData [as 別名]
# 或者: from pgpdump.BinaryData import packets [as 別名]
def get_pubkey_id_from_binary(data):
generator = BinaryData(data)
for packet in generator.packets():
if packet.raw == 6:
return packet.key_id