aboutsummaryrefslogtreecommitdiff
path: root/types
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-23 12:05:43 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-23 12:05:43 +0100
commit7ca509cc468e8bff5188ff06b87f758fca8ae39a (patch)
treeae11d6a633286c18127097225196b9d95a4be58d /types
parentb4dd74a3f36ca46b7bcda69e8d95949babfeb76d (diff)
started using Fingerprint() instead of String()
Diffstat (limited to 'types')
-rw-r--r--types/namespace_pool.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/types/namespace_pool.go b/types/namespace_pool.go
index 0f30567..1e9e8f6 100644
--- a/types/namespace_pool.go
+++ b/types/namespace_pool.go
@@ -6,7 +6,7 @@ import (
// NamespacePool is a pool of namespaces that contain complete verification keys
type NamespacePool struct {
- pool map[string]*Namespace
+ pool map[[NamespaceFingerprintSize]byte]*Namespace
list []*Namespace
// If we need to update this structure without a restart => add mutex.
}
@@ -16,17 +16,21 @@ type NamespacePool struct {
// complete verification key. The latter is determined by namespaceWithKey().
func NewNamespacePool(namespaces []*Namespace) (*NamespacePool, error) {
np := &NamespacePool{
- pool: make(map[string]*Namespace),
+ pool: make(map[[NamespaceFingerprintSize]byte]*Namespace),
list: make([]*Namespace, 0),
}
for _, namespace := range namespaces {
if !namespaceWithKey(namespace.Format) {
return nil, fmt.Errorf("need verification key in namespace pool: %v", namespace.Format)
}
- if _, ok := np.pool[namespace.String()]; ok {
+ fpr, err := namespace.Fingerprint()
+ if err != nil {
+ return nil, fmt.Errorf("need fingerprint in namespace pool: %v", err)
+ }
+ if _, ok := np.pool[*fpr]; ok {
return nil, fmt.Errorf("duplicate namespace: %v", namespace.String())
}
- np.pool[namespace.String()] = namespace
+ np.pool[*fpr] = namespace
np.list = append(np.list, namespace)
}
return np, nil
@@ -34,7 +38,11 @@ func NewNamespacePool(namespaces []*Namespace) (*NamespacePool, error) {
// Find checks if namespace is a member of the namespace pool.
func (np *NamespacePool) Find(namespace *Namespace) (*Namespace, bool) {
- if _, ok := np.pool[namespace.String()]; !ok {
+ fpr, err := namespace.Fingerprint()
+ if err != nil {
+ return nil, false
+ }
+ if _, ok := np.pool[*fpr]; !ok {
return nil, false
}
// If the passed namespace is a key fingerprint the actual key needs to be