@@ -42,14 +42,14 @@ type policyComponent interface {
4242 Endpoints () map [string ]note.Verifier
4343}
4444
45- // NewWitnessGroupFromPolicy creates a graph of witness objects that represents the
45+ // ParsePolicy creates a graph of witness objects that represents the
4646// policy provided, and which can be passed directly to the WithWitnesses
4747// appender lifecycle option.
4848//
4949// The policy structure is as described by [Sigsum's policy format](https://git.glasklar.is/sigsum/core/sigsum-go/-/blob/main/doc/policy.md)
5050// but with the difference that the configured witness keys MUST be signature type `0x04` `vkey`s as specified
5151// by C2SP [signed-note](https://github.com/C2SP/C2SP/blob/main/signed-note.md#verifier-keys).
52- func NewWitnessGroupFromPolicy (p []byte ) (WitnessGroup , error ) {
52+ func ParsePolicy (p []byte ) (Group , error ) {
5353 scanner := bufio .NewScanner (bytes .NewBuffer (p ))
5454 components := make (map [string ]policyComponent )
5555
@@ -72,35 +72,35 @@ func NewWitnessGroupFromPolicy(p []byte) (WitnessGroup, error) {
7272 // Given this function is parsing to create the graph structure which will be used by a Tessera log to witness
7373 // new checkpoints we'll ignore that special case here.
7474 if len (fields ) != 4 {
75- return WitnessGroup {}, fmt .Errorf ("invalid witness definition: %q" , line )
75+ return Group {}, fmt .Errorf ("invalid witness definition: %q" , line )
7676 }
7777 name , vkey , witnessURLStr := fields [1 ], fields [2 ], fields [3 ]
7878 if isBadName (name ) {
79- return WitnessGroup {}, fmt .Errorf ("invalid witness name %q" , name )
79+ return Group {}, fmt .Errorf ("invalid witness name %q" , name )
8080 }
8181 if _ , ok := components [name ]; ok {
82- return WitnessGroup {}, fmt .Errorf ("duplicate component name: %q" , name )
82+ return Group {}, fmt .Errorf ("duplicate component name: %q" , name )
8383 }
8484 witnessURL , err := url .Parse (witnessURLStr )
8585 if err != nil {
86- return WitnessGroup {}, fmt .Errorf ("invalid witness URL %q: %w" , witnessURLStr , err )
86+ return Group {}, fmt .Errorf ("invalid witness URL %q: %w" , witnessURLStr , err )
8787 }
88- w , err := NewWitness (vkey , witnessURL )
88+ w , err := New (vkey , witnessURL )
8989 if err != nil {
90- return WitnessGroup {}, fmt .Errorf ("invalid witness config %q: %w" , line , err )
90+ return Group {}, fmt .Errorf ("invalid witness config %q: %w" , line , err )
9191 }
9292 components [name ] = w
9393 case "group" :
9494 if len (fields ) < 3 {
95- return WitnessGroup {}, fmt .Errorf ("invalid group definition: %q" , line )
95+ return Group {}, fmt .Errorf ("invalid group definition: %q" , line )
9696 }
9797
9898 name , N , childrenNames := fields [1 ], fields [2 ], fields [3 :]
9999 if isBadName (name ) {
100- return WitnessGroup {}, fmt .Errorf ("invalid group name %q" , name )
100+ return Group {}, fmt .Errorf ("invalid group name %q" , name )
101101 }
102102 if _ , ok := components [name ]; ok {
103- return WitnessGroup {}, fmt .Errorf ("duplicate component name: %q" , name )
103+ return Group {}, fmt .Errorf ("duplicate component name: %q" , name )
104104 }
105105 var n int
106106 switch N {
@@ -111,57 +111,57 @@ func NewWitnessGroupFromPolicy(p []byte) (WitnessGroup, error) {
111111 default :
112112 i , err := strconv .ParseUint (N , 10 , 8 )
113113 if err != nil {
114- return WitnessGroup {}, fmt .Errorf ("invalid threshold %q for group %q: %w" , N , name , err )
114+ return Group {}, fmt .Errorf ("invalid threshold %q for group %q: %w" , N , name , err )
115115 }
116116 n = int (i )
117117 }
118118 if c := len (childrenNames ); n > c {
119- return WitnessGroup {}, fmt .Errorf ("group with %d children cannot have threshold %d" , c , n )
119+ return Group {}, fmt .Errorf ("group with %d children cannot have threshold %d" , c , n )
120120 }
121121
122122 children := make ([]policyComponent , len (childrenNames ))
123123 for i , cName := range childrenNames {
124124 if isBadName (cName ) {
125- return WitnessGroup {}, fmt .Errorf ("invalid component name %q" , cName )
125+ return Group {}, fmt .Errorf ("invalid component name %q" , cName )
126126 }
127127 child , ok := components [cName ]
128128 if ! ok {
129- return WitnessGroup {}, fmt .Errorf ("unknown component %q in group definition" , cName )
129+ return Group {}, fmt .Errorf ("unknown component %q in group definition" , cName )
130130 }
131131 children [i ] = child
132132 }
133- wg := NewWitnessGroup (n , children ... )
133+ wg := NewGroup (n , children ... )
134134 components [name ] = wg
135135 case "quorum" :
136136 if len (fields ) != 2 {
137- return WitnessGroup {}, fmt .Errorf ("invalid quorum definition: %q" , line )
137+ return Group {}, fmt .Errorf ("invalid quorum definition: %q" , line )
138138 }
139139 quorumName = fields [1 ]
140140 default :
141- return WitnessGroup {}, fmt .Errorf ("unknown keyword: %q" , fields [0 ])
141+ return Group {}, fmt .Errorf ("unknown keyword: %q" , fields [0 ])
142142 }
143143 }
144144 if err := scanner .Err (); err != nil {
145- return WitnessGroup {}, err
145+ return Group {}, err
146146 }
147147
148148 switch quorumName {
149149 case "" :
150- return WitnessGroup {}, fmt .Errorf ("policy file must define a quorum" )
150+ return Group {}, fmt .Errorf ("policy file must define a quorum" )
151151 case "none" :
152- return NewWitnessGroup (0 ), nil
152+ return NewGroup (0 ), nil
153153 default :
154154 if isBadName (quorumName ) {
155- return WitnessGroup {}, fmt .Errorf ("invalid quorum name %q" , quorumName )
155+ return Group {}, fmt .Errorf ("invalid quorum name %q" , quorumName )
156156 }
157157 policy , ok := components [quorumName ]
158158 if ! ok {
159- return WitnessGroup {}, fmt .Errorf ("quorum component %q not found" , quorumName )
159+ return Group {}, fmt .Errorf ("quorum component %q not found" , quorumName )
160160 }
161- wg , ok := policy .(WitnessGroup )
161+ wg , ok := policy .(Group )
162162 if ! ok {
163163 // A single witness can be a policy. Wrap it in a group.
164- return NewWitnessGroup (1 , policy ), nil
164+ return NewGroup (1 , policy ), nil
165165 }
166166 return wg , nil
167167 }
@@ -182,9 +182,9 @@ func isBadName(n string) bool {
182182 return isKeyword
183183}
184184
185- // NewWitness returns a Witness given a verifier key and the root URL for where this
185+ // New returns a Witness given a verifier key and the root URL for where this
186186// witness can be reached.
187- func NewWitness (vkey string , witnessRoot * url.URL ) (Witness , error ) {
187+ func New (vkey string , witnessRoot * url.URL ) (Witness , error ) {
188188 v , err := f_note .NewVerifierForCosignatureV1 (vkey )
189189 if err != nil {
190190 return Witness {}, err
@@ -226,29 +226,29 @@ func (w Witness) Endpoints() map[string]note.Verifier {
226226 return map [string ]note.Verifier {w .URL : w .Key }
227227}
228228
229- // NewWitnessGroup creates a grouping of Witness or WitnessGroup with a configurable threshold
229+ // NewGroup creates a grouping of Witness or WitnessGroup with a configurable threshold
230230// of these sub-components that need to be satisfied in order for this group to be satisfied.
231231//
232232// The threshold should only be set to less than the number of sub-components if these are
233233// considered fungible.
234- func NewWitnessGroup (n int , children ... policyComponent ) WitnessGroup {
234+ func NewGroup (n int , children ... policyComponent ) Group {
235235 if n < 0 || n > len (children ) {
236236 panic (fmt .Errorf ("threshold of %d outside bounds for children %s" , n , children ))
237237 }
238- return WitnessGroup {
238+ return Group {
239239 Components : children ,
240240 N : n ,
241241 }
242242}
243243
244- // WitnessGroup defines a group of witnesses, and a threshold of
244+ // Group defines a group of witnesses, and a threshold of
245245// signatures that must be met for this group to be satisfied.
246246// Witnesses within a group should be fungible, e.g. all of the Armored
247247// Witness devices form a logical group, and N should be picked to
248248// represent a threshold of the quorum. For some users this will be a
249249// simple majority, but other strategies are available.
250250// N must be <= len(WitnessKeys).
251- type WitnessGroup struct {
251+ type Group struct {
252252 Components []policyComponent
253253 N int
254254}
@@ -263,7 +263,7 @@ type WitnessGroup struct {
263263// checkpoint, which is O(N). If this is called every time a witness returns a
264264// checkpoint then this algorithm is O(N^2). To support large N, this may require
265265// some rewriting in order to maintain performance.
266- func (wg WitnessGroup ) Satisfied (cp []byte ) bool {
266+ func (wg Group ) Satisfied (cp []byte ) bool {
267267 if wg .N <= 0 {
268268 return true
269269 }
@@ -283,7 +283,7 @@ func (wg WitnessGroup) Satisfied(cp []byte) bool {
283283// response. The returned result is a map from the URL that should be used to update
284284// the witness with a new checkpoint, to the value which is the verifier to check
285285// the response is well formed.
286- func (wg WitnessGroup ) Endpoints () map [string ]note.Verifier {
286+ func (wg Group ) Endpoints () map [string ]note.Verifier {
287287 endpoints := make (map [string ]note.Verifier )
288288 for _ , c := range wg .Components {
289289 maps .Copy (endpoints , c .Endpoints ())
0 commit comments