...
1 package jwe
2
3 import (
4 "context"
5
6 "github.com/lestrrat-go/option"
7 )
8
9 type Option = option.Interface
10 type identMessage struct{}
11 type identPostParser struct{}
12 type identPrettyFormat struct{}
13 type identProtectedHeader struct{}
14
15 type DecryptOption interface {
16 Option
17 decryptOption()
18 }
19
20 type decryptOption struct {
21 Option
22 }
23
24 func (*decryptOption) decryptOption() {}
25
26 type SerializerOption interface {
27 Option
28 serializerOption()
29 }
30
31 type serializerOption struct {
32 Option
33 }
34
35 func (*serializerOption) serializerOption() {}
36
37 type EncryptOption interface {
38 Option
39 encryptOption()
40 }
41
42 type encryptOption struct {
43 Option
44 }
45
46 func (*encryptOption) encryptOption() {}
47
48
49
50 func WithPrettyFormat(b bool) SerializerOption {
51 return &serializerOption{option.New(identPrettyFormat{}, b)}
52 }
53
54
55
56 func WithProtectedHeaders(h Headers) EncryptOption {
57 cloned, _ := h.Clone(context.Background())
58 return &encryptOption{option.New(identProtectedHeader{}, cloned)}
59 }
60
61
62
63
64
65
66
67
68
69 func WithMessage(m *Message) DecryptOption {
70 return &decryptOption{option.New(identMessage{}, m)}
71 }
72
73
74
75
76
77
78
79
80
81
82
83
84
85 func WithPostParser(p PostParser) DecryptOption {
86 return &decryptOption{option.New(identPostParser{}, p)}
87 }
88
View as plain text