def test_from_string_pkcs8_extra_bytes(self): key_bytes = self._load_pkcs8_key_bytes() _, pem_bytes = pem.readPemBlocksFromFile( six.StringIO(_from_bytes(key_bytes)), _pure_python_crypt._PKCS8_MARKER) with mock.patch('pyasn1.codec.der.decoder.decode') as mock_decode: key_info, remaining = None, 'extra' mock_decode.return_value = (key_info, remaining) with self.assertRaises(ValueError): RsaSigner.from_string(key_bytes) # Verify mock was called. mock_decode.assert_called_once_with( pem_bytes, asn1Spec=_pure_python_crypt._PKCS8_SPEC)
def test_verify_unicode_success(self): to_sign = u'foo' signer = RsaSigner.from_string(self._load_private_key_bytes()) actual_signature = signer.sign(to_sign) verifier = RsaVerifier.from_string(self._load_public_key_bytes(), is_x509_cert=False) self.assertTrue(verifier.verify(to_sign, actual_signature))
def test_from_string_bogus_key(self): key_bytes = 'bogus-key' with self.assertRaises(ValueError): RsaSigner.from_string(key_bytes)
def test_from_string_pkcs12(self): key_bytes = self._load_pkcs12_key_bytes() with self.assertRaises(ValueError): RsaSigner.from_string(key_bytes)
def test_from_string_pkcs8_unicode(self): key_bytes = _from_bytes(self._load_pkcs8_key_bytes()) signer = RsaSigner.from_string(key_bytes) self.assertIsInstance(signer, RsaSigner) self.assertIsInstance(signer._key, rsa.key.PrivateKey)