~ubuntu-branches/ubuntu/saucy/m2crypto/saucy

« back to all changes in this revision

Viewing changes to tests/test_pgp.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-11-06 01:28:39 UTC
  • mfrom: (2.2.5 sid)
  • Revision ID: james.westby@ubuntu.com-20091106012839-zjjugwmj8zggokqh
Tags: 0.20.1-1ubuntu1
* Merge from debian testing, remaining changes:
  - debian/rules; enable testsuite, add more files to "clean" rule.
  - tests/test_ssl.py: use signal 9 to kill old s_server processes
    to work around build HUP signal-ignore-mask (LP: #451998).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""PGP test program.
 
4
 
 
5
Copyright (c) 1999 Ng Pheng Siong. All rights reserved."""
 
6
 
 
7
import unittest
 
8
from M2Crypto import EVP, PGP
 
9
from cStringIO import StringIO
 
10
 
 
11
 
 
12
class PGPTestCase(unittest.TestCase):
 
13
 
 
14
    def test_simple(self):
 
15
        pkr = PGP.load_pubring('tests/pubring.pgp')
 
16
        daft = pkr['daft']
 
17
        daft_pkt = daft._pubkey_pkt.pack()
 
18
        s1 = EVP.MessageDigest('sha1')
 
19
        s1.update(daft_pkt)
 
20
        s1f = `s1.final()`
 
21
    
 
22
        buf = StringIO(daft_pkt)
 
23
        ps = PGP.packet_stream(buf)
 
24
        dift_pkt = ps.read()
 
25
        s2 = EVP.MessageDigest('sha1')
 
26
        s2.update(dift_pkt.pack())
 
27
        s2f = `s2.final()`
 
28
 
 
29
        self.assertEqual(s1f, s2f)
 
30
 
 
31
def suite():
 
32
    suite = unittest.TestSuite()
 
33
    suite.addTest(unittest.makeSuite(PGPTestCase))
 
34
    return suite
 
35
 
 
36
 
 
37
if __name__ == '__main__':
 
38
    Rand.load_file('randpool.dat', -1)
 
39
    unittest.TextTestRunner().run(suite())
 
40
    Rand.save_file('randpool.dat')