-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata.go
More file actions
45 lines (39 loc) · 1.18 KB
/
Copy pathmetadata.go
File metadata and controls
45 lines (39 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package encx
import (
"encoding/json"
"time"
)
// EncryptionMetadata contains metadata about how a struct was encrypted
type EncryptionMetadata struct {
PepperVersion int `json:"pepper_version"`
KEKAlias string `json:"kek_alias"`
EncryptionTime int64 `json:"encryption_time"`
GeneratorVersion string `json:"generator_version"`
}
// ToJSON serializes the metadata to JSON bytes
func (em *EncryptionMetadata) ToJSON() ([]byte, error) {
return json.Marshal(em)
}
// FromJSON deserializes metadata from JSON bytes
func (em *EncryptionMetadata) FromJSON(data []byte) error {
return json.Unmarshal(data, em)
}
// NewEncryptionMetadata creates a new EncryptionMetadata instance
func NewEncryptionMetadata(kekAlias, generatorVersion string, pepperVersion int) *EncryptionMetadata {
return &EncryptionMetadata{
PepperVersion: pepperVersion,
KEKAlias: kekAlias,
EncryptionTime: time.Now().Unix(),
GeneratorVersion: generatorVersion,
}
}
// Validate checks if the metadata is valid
func (em *EncryptionMetadata) Validate() error {
if em.KEKAlias == "" {
return ErrMissingKEKAlias
}
if em.GeneratorVersion == "" {
return ErrMissingGeneratorVersion
}
return nil
}