mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-27 00:19:36 -05:00
14103e4f89
Custom type & marshal implementation for measurements to write base64 instead of single bytes
34 lines
682 B
Go
34 lines
682 B
Go
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
|
|
}
|