def testA01KnownGood(self): """SignatureSubpacket: create_SignatureSubpacket() using known values""" pkt_d = read_test_file(['pgpfiles', 'pkt', 'sig', 'sig.DSAELG1.pkt']) sig = Signature(pkt_d) for good in sig.body.hashed_subpkts: subpkt = create_SignatureSubpacket(good.type, good.value) self.assertEqual(subpkt.type, good.type) self.assertEqual(subpkt.value, good.value) for good in sig.body.unhashed_subpkts: subpkt = create_SignatureSubpacket(good.type, good.value) self.assertEqual(subpkt.type, good.type) self.assertEqual(subpkt.value, good.value)
def testE06SignatureCreationV4RSABinarySubpackets(self): "crypto.signature: sign() v4 RSA with hashed subpkts BINARY" seckey_d = read_test_file(['pgpfiles','key','RSA1.sec.gpg']) seckeypkt = list_pkts(seckey_d)[0] msg = 'testmessage\r\nyaddaboo\n\nsdfll\r\n' sigtype = SIG_BINARY created = int(time.time()) - 5000 subpkt_created = create_SignatureSubpacket(SIGSUB_CREATED, created) subpkt_keyid = create_SignatureSubpacket(SIGSUB_SIGNERID, seckeypkt.body.id) opts = {'passphrase':'test', 'hashed_subpkts':[subpkt_created], 'unhashed_subpkts':[subpkt_keyid]} sigpkt = sign(sigtype, msg, seckeypkt, **opts) verified = verify(sigpkt, msg, seckeypkt) self.assertEqual(1, verified)
def testE06SignatureCreationV4RSABinarySubpackets(self): "crypto.signature: sign() v4 RSA with hashed subpkts BINARY" seckey_d = read_test_file(['pgpfiles', 'key', 'RSA1.sec.gpg']) seckeypkt = list_pkts(seckey_d)[0] msg = 'testmessage\r\nyaddaboo\n\nsdfll\r\n' sigtype = SIG_BINARY created = int(time.time()) - 5000 subpkt_created = create_SignatureSubpacket(SIGSUB_CREATED, created) subpkt_keyid = create_SignatureSubpacket(SIGSUB_SIGNERID, seckeypkt.body.id) opts = { 'passphrase': 'test', 'hashed_subpkts': [subpkt_created], 'unhashed_subpkts': [subpkt_keyid] } sigpkt = sign(sigtype, msg, seckeypkt, **opts) verified = verify(sigpkt, msg, seckeypkt) self.assertEqual(1, verified)
def testA02Sanity(self): """SignatureSubpacket: create_SignatureSubpacket() good names, values sanity""" import time t = int(time.time()) subvals = [(SIGSUB_SIGNERID, '3366A0B0C0D0E0F0'), (SIGSUB_CREATED, t), (SIGSUB_REVOCABLE, 0), (SIGSUB_TRUST, (56, 84)), (SIGSUB_SYMCODE, [0, 1, 2]), (SIGSUB_REVOKER, (1, 1, 'A1A2A3A4A5A6A7A8A9A0B1B2B3B4B5B6B7B8B9B0')), (SIGSUB_NOTE, ([1, 2, 3, 4], 'note name', 'note value')), (SIGSUB_KEYSERV, 'SomeURL'), (SIGSUB_REVOCREASON, (1, 'Oh, just because.'))] for vals in subvals: subpkt = create_SignatureSubpacket(vals[0], vals[1]) self.assertEqual(subpkt.type, vals[0]) self.assertEqual(subpkt.value, vals[1])