42 lines
1.7 KiB
Go
42 lines
1.7 KiB
Go
// Package meshcatalogclient holds the logic the holders and callers of the seat mesh-catalog share over its contract (novox/hq
|
|
// ADR 0625 §4, ADR 0634 §2): the form of a module's source fingerprint, `src2:` and 64 lowercase hex digits (ADR 0593 §2),
|
|
// over the `fp2` field of the seat's `modules` value. The indexer computes a fingerprint alone, in its own package; every part
|
|
// that keys a state by it, the node-engine among them, reads this form here.
|
|
package meshcatalogclient
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
// SourcePrefix2 opens every source fingerprint of the form.
|
|
const SourcePrefix2 = "src2:"
|
|
|
|
// Toolchain2 is what an artifact's toolchain enters the fingerprint as (novox/hq ADR 0405 clause 7): the artifact's
|
|
// language, the installed toolchain's version and the build module's recipe version.
|
|
type Toolchain2 struct {
|
|
Language string
|
|
Version string
|
|
Recipe string
|
|
}
|
|
|
|
// KeyPart is a 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 KeyPart(fp string) (string, error) {
|
|
part, ok := strings.CutPrefix(fp, SourcePrefix2)
|
|
if !ok || !keys.IsHex64(part) {
|
|
return "", fmt.Errorf("fingerprint: %q is not a fingerprint of the form, %s and 64 lowercase hex digits", fp, SourcePrefix2)
|
|
}
|
|
return part, nil
|
|
}
|
|
|
|
// ParseKeyPart is the inverse of KeyPart. It refuses a part that is not 64 lowercase hex digits, naming it.
|
|
func ParseKeyPart(part string) (string, error) {
|
|
if !keys.IsHex64(part) {
|
|
return "", fmt.Errorf("fingerprint: %q is not the key part of a fingerprint, 64 lowercase hex digits", part)
|
|
}
|
|
return SourcePrefix2 + part, nil
|
|
}
|