Validate byte-preserving record fields as base64 strings
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user