def testValidateSignedResource(): resource = '{"1":"test"}' vk, sk = ecdsa.generate64uKeys() signature = ecdsa.signResource64u(resource, sk) # returns parsed json if signature is valid parsedResource = ecdsa.validateSignedResource(signature, resource, vk) assert parsedResource == json.loads(resource)
def testValidateSignedResourceInvalidSignature(): resource = '{"1":"test"}' vk, sk = ecdsa.generate64uKeys() signature = ecdsa.signResource64u(resource, sk) with pytest.raises(didering.ValidationError) as ex: ecdsa.validateSignedResource(signature, '{"1":"tes"}', vk) assert ex.value == "Unverifiable signature"
def testSignResource64u(): resource = "message" vk, sk = ecdsa.generate64uKeys() signature = ecdsa.signResource64u(resource, sk) assert str(signature) == signature assert len(signature) == 88 assert len(str64uToBytes(signature)) == 64
def testValidateSignedResourceInvalidJson(): resource = "message" vk, sk = ecdsa.generate64uKeys() signature = ecdsa.signResource64u(resource, sk) with pytest.raises(didering.ValidationError) as ex: ecdsa.validateSignedResource(signature, resource, vk) assert ex.value == "Invalid JSON"
def testGenerate64uKeys(): vk, sk = ecdsa.generate64uKeys() assert len(vk) == 88 assert len(sk) == 44 # check that keys are strings assert str(vk) == vk assert str(sk) == sk