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

Bless gorename

parent 50a45763
......@@ -6,8 +6,8 @@ import (
"github.com/mhe/gabi"
)
// SchemeManagerDescription describes a scheme manager.
type SchemeManagerDescription struct {
// SchemeManager describes a scheme manager.
type SchemeManager struct {
Name string `xml:"Id"`
URL string `xml:"Contact"`
HRName string `xml:"Name"`
......@@ -19,8 +19,8 @@ type SchemeManagerDescription struct {
XMLName xml.Name `xml:"SchemeManager"`
}
// IssuerDescription describes an issuer.
type IssuerDescription struct {
// Issuer describes an issuer.
type Issuer struct {
HRName string `xml:"Name"`
HRShortName string `xml:"ShortName"`
Name string `xml:"ID"`
......@@ -32,8 +32,8 @@ type IssuerDescription struct {
identifier *IssuerIdentifier
}
// CredentialDescription is a description of a credential type, specifying (a.o.) its name, issuer, and attributes.
type CredentialDescription struct {
// CredentialType is a description of a credential type, specifying (a.o.) its name, issuer, and attributes.
type CredentialType struct {
HRName string `xml:"Name"`
HRShortName string `xml:"ShortName"`
IssuerName string `xml:"IssuerID"`
......@@ -54,18 +54,18 @@ type AttributeDescription struct {
}
// Identifier returns the identifier of the specified credential type.
func (cd *CredentialDescription) Identifier() string {
func (cd *CredentialType) Identifier() string {
return cd.SchemeManagerName + "." + cd.IssuerName + "." + cd.Name
}
// Identifier returns the identifier of the specified issuer description.
func (id *IssuerDescription) Identifier() string {
func (id *Issuer) Identifier() string {
return id.SchemeManagerName + "." + id.Name
}
// CurrentPublicKey returns the latest known public key of the issuer identified by this instance.
func (id *IssuerDescription) CurrentPublicKey() *gabi.PublicKey {
keys := MetaStore.publickeys[id.Identifier()]
func (id *Issuer) CurrentPublicKey() *gabi.PublicKey {
keys := MetaStore.PublicKeys[id.Identifier()]
if keys == nil || len(keys) == 0 {
return nil
}
......@@ -73,8 +73,8 @@ func (id *IssuerDescription) CurrentPublicKey() *gabi.PublicKey {
}
// PublicKey returns the specified public key of the issuer identified by this instance.
func (id *IssuerDescription) PublicKey(index int) *gabi.PublicKey {
keys := MetaStore.publickeys[id.Identifier()]
func (id *Issuer) PublicKey(index int) *gabi.PublicKey {
keys := MetaStore.PublicKeys[id.Identifier()]
if keys == nil || index >= len(keys) {
return nil
}
......
......@@ -12,14 +12,14 @@ func TestParseStore(t *testing.T) {
t.Fatal(err)
}
assert.NotNil(t, MetaStore.issuers["irma-demo.RU"].CurrentPublicKey().N, "irma-demo.RU public key has no modulus")
assert.Equal(t, MetaStore.managers["irma-demo"].HRName, "Irma Demo", "irma-demo scheme manager has unexpected name")
assert.NotNil(t, MetaStore.Issuers["irma-demo.RU"].CurrentPublicKey().N, "irma-demo.RU public key has no modulus")
assert.Equal(t, MetaStore.SchemeManagers["irma-demo"].HRName, "Irma Demo", "irma-demo scheme manager has unexpected name")
assert.Equal(t,
"Radboud Universiteit Nijmegen",
MetaStore.issuers["irma-demo.RU"].HRName,
MetaStore.Issuers["irma-demo.RU"].HRName,
"irma-demo.RU issuer has unexpected name")
assert.Equal(t,
"Student Card",
MetaStore.credentials["irma-demo.RU.studentCard"].HRShortName,
MetaStore.Credentials["irma-demo.RU.studentCard"].HRShortName,
"irma-demo.RU.studentCard has unexpected name")
}
......@@ -12,32 +12,32 @@ import (
// MetaStore is the global instance of ConfigurationStore
var MetaStore = ConfigurationStore{
make(map[string]*SchemeManagerDescription),
make(map[string]*IssuerDescription),
make(map[string]*CredentialDescription),
make(map[string]*SchemeManager),
make(map[string]*Issuer),
make(map[string]*CredentialType),
make(map[string][]*gabi.PublicKey),
}
// ConfigurationStore keeps track of scheme managers, issuers, credential types and public keys.
// Use the global MetaStore instance.
type ConfigurationStore struct {
managers map[string]*SchemeManagerDescription
issuers map[string]*IssuerDescription
credentials map[string]*CredentialDescription
publickeys map[string][]*gabi.PublicKey
SchemeManagers map[string]*SchemeManager
Issuers map[string]*Issuer
Credentials map[string]*CredentialType
PublicKeys map[string][]*gabi.PublicKey
}
// ParseFolder populates the current store by parsing the specified irma_configuration folder,
// listing the containing scheme managers, issuers, credential types and public keys.
func (store *ConfigurationStore) ParseFolder(path string) error {
return iterateSubfolders(path, func(dir string) error {
manager := &SchemeManagerDescription{}
manager := &SchemeManager{}
exists, err := pathToDescription(dir+"/description.xml", manager)
if err != nil {
return err
}
if exists {
MetaStore.managers[manager.Name] = manager
MetaStore.SchemeManagers[manager.Name] = manager
return store.parseIssuerFolders(dir)
}
return nil
......@@ -46,13 +46,13 @@ func (store *ConfigurationStore) ParseFolder(path string) error {
func (store *ConfigurationStore) parseIssuerFolders(path string) error {
return iterateSubfolders(path, func(dir string) error {
issuer := &IssuerDescription{}
issuer := &Issuer{}
exists, err := pathToDescription(dir+"/description.xml", issuer)
if err != nil {
return err
}
if exists {
store.issuers[issuer.Identifier()] = issuer
store.Issuers[issuer.Identifier()] = issuer
if err = store.parseCredentialsFolder(dir + "/Issues/"); err != nil {
return err
}
......@@ -62,7 +62,7 @@ func (store *ConfigurationStore) parseIssuerFolders(path string) error {
})
}
func (store *ConfigurationStore) parseKeysFolder(issuer *IssuerDescription, path string) error {
func (store *ConfigurationStore) parseKeysFolder(issuer *Issuer, path string) error {
for i := 0; ; i++ {
file := path + strconv.Itoa(i) + ".xml"
if _, err := os.Stat(file); err != nil {
......@@ -72,20 +72,20 @@ func (store *ConfigurationStore) parseKeysFolder(issuer *IssuerDescription, path
if err != nil {
return err
}
MetaStore.publickeys[issuer.Identifier()] = append(MetaStore.publickeys[issuer.Identifier()], pk)
MetaStore.PublicKeys[issuer.Identifier()] = append(MetaStore.PublicKeys[issuer.Identifier()], pk)
}
return nil
}
func (store *ConfigurationStore) parseCredentialsFolder(path string) error {
return iterateSubfolders(path, func(dir string) error {
cred := &CredentialDescription{}
cred := &CredentialType{}
exists, err := pathToDescription(dir+"/description.xml", cred)
if err != nil {
return err
}
if exists {
store.credentials[cred.Identifier()] = cred
store.Credentials[cred.Identifier()] = cred
}
return nil
})
......
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