diff options
author | Rasmus Dahlberg <rasmus@rgdd.se> | 2023-03-17 10:09:38 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus@rgdd.se> | 2023-03-17 10:09:38 +0100 |
commit | 7e4d74b9150b58dc2eea0a0fd1bfb2e4b65465fb (patch) | |
tree | c7b92927b5f2d2738b42ccb31036129dfc4d184c /internal/utils | |
parent | e49b1687638126b3bd3bbb1935e343024adba34d (diff) |
Add utils
Diffstat (limited to 'internal/utils')
-rw-r--r-- | internal/utils/utils.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/internal/utils/utils.go b/internal/utils/utils.go new file mode 100644 index 0000000..7f5b1bc --- /dev/null +++ b/internal/utils/utils.go @@ -0,0 +1,56 @@ +package utils + +import ( + "crypto/sha256" + "fmt" + "os" + + "git.cs.kau.se/rasmoste/ct-sans/internal/merkle" + "gitlab.torproject.org/rgdd/ct/pkg/metadata" +) + +// Logs select logs that count towards CT-compliance checks. Logs that don't +// have a description are skipped after printing a warning. +func Logs(md metadata.Metadata) (logs []metadata.Log) { + for _, operators := range md.Operators { + for _, log := range operators.Logs { + if log.Description == nil { + fmt.Fprintf(os.Stderr, "WARNING: skipping log without description") + continue + } + if log.State == nil { + continue // skip logs with unknown states + } + if log.State.Name == metadata.LogStatePending { + continue // pending logs do not count towards CT-compliance + } + if log.State.Name == metadata.LogStateRetired { + continue // retired logs are not necessarily reachable + } + if log.State.Name == metadata.LogStateRejected { + continue // rejected logs do not count towards CT-compliance + } + + logs = append(logs, log) + } + } + return +} + +// Proof formats hashes so that they can be passed to the merkle package +func Proof(hashes [][]byte) (p [][sha256.Size]byte) { + for _, hash := range hashes { + var h [sha256.Size]byte + copy(h[:], hash) + p = append(p, h) + } + return +} + +// LeafHashes formats a list of data as leaf hashes +func LeafHashes(data [][]byte) (lh [][sha256.Size]byte) { + for _, d := range data { + lh = append(lh, merkle.HashLeafNode(d)) + } + return +} |