Commit 4472df6b authored by Koen van Ingen's avatar Koen van Ingen
Browse files

fix: decode new attributes with new metadata version

parent 634bebc7
......@@ -112,8 +112,15 @@ func (al *AttributeList) Strings() []TranslatedString {
}
func (al *AttributeList) decode(i int) *string {
bi := new(big.Int).Set(al.Ints[i+1])
if al.MetadataAttribute.Version() >= 3 {
attr := al.Ints[i+1]
metadataVersion := al.MetadataAttribute.Version()
return decodeAttribute(attr, metadataVersion)
}
// Decode attribute value into string according to metadataVersion
func decodeAttribute(attr *big.Int, metadataVersion byte) *string {
bi := new(big.Int).Set(attr)
if metadataVersion >= 3 {
if bi.Bit(0) == 0 { // attribute does not exist
return nil
}
......
......@@ -336,3 +336,16 @@ func TestVerifyInValidNonce(t *testing.T) {
require.Equal(t, proofStatus, INVALID_CRYPTO)
require.Nil(t, disclosed)
}
// Test attribute decoding with both old and new metadata versions
func TestAttributeDecoding(t *testing.T) {
expected := "male"
newAttribute, _ := new(big.Int).SetString("3670202571", 10)
newString := decodeAttribute(newAttribute, 3)
require.Equal(t, *newString, expected)
oldAttribute, _ := new(big.Int).SetString("1835101285", 10)
oldString := decodeAttribute(oldAttribute, 2)
require.Equal(t, *oldString, expected)
}
......@@ -157,8 +157,8 @@ func NewDisclosedCredentialFromADisclosed(aDisclosed map[int]*big.Int, configura
}
description := cred.Attributes[k-2]
attributeValue := string(v.Bytes())
attributes[description.GetAttributeTypeIdentifier(cred.Identifier())] = &attributeValue
attributeValue := decodeAttribute(v, metadata.Version())
attributes[description.GetAttributeTypeIdentifier(cred.Identifier())] = attributeValue
}
return &DisclosedCredential{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment