Files
filou/payload/metadata.go
T
2014-10-17 15:46:21 -04:00

38 lines
651 B
Go

package payload
import (
"encoding/hex"
"encoding/json"
)
type Metadata struct {
IV []byte
Key []byte
}
type jsonMetada struct {
IV string
Key string
}
func (this *Metadata) MarshalJSON() ([]byte, error) {
ret := &jsonMetada{
IV: hex.EncodeToString(this.IV),
Key: hex.EncodeToString(this.Key),
}
return json.Marshal(ret)
}
func (this *Metadata) UnmarshalJSON(data []byte) (err error) {
ret := &jsonMetada{}
if err = json.Unmarshal(data, ret); err != nil {
return err
}
if this.IV, err = hex.DecodeString(ret.IV); err != nil {
return
} else if this.Key, err = hex.DecodeString(ret.Key); err != nil {
return
}
return
}