def test_cli_sign_writes_correct_signature_to_stdout(self): keypair = lamp.generate_keys() msg = 'hey' priv_name = 'test_priv.key' sig_name = 'test_sign.txt' expected_sig = lamp.sign_message(keypair.priv, msg) lamp.export_key(keypair.priv, priv_name) with patch('sys.stdout', new=StringIO()) as fake_out: lamp.cli(['sign', '--priv', priv_name, '--msg', msg]) self.assertEqual(lamp.str_to_sig(fake_out.getvalue()), expected_sig)
def test_cli_verify_signature_with_inline_msg(self): keypair = lamp.generate_keys() msg = 'hey' pub_name = 'test_pub.key' sig_name = 'test_sign.txt' sig = lamp.sign_message(keypair.priv, msg) lamp.export_key(keypair.pub, pub_name) with open(sig_name, 'w') as f: f.write(''.join(sig).strip()) with patch('sys.stdout', new=StringIO()) as fake_out: lamp.cli( ['verify', '--pub', pub_name, '--msg', msg, '--sig', sig_name]) self.assertEqual(fake_out.getvalue().strip(), 'valid')
def test_signature_is_256_blocks_long(self): msg = 'test message' signature = lamp.sign_message(self.priv, msg) self.assertEqual(len(signature), 256)
def test_verify_signature_fails_on_different_fails(self): msg = 'test message' signature = lamp.sign_message(self.priv, msg) different_pub = lamp.generate_keys().pub self.assertFalse(lamp.verify_signature(different_pub, msg, signature))
def test_verify_signature_succeeds_on_same_key(self): msg = 'test message' signature = lamp.sign_message(self.priv, msg) self.assertTrue(lamp.verify_signature(self.pub, msg, signature))
def test_verify_signature_fails_on_different_message(self): msg = 'a' different_msg = 'b' signature = lamp.sign_message(self.priv, msg) self.assertFalse( lamp.verify_signature(self.pub, different_msg, signature))