oficina / home Public

roster: export ValidSubject, the person-ref shape Check answers about

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 15833f7bfedd9e20445a57ea9229e527c6715d64 parent 17db191
2 files changed, +13 −1
  • roster/lease_test.go +8 −0
  • roster/protocol.go +5 −1
diff --git a/roster/lease_test.go b/roster/lease_test.go
index 4018a94..57c9984 100644
--- a/roster/lease_test.go
+++ b/roster/lease_test.go
@@ -326,3 +326,11 @@ func TestLeaseEndedByFenceStaysEndedAfterPublication(t *testing.T) {
t.Fatal("no fresh decision after the fence")
}
}
+
+func TestValidSubject(t *testing.T) {
+ for s, want := range map[string]bool{person(1): true, "pr_" + "aaaaaaaaaaaaaaaaaaaaaaaaa2": true, "pr_short": false, "pr_" + "AAAAAAAAAAAAAAAAAAAAAAAAAA": false, "xx_aaaaaaaaaaaaaaaaaaaaaaaaaa": false, "pr_aaaaaaaaaaaaaaaaaaaaaaaaa1": false, "": false} {
+ if ValidSubject(s) != want {
+ t.Errorf("ValidSubject(%q) = %v", s, !want)
+ }
+ }
+}
diff --git a/roster/protocol.go b/roster/protocol.go
index bcdb434..dcec226 100644
--- a/roster/protocol.go
+++ b/roster/protocol.go
@@ -210,7 +210,11 @@ func hash(b []byte) string { s := sha256.Sum256(b); return base64.RawURLEncoding
// CursorHash always returns SHA256 of the exact cursor bytes. For page zero it
// returns SHA256(empty), encoded as 43 canonical base64url characters.
func CursorHash(cursor string) string { return hash([]byte(cursor)) }
-func ValidChallenge(s string) bool { _, ok := canonical(s, 32); return ok }
+
+// ValidSubject reports whether s has a roster person ref's shape ("pr_" and
+// 26 lower-case base32 letters): the only subjects Check can answer about.
+func ValidSubject(s string) bool { return validMember(MemberEntry{s, "member"}) }
+func ValidChallenge(s string) bool { _, ok := canonical(s, 32); return ok }
type MemberEntry struct {
Subject string `json:"person_ref"`