Commit 73823549 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Add Manager.CredentialList()

parent 58b74cb1
package irmago package irmago
import "github.com/mhe/gabi" import (
"strings"
"github.com/mhe/gabi"
)
// credential represents an IRMA credential, whose zeroth attribute // credential represents an IRMA credential, whose zeroth attribute
// is always the secret key and the first attribute the metadata attribute. // is always the secret key and the first attribute the metadata attribute.
type credential struct { type credential struct {
*gabi.Credential *gabi.Credential
*MetadataAttribute *MetadataAttribute
info *Credential
}
// A Credential contains all information of an IRMA credential.
type Credential struct {
ID string // e.g., "irma-demo.RU.studentCard"
SignedOn Timestamp // Unix timestamp
Expires Timestamp // Unix timestamp
Type *CredentialType // Credential information from MetaStore
Issuer *Issuer // Issuer information from MetaStore
SchemeManager *SchemeManager // Scheme manager information from MetaStore
Attributes []TranslatedString // Human-readable rendered attributes
Logo string // Path to logo on storage
} }
// A CredentialList is a list of credentials (implements sort.Interface).
type CredentialList []*Credential
func newCredential(gabicred *gabi.Credential) (cred *credential) { func newCredential(gabicred *gabi.Credential) (cred *credential) {
cred = &credential{} meta := MetadataFromInt(gabicred.Attributes[1])
cred.Credential = gabicred credtype := meta.CredentialType()
cred.MetadataAttribute = MetadataFromInt(gabicred.Attributes[1]) issid := credtype.IssuerIdentifier()
cred.Pk = MetaStore.PublicKey(cred.CredentialType().IssuerIdentifier(), cred.KeyCounter())
attrs := make([]TranslatedString, len(credtype.Attributes))
for i := range credtype.Attributes {
val := string(gabicred.Attributes[i+2].Bytes())
attrs[i] = TranslatedString(map[string]string{"en": val, "nl": val})
}
cred = &credential{
Credential: gabicred,
MetadataAttribute: meta,
info: &Credential{
ID: credtype.Identifier().String(),
SignedOn: Timestamp(meta.SigningDate()),
Expires: Timestamp(meta.Expiry()),
Type: credtype,
Issuer: MetaStore.Issuers[issid],
SchemeManager: MetaStore.SchemeManagers[issid.SchemeManagerIdentifier()],
Attributes: attrs,
Logo: "", // TODO
},
}
cred.Pk = MetaStore.PublicKey(issid, cred.KeyCounter())
return return
} }
// Len implements sort.Interface.
func (cl CredentialList) Len() int {
return len(cl)
}
// Swap implements sort.Interface.
func (cl CredentialList) Swap(i, j int) {
cl[i], cl[j] = cl[j], cl[i]
}
// Less implements sort.Interface.
func (cl CredentialList) Less(i, j int) bool {
// TODO Decide on sorting, and if it depends on a TranslatedString, allow language choosing
return strings.Compare(cl[i].Type.Name["en"], cl[j].Type.Name["en"]) > 0
}
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"crypto/rand" "crypto/rand"
"sort"
"github.com/Roasbeef/go-go-gadget-paillier" "github.com/Roasbeef/go-go-gadget-paillier"
"github.com/mhe/gabi" "github.com/mhe/gabi"
) )
...@@ -31,6 +33,17 @@ func newCredentialManager() *CredentialManager { ...@@ -31,6 +33,17 @@ func newCredentialManager() *CredentialManager {
} }
} }
func (cm *CredentialManager) CredentialList() CredentialList {
list := CredentialList([]*Credential{})
for _, credlist := range cm.credentials {
for _, cred := range credlist {
list = append(list, cred.info)
}
}
sort.Sort(list)
return list
}
func (cm *CredentialManager) generateSecretKey() (sk *big.Int, err error) { func (cm *CredentialManager) generateSecretKey() (sk *big.Int, err error) {
return gabi.RandomBigInt(gabi.DefaultSystemParameters[1024].Lm) return gabi.RandomBigInt(gabi.DefaultSystemParameters[1024].Lm)
} }
......
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