| 56 | ) |
| 57 | |
| 58 | func additionalDataFromOpts(opts ...CodecOption) []byte { |
| 59 | if len(opts) == 0 { |
| 60 | return nil |
| 61 | } |
| 62 | ad := &data{} |
| 63 | for _, o := range opts { |
| 64 | o(ad) |
| 65 | } |
| 66 | b, err := json.Marshal(ad) |
| 67 | if err != nil { |
| 68 | // Panic is OK here because the struct and the parameters are all known. |
| 69 | panic("failed to marshal additional data: " + errors.WithStack(err).Error()) |
| 70 | } |
| 71 | |
| 72 | return b |
| 73 | } |
| 74 | |
| 75 | // Decode decodes the given string to a value. |
| 76 | func Decode[T any](ctx context.Context, cipher aead.Cipher, encoded string, opts ...CodecOption) (*T, error) { |