@@ -159,28 +159,37 @@ func (m TLSVerificationMode) MarshalText() ([]byte, error) {
159159 return nil , fmt .Errorf ("could not marshal '%+v' to text" , m )
160160}
161161
162- // Unpack unpacks the string into constants .
162+ // Unpack unpacks the input into a TLSVerificationMode .
163163func (m * TLSVerificationMode ) Unpack (in interface {}) error {
164164 if in == nil {
165165 * m = VerifyFull
166166 return nil
167167 }
168168
169- s , ok := in .(string )
170- if ! ok {
171- return fmt .Errorf ("verification mode must be an identifier" )
172- }
173- if s == "" {
174- * m = VerifyFull
175- return nil
169+ switch o := in .(type ) {
170+ case string :
171+ if o == "" {
172+ * m = VerifyFull
173+ return nil
174+ }
175+
176+ mode , found := tlsVerificationModes [o ]
177+ if ! found {
178+ return fmt .Errorf ("unknown verification mode '%v'" , o )
179+ }
180+ * m = mode
181+ case uint64 :
182+ * m = TLSVerificationMode (o )
183+ default :
184+ return fmt .Errorf ("verification mode is an unknown type: %T" , o )
176185 }
186+ return nil
187+ }
177188
178- mode , found := tlsVerificationModes [ s ]
179- if ! found {
180- return fmt .Errorf ("unknown verification mode '%v' " , s )
189+ func ( m * TLSVerificationMode ) Validate () error {
190+ if * m > VerifyStrict {
191+ return fmt .Errorf ("unsupported verification mode: %v " , m )
181192 }
182-
183- * m = mode
184193 return nil
185194}
186195
@@ -214,13 +223,20 @@ func (m *TLSClientAuth) Unpack(s string) error {
214223
215224type CipherSuite uint16
216225
217- func (cs * CipherSuite ) Unpack (s string ) error {
218- suite , found := tlsCipherSuites [s ]
219- if ! found {
220- return fmt .Errorf ("invalid tls cipher suite '%v'" , s )
226+ func (cs * CipherSuite ) Unpack (i interface {}) error {
227+ switch o := i .(type ) {
228+ case string :
229+ suite , found := tlsCipherSuites [o ]
230+ if ! found {
231+ return fmt .Errorf ("invalid tls cipher suite '%v'" , o )
232+ }
233+
234+ * cs = suite
235+ case uint64 :
236+ * cs = CipherSuite (o )
237+ default :
238+ return fmt .Errorf ("cipher suite is an unknown type: %T" , o )
221239 }
222-
223- * cs = suite
224240 return nil
225241}
226242
@@ -233,13 +249,20 @@ func (cs CipherSuite) String() string {
233249
234250type tlsCurveType tls.CurveID
235251
236- func (ct * tlsCurveType ) Unpack (s string ) error {
237- t , found := tlsCurveTypes [s ]
238- if ! found {
239- return fmt .Errorf ("invalid tls curve type '%v'" , s )
252+ func (ct * tlsCurveType ) Unpack (i interface {}) error {
253+ switch o := i .(type ) {
254+ case string :
255+ t , found := tlsCurveTypes [o ]
256+ if ! found {
257+ return fmt .Errorf ("invalid tls curve type '%v'" , o )
258+ }
259+
260+ * ct = t
261+ case uint64 :
262+ * ct = tlsCurveType (o )
263+ default :
264+ return fmt .Errorf ("tls curve type is an unsupported input type: %T" , o )
240265 }
241-
242- * ct = t
243266 return nil
244267}
245268
@@ -252,13 +275,20 @@ func (r TLSRenegotiationSupport) String() string {
252275 return "<" + unknownType + ">"
253276}
254277
255- func (r * TLSRenegotiationSupport ) Unpack (s string ) error {
256- t , found := tlsRenegotiationSupportTypes [s ]
257- if ! found {
258- return fmt .Errorf ("invalid tls renegotiation type '%v'" , s )
278+ func (r * TLSRenegotiationSupport ) Unpack (i interface {}) error {
279+ switch o := i .(type ) {
280+ case string :
281+ t , found := tlsRenegotiationSupportTypes [o ]
282+ if ! found {
283+ return fmt .Errorf ("invalid tls renegotiation type '%v'" , o )
284+ }
285+
286+ * r = t
287+ case uint64 :
288+ * r = TLSRenegotiationSupport (o )
289+ default :
290+ return fmt .Errorf ("tls renegotation support is an unknown type: %T" , o )
259291 }
260-
261- * r = t
262292 return nil
263293}
264294
0 commit comments