Пример #1
0
 def test_encode_decode(self):
     test_claim = ClaimDict.load_dict(example_010)
     self.assertEquals(test_claim.is_certificate, False)
     self.assertDictEqual(test_claim.claim_dict, example_010)
     test_pb = test_claim.protobuf
     self.assertDictEqual(
         ClaimDict.load_protobuf(test_pb).claim_dict, example_010)
     self.assertEquals(test_pb.ByteSize(),
                       ClaimDict.load_protobuf(test_pb).protobuf_len)
     self.assertEquals(test_claim.json_len,
                       ClaimDict.load_protobuf(test_pb).json_len)
Пример #2
0
 def test_fail_to_validate_fake_ecdsa_signature(self):
     signed = ClaimDict.load_dict(example_010).sign(secp256k1_private_key,
                                                    claim_address_1,
                                                    claim_id_1,
                                                    curve=SECP256k1)
     signed_copy = ClaimDict.load_protobuf(signed.protobuf)
     fake_key = get_signer(SECP256k1).generate().private_key.to_pem()
     fake_cert = ClaimDict.generate_certificate(fake_key, curve=SECP256k1)
     self.assertRaises(ecdsa.keys.BadSignatureError,
                       signed_copy.validate_signature, claim_address_2,
                       fake_cert)
Пример #3
0
 def test_validate_ecdsa_signature(self):
     cert = ClaimDict.generate_certificate(nist384p_private_key,
                                           curve=NIST384p)
     signed = ClaimDict.load_dict(example_010).sign(nist384p_private_key,
                                                    claim_address_2,
                                                    claim_id_1,
                                                    curve=NIST384p)
     self.assertDictEqual(signed.claim_dict, claim_010_signed_nist384p)
     signed_copy = ClaimDict.load_protobuf(signed.protobuf)
     self.assertEquals(
         signed_copy.validate_signature(claim_address_2, cert), True)
Пример #4
0
 def test_fail_to_validate_with_no_claim_address(self):
     cert = ClaimDict.generate_certificate(secp256k1_private_key,
                                           curve=SECP256k1)
     self.assertDictEqual(cert.claim_dict, secp256k1_cert)
     signed = ClaimDict.load_dict(example_010).sign(secp256k1_private_key,
                                                    claim_address_2,
                                                    claim_id_1,
                                                    curve=SECP256k1)
     self.assertDictEqual(signed.claim_dict, claim_010_signed_secp256k1)
     signed_copy = ClaimDict.load_protobuf(signed.protobuf)
     self.assertRaises(Exception, signed_copy.validate_signature, None,
                       cert)