MCPcopy
hub / github.com/ory/hydra / Decode

Function Decode

flow/encoding.go:76–94  ·  view source on GitHub ↗

Decode decodes the given string to a value.

(ctx context.Context, cipher aead.Cipher, encoded string, opts ...CodecOption)

Source from the content-addressed store, hash-verified

74
75// Decode decodes the given string to a value.
76func Decode[T any](ctx context.Context, cipher aead.Cipher, encoded string, opts ...CodecOption) (*T, error) {
77 plaintext, err := cipher.Decrypt(ctx, encoded, additionalDataFromOpts(opts...))
78 if err != nil {
79 return nil, err
80 }
81
82 rawBytes, err := gzip.NewReader(bytes.NewReader(plaintext))
83 if err != nil {
84 return nil, err
85 }
86 defer func() { _ = rawBytes.Close() }()
87
88 var val T
89 if err = json.NewDecoder(rawBytes).Decode(&val); err != nil {
90 return nil, err
91 }
92
93 return &val, nil
94}
95
96// Encode encodes the given value to a string.
97func Encode(ctx context.Context, cipher aead.Cipher, val any, opts ...CodecOption) (s string, err error) {

Callers 1

TestEncodingFunction · 0.92

Calls 4

additionalDataFromOptsFunction · 0.85
DecryptMethod · 0.65
CloseMethod · 0.65
DecodeMethod · 0.65

Tested by 1

TestEncodingFunction · 0.74