~exarkun/pyopenssl/rsa-check

« back to all changes in this revision

Viewing changes to test/test_crypto.py

  • Committer: Jean-Paul Calderone
  • Date: 2009-05-13 18:14:30 UTC
  • Revision ID: exarkun@divmod.com-20090513181430-oz77e033hmptieoj
test the negative path through PKeyType.check

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
"""
89
89
encryptedPrivateKeyPEMPassphrase = "foobar"
90
90
 
 
91
inconsistentPrivateKeyPEM = """-----BEGIN RSA PRIVATE KEY-----
 
92
MIIBPAIBAAJBAKy+e3dulvXzV7zoTZWc5TzgApr8DmeQHTYC8ydfzH7EECe4R1Xh
 
93
5kwIzOuuFfn178FBiS84gngaNcrFi0Z5fAkCAwEaAQJBAIqm/bz4NA1H++Vx5Ewx
 
94
OcKp3w19QSaZAwlGRtsUxrP7436QjnREM3Bm8ygU11BjkPVmtrKm6AayQfCHqJoT
 
95
zIECIQDW0BoMoL0HOYM/mrTLhaykYAVqgIeJsPjvkEhTFXWBuQIhAM3deFAvWNu4
 
96
nklUQ37XsCT2c9tmNt1LAT+slG2JOTTRAiAuXDtC/m3NYVwyHfFm+zKHRzHkClk2
 
97
HjubeEgjpj32AQIhAJqMGTaZVOwevTXvvHwNeH+vRWsAYU/gbx+OQB+7VOcBAiEA
 
98
oolb6NMg/R3enNPvS1O4UU1H8wpaF77L4yiSWlE0p4w=
 
99
-----END RSA PRIVATE KEY-----
 
100
"""
 
101
 
 
102
 
91
103
 
92
104
class _Python23TestCaseHelper:
93
105
    # Python 2.3 compatibility.
179
191
    def test_pregeneration(self):
180
192
        """
181
193
        L{PKeyType.bits} and L{PKeyType.type} return C{0} before the key is
 
194
        generated.  L{PKeyType.check} raises L{TypeError} before the key is
182
195
        generated.
183
196
        """
184
197
        key = PKey()
185
198
        self.assertEqual(key.type(), 0)
186
199
        self.assertEqual(key.bits(), 0)
 
200
        self.assertRaises(TypeError, key.check)
187
201
 
188
202
 
189
203
    def test_failedGeneration(self):
262
276
             self.assertEqual(key.bits(), bits)
263
277
 
264
278
 
 
279
    def test_inconsistentKey(self):
 
280
        """
 
281
        L{PKeyType.check} returns C{False} if the key is not consistent.
 
282
        """
 
283
        key = load_privatekey(FILETYPE_PEM, inconsistentPrivateKeyPEM)
 
284
        self.assertFalse(key.check())
 
285
 
265
286
 
266
287
class X509NameTests(TestCase, _Python23TestCaseHelper):
267
288
    """