gunk-dev/the-valley

signerprojects.go

sourcecc441a0b6b45main's published tip history
1.4 KiB
1package main
2
3import (
4 "fmt"
5 "os"
6
7 "the-valley/note"
8)
9
10// readSignerProjects reads the signer projects file at path
11// (note/signerprojects.go), and returns what it says and the bytes it
12// read. An empty path is no file, and restricts nobody. A file that cannot
13// be read, or does not read as a signer projects file, is an error, so a
14// controller given a broken file judges nothing rather than judging
15// without it.
16//
17// The file may not name signer, the name the integrator signs under. A
18// signer the file names is restricted to projects: a worker, or another
19// controller whose countersignatures must count nowhere. The integrator
20// signs transfer statements, which clients believe in every project it
21// serves, so a signer restricted under its name would be both.
22func readSignerProjects(path, signer string) (note.SignerProjects, []byte, error) {
23 if path == "" {
24 return nil, nil, nil
25 }
26 data, err := os.ReadFile(path)
27 if err != nil {
28 return nil, nil, fmt.Errorf("reading the signer projects file: %w", err)
29 }
30 s, err := note.ParseSignerProjects(data)
31 if err != nil {
32 return nil, nil, fmt.Errorf("the signer projects file %s does not read: %w", path, err)
33 }
34 if s.Restricts(signer) {
35 return nil, nil, fmt.Errorf("the signer projects file %s names %s, the name the integrator signs under; a worker or attester restricted to projects signs under a name of its own", path, signer)
36 }
37 return s, data, nil
38}