Validate byte-preserving record fields as base64 strings

This commit is contained in:
2026-11-03 00:18:47 +00:00
parent 2a7bed87db
commit e0019abe31
5 changed files with 83 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ package publish
import (
"context"
"crypto/rand"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
@@ -52,8 +53,15 @@ func LoadEvidence(path string) (Evidence, error) {
}
for _, field := range evidenceFields(&evidence) {
if raw, ok := fields[field.name]; ok {
var bytes []byte
if err := json.Unmarshal(raw, &bytes); err != nil {
var encoded *string
if err := json.Unmarshal(raw, &encoded); err != nil {
return Evidence{}, &RecoveryError{Kind: "record_format", RecordPath: path, cause: fmt.Errorf("decode record field %s bytes %q: %w", field.name, path, err)}
}
if encoded == nil {
return Evidence{}, &RecoveryError{Kind: "record_format", RecordPath: path, cause: fmt.Errorf("record field %s bytes %q must be a base64 string", field.name, path)}
}
bytes, err := base64.StdEncoding.DecodeString(*encoded)
if err != nil {
return Evidence{}, &RecoveryError{Kind: "record_format", RecordPath: path, cause: fmt.Errorf("decode record field %s bytes %q: %w", field.name, path, err)}
}
*field.value = string(bytes)