github.com/opentofu/opentofu@v1.7.1/internal/encryption/keyprovider/output.go (about) 1 package keyprovider 2 3 import "github.com/zclconf/go-cty/cty" 4 5 // Output is the standardized structure a key provider must return when providing a key. 6 // It contains two keys because some key providers may prefer include random data (e.g. salt) 7 // in the generated keys and this salt will be different for decryption and encryption. 8 type Output struct { 9 EncryptionKey []byte `hcl:"encryption_key" cty:"encryption_key" json:"encryption_key" yaml:"encryption_key"` 10 DecryptionKey []byte `hcl:"decryption_key" cty:"decryption_key" json:"decryption_key" yaml:"decryption_key"` 11 } 12 13 // Cty turns the Output struct into a CTY value. 14 func (o *Output) Cty() cty.Value { 15 return cty.ObjectVal(map[string]cty.Value{ 16 "encryption_key": o.byteToCty(o.EncryptionKey), 17 "decryption_key": o.byteToCty(o.DecryptionKey), 18 }) 19 } 20 21 func (o *Output) byteToCty(data []byte) cty.Value { 22 if len(data) == 0 { 23 return cty.NullVal(cty.List(cty.Number)) 24 } 25 ctyData := make([]cty.Value, len(data)) 26 for i, d := range data { 27 ctyData[i] = cty.NumberIntVal(int64(d)) 28 } 29 return cty.ListVal(ctyData) 30 }