2021-09-27 08:36:28 +00:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Encryption is the encryption parameter.
|
|
|
|
type Encryption int
|
|
|
|
|
|
|
|
// supported encryption policies.
|
|
|
|
const (
|
|
|
|
EncryptionNo Encryption = iota
|
|
|
|
EncryptionOptional
|
|
|
|
EncryptionStrict
|
|
|
|
)
|
|
|
|
|
|
|
|
// MarshalJSON marshals a Encryption into JSON.
|
|
|
|
func (d Encryption) MarshalJSON() ([]byte, error) {
|
|
|
|
var out string
|
|
|
|
|
|
|
|
switch d {
|
|
|
|
case EncryptionNo:
|
|
|
|
out = "no"
|
|
|
|
|
|
|
|
case EncryptionOptional:
|
|
|
|
out = "optional"
|
|
|
|
|
|
|
|
default:
|
|
|
|
out = "strict"
|
|
|
|
}
|
|
|
|
|
|
|
|
return json.Marshal(out)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON unmarshals a Encryption from JSON.
|
|
|
|
func (d *Encryption) UnmarshalJSON(b []byte) error {
|
|
|
|
var in string
|
|
|
|
if err := json.Unmarshal(b, &in); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch in {
|
|
|
|
case "no", "false":
|
|
|
|
*d = EncryptionNo
|
|
|
|
|
|
|
|
case "optional":
|
|
|
|
*d = EncryptionOptional
|
|
|
|
|
|
|
|
case "strict", "yes", "true":
|
|
|
|
*d = EncryptionStrict
|
|
|
|
|
|
|
|
default:
|
2021-09-27 08:43:48 +00:00
|
|
|
return fmt.Errorf("invalid encryption value: '%s'", in)
|
2021-09-27 08:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|