oficina / alta Public

Clone
git clone https://amadan.net/oficina/alta

Plain git — no account needed to clone.

Download

Download this file

1package carlosop
2
3import (
4 "crypto/sha256"
5 "encoding/hex"
6 "regexp"
7)
8
9// EnvDigest is carlos/platform 522's `vd1:` digest (spec §4.3) of a plain
10// var holding value: SHA-256 over the four stored fields of a var, kind
11// "env", the value, and an empty envelope and sealed-to fingerprint,
12// NUL-separated under the scheme's domain string.
13//
14// It is applied only to the two agent keys' values, which the runner itself
15// sends. Never to a secret: a secret's digest is over its envelope, and the
16// runner never holds a secret's plaintext. Like the value, the result is not
17// to be printed or logged.
18func EnvDigest(value string) string {
19 h := sha256.New()
20 for i, f := range []string{"carlos.config.var.v1", "env", value, "", ""} {
21 if i > 0 {
22 h.Write([]byte{0})
23 }
24 h.Write([]byte(f))
25 }
26 return "vd1:" + hex.EncodeToString(h.Sum(nil))
27}
28
29var (
30 versionShape = regexp.MustCompile(`^cv1:[0-9a-f]{64}$`)
31 digestShape = regexp.MustCompile(`^vd1:[0-9a-f]{64}$`)
32)
33
34// validVersion admits a 522 layer version: "none" for an absent layer, or
35// "cv1:" and 64 lowercase hex.
36func validVersion(v string) bool { return v == "none" || versionShape.MatchString(v) }
37
38// validDigest admits a 522 var digest: "vd1:" and 64 lowercase hex.
39func validDigest(d string) bool { return digestShape.MatchString(d) }
40