mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-13 17:25:32 -04:00
Fix/config/measurements in yaml (#135)
Custom type & marshal implementation for measurements to write base64 instead of single bytes
This commit is contained in:
parent
19394e5563
commit
14103e4f89
4 changed files with 177 additions and 16 deletions
33
internal/config/measurements.go
Normal file
33
internal/config/measurements.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package config
|
||||
|
||||
import "encoding/base64"
|
||||
|
||||
type Measurements map[uint32][]byte
|
||||
|
||||
func (m Measurements) MarshalYAML() (interface{}, error) {
|
||||
base64Map := make(map[uint32]string)
|
||||
|
||||
for key, value := range m {
|
||||
base64Map[key] = base64.StdEncoding.EncodeToString(value[:])
|
||||
}
|
||||
|
||||
return base64Map, nil
|
||||
}
|
||||
|
||||
func (m *Measurements) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
base64Map := make(map[uint32]string)
|
||||
err := unmarshal(base64Map)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*m = make(Measurements)
|
||||
for key, value := range base64Map {
|
||||
measurement, err := base64.StdEncoding.DecodeString(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
(*m)[key] = measurement
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue