1package gnopm23import"strings"45// Size caps. Every string the chain stores is bounded: an unbounded field is an6// unbounded storage deposit, and on gno.land the deposit is paid per byte by7// whoever writes it.8
Functions
not supported for pure packages by the node (vm/qfuncs)
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
const (
9 MaxPkgPathLen = 256
10 MaxRepoLen = 512
11 MaxDirLen = 256
12 MaxRefLen = 255// git's own limit for a single ref name
13
14// MaxClaimants bounds how many addresses may claim one package path.
15// Unbounded, it is a spam surface: one path with ten thousand claims is a
16// Render that never returns and a listing nobody can read.
17 MaxClaimants = 16
18)
19
20// ValidCommit reports whether s is a git object id: 40 (SHA-1) or 64 (SHA-256)
21// lowercase hex characters. Case is fixed so the same object always produces
22// the same stored bytes, and so a verifier comparing two claims compares two
23// comparable strings.
24func ValidCommit(s string) bool {
25if len(s) != 40 && len(s) != 64 {
26returnfalse
27 }
28for i := 0; i < len(s); i++ {
29 c := s[i]
30if (c < '0' || c > '9') && (c < 'a' || c > 'f') {
31returnfalse
32 }
33 }
34returntrue
35}
36
37// ValidRepo reports whether s is a repository URL this registry accepts.
38//
39// Deliberately narrow: "https://" only, a host, and a path. Not a taste
40// judgement about git transports, a safety one. Whatever is stored here is
41// eventually rendered as a link by this realm, by gnoweb and by every explorer
42// that reads the registry, and the set of schemes that are safe to hand a
43// browser is exactly one. "javascript:", "data:" and "file:" are the attack;
44// "git://" and "ssh://" are merely unreachable from a web page, and a claimant
45// who needs one can point at the https mirror every forge already serves.
46func ValidRepo(s string) bool {
47if s == "" || len(s) > MaxRepoLen {
48returnfalse
49 }
50const scheme = "https://"
51if !strings.HasPrefix(s, scheme) {
52returnfalse
53 }
54 rest := s[len(scheme):]
55if rest == "" || strings.HasPrefix(rest, "/") {
56returnfalse
57 }
58// A host must be present and must not be a userinfo trick
59// ("https://github.com@evil.example/x" fetches from evil.example while