Commit 3042a679 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

feat: add RevocationSupported bool to AttributeList, CredentialInfo

Also simplifies how CredentialInfo instances are computed from AttributeLists.
parent d013400e
......@@ -41,27 +41,35 @@ type MetadataAttribute struct {
// AttributeList contains attributes, excluding the secret key,
// providing convenient access to the metadata attribute.
type AttributeList struct {
*MetadataAttribute `json:"-"`
Ints []*big.Int
Revoked bool `json:",omitempty"`
strings []TranslatedString
attrMap map[AttributeTypeIdentifier]TranslatedString
info *CredentialInfo
h string
*MetadataAttribute `json:"-"`
Ints []*big.Int
Revoked bool `json:",omitempty"`
RevocationSupported bool `json:,omitempty`
strings []TranslatedString
attrMap map[AttributeTypeIdentifier]TranslatedString
info *CredentialInfo
h string
}
// NewAttributeListFromInts initializes a new AttributeList from a list of bigints.
func NewAttributeListFromInts(ints []*big.Int, conf *Configuration) *AttributeList {
al := &AttributeList{
Ints: ints,
MetadataAttribute: MetadataFromInt(ints[0], conf),
metadata := MetadataFromInt(ints[0], conf)
credtype := metadata.CredentialType()
idx := credtype.RevocationIndex + 1
var rev bool
if credtype != nil {
rev = len(ints) > idx && ints[idx] != nil && ints[idx].Cmp(bigZero) != 0
}
return &AttributeList{
Ints: ints,
MetadataAttribute: metadata,
RevocationSupported: rev,
}
return al
}
func (al *AttributeList) Info() *CredentialInfo {
if al.info == nil {
al.info = NewCredentialInfo(al.Ints, al.Conf)
al.info = al.CredentialInfo()
}
al.info.Revoked = al.Revoked
return al.info
......@@ -95,11 +103,11 @@ func (al *AttributeList) Hash() string {
return al.h
}
func (al *AttributeList) Map(conf *Configuration) map[AttributeTypeIdentifier]TranslatedString {
func (al *AttributeList) Map() map[AttributeTypeIdentifier]TranslatedString {
if al.attrMap == nil {
al.attrMap = make(map[AttributeTypeIdentifier]TranslatedString)
ctid := al.CredentialType().Identifier()
attrTypes := conf.CredentialTypes[ctid].AttributeTypes
attrTypes := al.Conf.CredentialTypes[ctid].AttributeTypes
for i, val := range al.Strings() {
if attrTypes[i].RevocationAttribute {
continue
......
......@@ -4,43 +4,41 @@ import (
"fmt"
"strings"
"time"
"github.com/privacybydesign/gabi/big"
)
// CredentialInfo contains all information of an IRMA credential.
type CredentialInfo struct {
ID string // e.g., "studentCard"
IssuerID string // e.g., "RU"
SchemeManagerID string // e.g., "irma-demo"
SignedOn Timestamp // Unix timestamp
Expires Timestamp // Unix timestamp
Attributes map[AttributeTypeIdentifier]TranslatedString // Human-readable rendered attributes
Hash string // SHA256 hash over the attributes
Revoked bool // If the credential has been revoked
ID string // e.g., "studentCard"
IssuerID string // e.g., "RU"
SchemeManagerID string // e.g., "irma-demo"
SignedOn Timestamp // Unix timestamp
Expires Timestamp // Unix timestamp
Attributes map[AttributeTypeIdentifier]TranslatedString // Human-readable rendered attributes
Hash string // SHA256 hash over the attributes
Revoked bool // If the credential has been revoked
RevocationSupported bool // If the credential supports creating nonrevocation proofs
}
// A CredentialInfoList is a list of credentials (implements sort.Interface).
type CredentialInfoList []*CredentialInfo
func NewCredentialInfo(ints []*big.Int, conf *Configuration) *CredentialInfo {
meta := MetadataFromInt(ints[0], conf)
credtype := meta.CredentialType()
func (attrs *AttributeList) CredentialInfo() *CredentialInfo {
credtype := attrs.CredentialType()
if credtype == nil {
return nil
}
attrs := NewAttributeListFromInts(ints, conf)
id := credtype.Identifier()
issid := id.IssuerIdentifier()
return &CredentialInfo{
ID: id.Name(),
IssuerID: issid.Name(),
SchemeManagerID: issid.SchemeManagerIdentifier().Name(),
SignedOn: Timestamp(meta.SigningDate()),
Expires: Timestamp(meta.Expiry()),
Attributes: attrs.Map(conf),
Hash: attrs.Hash(),
ID: id.Name(),
IssuerID: issid.Name(),
SchemeManagerID: issid.SchemeManagerIdentifier().Name(),
SignedOn: Timestamp(attrs.SigningDate()),
Expires: Timestamp(attrs.Expiry()),
Attributes: attrs.Map(),
Hash: attrs.Hash(),
Revoked: attrs.Revoked,
RevocationSupported: attrs.RevocationSupported,
}
}
......
......@@ -555,7 +555,7 @@ func (cr *CredentialRequest) Info(conf *Configuration, metadataVersion byte) (*C
if err != nil {
return nil, err
}
return NewCredentialInfo(list.Ints, conf), nil
return list.CredentialInfo(), nil
}
// Validate checks that this credential request is consistent with the specified Configuration:
......
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