"veyron2/security": IsValidBlessingPattern
Added a method to checking whether a given BlessingPattern is
well-formed.
Change-Id: I4b6d0caa6df6934fd2eba2cda565b539e6ff676c
diff --git a/runtimes/google/rt/blessingstore.go b/runtimes/google/rt/blessingstore.go
index f353111..2feed95 100644
--- a/runtimes/google/rt/blessingstore.go
+++ b/runtimes/google/rt/blessingstore.go
@@ -4,7 +4,6 @@
"errors"
"fmt"
"reflect"
- "strings"
"sync"
isecurity "veyron/runtimes/google/security"
@@ -50,8 +49,8 @@
if !reflect.DeepEqual(blessings.PublicKey(), s.publicKey) {
return errStoreAddMismatch
}
- if err := validateBlessingPattern(forPeers); err != nil {
- return err
+ if !forPeers.IsValid() {
+ return fmt.Errorf("%q is an invalid BlessingPattern", forPeers)
}
s.mu.Lock()
@@ -148,28 +147,6 @@
return encodeAndStore(s.state, s.dir, blessingStoreDataFile, blessingStoreSigFile, s.signer)
}
-// TODO(ataly): Use ValidateBlessingPattern from "veyron2/security" when available.
-func validateBlessingPattern(pattern security.BlessingPattern) error {
- errInvalidPattern := func(pattern security.BlessingPattern) error {
- return fmt.Errorf("invalid blessing pattern:%q", pattern)
- }
-
- patternParts := strings.Split(string(pattern), security.ChainSeparator)
- for i, p := range patternParts {
- if p == "" {
- return errInvalidPattern(pattern)
- }
- glob := string(security.AllPrincipals)
- if p != glob && strings.Contains(p, glob) {
- return errInvalidPattern(pattern)
- }
- if p == glob && (i < len(patternParts)-1) {
- return errInvalidPattern(pattern)
- }
- }
- return nil
-}
-
// NewInMemoryBlessingStore returns an in-memory security.BlessingStore for a
// principal with the provided PublicKey.
//
diff --git a/runtimes/google/rt/blessingstore_test.go b/runtimes/google/rt/blessingstore_test.go
index 05395f1..ac3e949 100644
--- a/runtimes/google/rt/blessingstore_test.go
+++ b/runtimes/google/rt/blessingstore_test.go
@@ -91,7 +91,7 @@
{
blessings: []security.PublicID{cAlicePub, cVeyronAlice, sAlice},
patterns: []security.BlessingPattern{"", "foo...", "...foo", "/bar", "foo/", "foo/.../bar"},
- wantErr: "invalid blessing pattern",
+ wantErr: "invalid BlessingPattern",
},
}
for _, d := range testDataForAdd {
diff --git a/runtimes/google/security/publicid_store.go b/runtimes/google/security/publicid_store.go
index 7599143..ed53f727 100644
--- a/runtimes/google/security/publicid_store.go
+++ b/runtimes/google/security/publicid_store.go
@@ -11,7 +11,6 @@
"veyron/security/serialization"
"veyron2/security"
- "veyron2/security/wire"
"veyron2/vom"
)
@@ -154,8 +153,8 @@
}
func (s *publicIDStore) SetDefaultBlessingPattern(pattern security.BlessingPattern) error {
- if err := wire.ValidateBlessingPattern(pattern); err != nil {
- return err
+ if !pattern.IsValid() {
+ return fmt.Errorf("%q is an invalid BlessingPattern", pattern)
}
s.mu.Lock()
defer s.mu.Unlock()