package delivery import ( "fmt" "strings" ) // SourcePrefix2 opens every source fingerprint of the new form. The fingerprint is computed by the indexer alone, in // its own package (novox/hq ADR 0593 ยง2); this is its form, read by every part. const SourcePrefix2 = "src2:" // Toolchain2 is what an artifact's toolchain enters the new fingerprint as (novox/hq ADR 0405 clause 7): the // artifact's language, the installed toolchain's version and the build module's recipe version, in place of the // toolchain image's digest. A toolchain update so changes the fingerprints of that language's modules only. type Toolchain2 struct { Language string Version string Recipe string } // FingerprintKeyPart is a new-form fingerprint as a key part: its 64 hex digits without the prefix, since a bus key // may not hold ':'. It refuses a value that is not `src2:` and 64 lowercase hex digits, a src1 fingerprint included, // naming it. func FingerprintKeyPart(fp string) (string, error) { part, ok := strings.CutPrefix(fp, SourcePrefix2) if !ok || !isHex64(part) { return "", fmt.Errorf("delivery: %q is not a fingerprint of the new form, %s and 64 lowercase hex digits", fp, SourcePrefix2) } return part, nil } // ParseFingerprintKeyPart is the inverse of FingerprintKeyPart. It refuses a part that is not 64 lowercase hex // digits, a src1 fingerprint or a prefixed value included, naming it. func ParseFingerprintKeyPart(part string) (string, error) { if !isHex64(part) { return "", fmt.Errorf("delivery: %q is not the key part of a fingerprint, 64 lowercase hex digits", part) } return SourcePrefix2 + part, nil } func isHex64(s string) bool { return len(s) == 64 && strings.Trim(s, "0123456789abcdef") == "" }