Commit 0ce495f8 authored by Koen van Ingen's avatar Koen van Ingen
Browse files

Simpler attributeresultlist type

parent 5414cf36
...@@ -19,15 +19,14 @@ const ( ...@@ -19,15 +19,14 @@ const (
metadataLength = 1 + 3 + 2 + 2 + 16 metadataLength = 1 + 3 + 2 + 2 + 16
) )
type AttributeResultList struct {
AttributeResults []*AttributeResult
}
type AttributeResult struct { type AttributeResult struct {
AttributeValue string `json:"value"` // Value of the disclosed attribute AttributeValue string `json:"value"` // Value of the disclosed attribute
AttributeId AttributeTypeIdentifier `json:"id"` AttributeId AttributeTypeIdentifier `json:"id"`
AttributeProofStatus AttributeProofStatus `json:"status"` AttributeProofStatus AttributeProofStatus `json:"status"`
} }
type AttributeResultList []*AttributeResult
// AttributeProofStatus is the proof status of a single attribute // AttributeProofStatus is the proof status of a single attribute
type AttributeProofStatus string type AttributeProofStatus string
...@@ -482,14 +481,10 @@ func (disjunction *AttributeDisjunction) UnmarshalJSON(bytes []byte) error { ...@@ -482,14 +481,10 @@ func (disjunction *AttributeDisjunction) UnmarshalJSON(bytes []byte) error {
return nil return nil
} }
func (al *AttributeResultList) Append(result *AttributeResult) {
al.AttributeResults = append(al.AttributeResults, result)
}
func (al *AttributeResultList) String() string { func (al *AttributeResultList) String() string {
// TODO: pretty print? // TODO: pretty print?
str := "Attribute --- Value --- ProofStatus:" str := "Attribute --- Value --- ProofStatus:"
for _, v := range al.AttributeResults { for _, v := range *al {
str = str + "\n" + v.String() str = str + "\n" + v.String()
} }
return str return str
......
...@@ -38,7 +38,7 @@ func corruptProofString(proof string) string { ...@@ -38,7 +38,7 @@ func corruptProofString(proof string) string {
proofBytes := []byte(proof) proofBytes := []byte(proof)
// 15 because this is somewhere in a bigint in the json string // 15 because this is somewhere in a bigint in the json string
proofBytes[15] ^= 0x02 proofBytes[15] ^= 0x01
return string(proofBytes) return string(proofBytes)
} }
return proof return proof
...@@ -85,7 +85,7 @@ func TestManualSession(t *testing.T) { ...@@ -85,7 +85,7 @@ func TestManualSession(t *testing.T) {
t.Logf("Invalid proof result: %v Expected: %v", ps, irma.VALID) t.Logf("Invalid proof result: %v Expected: %v", ps, irma.VALID)
t.Fail() t.Fail()
} }
if attrStatus := result.ToAttributeResultList().AttributeResults[0].AttributeProofStatus; attrStatus != irma.PRESENT { if attrStatus := result.ToAttributeResultList()[0].AttributeProofStatus; attrStatus != irma.PRESENT {
t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.PRESENT) t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.PRESENT)
t.Fail() t.Fail()
} }
...@@ -160,12 +160,12 @@ func TestManualSessionInvalidRequest(t *testing.T) { ...@@ -160,12 +160,12 @@ func TestManualSessionInvalidRequest(t *testing.T) {
} }
// First attribute result is MISSING, because it is in the request but not disclosed // First attribute result is MISSING, because it is in the request but not disclosed
if attrStatus := result.ToAttributeResultList().AttributeResults[0].AttributeProofStatus; attrStatus != irma.MISSING { if attrStatus := result.ToAttributeResultList()[0].AttributeProofStatus; attrStatus != irma.MISSING {
t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.MISSING) t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.MISSING)
t.Fail() t.Fail()
} }
// Second attribute result is EXTRA, since it is disclosed, but not matching the sigrequest // Second attribute result is EXTRA, since it is disclosed, but not matching the sigrequest
if attrStatus := result.ToAttributeResultList().AttributeResults[1].AttributeProofStatus; attrStatus != irma.EXTRA { if attrStatus := result.ToAttributeResultList()[1].AttributeProofStatus; attrStatus != irma.EXTRA {
t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.EXTRA) t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.EXTRA)
t.Fail() t.Fail()
} }
...@@ -195,7 +195,7 @@ func TestManualSessionInvalidAttributeValue(t *testing.T) { ...@@ -195,7 +195,7 @@ func TestManualSessionInvalidAttributeValue(t *testing.T) {
t.Logf("Invalid proof result: %v Expected: %v", ps, irma.MISSING_ATTRIBUTES) t.Logf("Invalid proof result: %v Expected: %v", ps, irma.MISSING_ATTRIBUTES)
t.Fail() t.Fail()
} }
if attrStatus := result.ToAttributeResultList().AttributeResults[0].AttributeProofStatus; attrStatus != irma.INVALID_VALUE { if attrStatus := result.ToAttributeResultList()[0].AttributeProofStatus; attrStatus != irma.INVALID_VALUE {
t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.INVALID_VALUE) t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.INVALID_VALUE)
t.Fail() t.Fail()
} }
...@@ -255,11 +255,11 @@ func TestManualSessionMultiProof(t *testing.T) { ...@@ -255,11 +255,11 @@ func TestManualSessionMultiProof(t *testing.T) {
t.Logf("Invalid proof result: %v Expected: %v", result.ProofStatus, irma.VALID) t.Logf("Invalid proof result: %v Expected: %v", result.ProofStatus, irma.VALID)
t.Fail() t.Fail()
} }
if attrStatus := result.ToAttributeResultList().AttributeResults[0].AttributeProofStatus; attrStatus != irma.PRESENT { if attrStatus := result.ToAttributeResultList()[0].AttributeProofStatus; attrStatus != irma.PRESENT {
t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.PRESENT) t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.PRESENT)
t.Fail() t.Fail()
} }
if attrStatus := result.ToAttributeResultList().AttributeResults[1].AttributeProofStatus; attrStatus != irma.PRESENT { if attrStatus := result.ToAttributeResultList()[1].AttributeProofStatus; attrStatus != irma.PRESENT {
t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.PRESENT) t.Logf("Invalid attribute result value: %v Expected: %v", attrStatus, irma.PRESENT)
t.Fail() t.Fail()
} }
......
...@@ -112,7 +112,7 @@ func (disclosed DisclosedCredentialList) IsExpired() bool { ...@@ -112,7 +112,7 @@ func (disclosed DisclosedCredentialList) IsExpired() bool {
return false return false
} }
func (proofResult *ProofResult) ToAttributeResultList() *AttributeResultList { func (proofResult *ProofResult) ToAttributeResultList() AttributeResultList {
var resultList AttributeResultList var resultList AttributeResultList
for _, v := range proofResult.disjunctions { for _, v := range proofResult.disjunctions {
...@@ -122,9 +122,9 @@ func (proofResult *ProofResult) ToAttributeResultList() *AttributeResultList { ...@@ -122,9 +122,9 @@ func (proofResult *ProofResult) ToAttributeResultList() *AttributeResultList {
AttributeProofStatus: v.ProofStatus, AttributeProofStatus: v.ProofStatus,
} }
resultList.Append(&result) resultList = append(resultList, &result)
} }
return &resultList return resultList
} }
// Returns true if this attrId is present in one of the disjunctions // Returns true if this attrId is present in one of the disjunctions
......
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