-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tlscurve option to specify TLS curve. (#442)
Valid values for this option are: P-224, P-256, P-384, and P-512. P-521 is the default curve used by the wallet config. Closes #441.
- Loading branch information
Showing
4 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2016 The Decred developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
package cfgutil | ||
|
||
import ( | ||
"crypto/elliptic" | ||
"fmt" | ||
) | ||
|
||
// CurveID specifies a recognized curve through a constant value. | ||
type CurveID int | ||
|
||
// Recognized curve IDs. | ||
const ( | ||
CurveP224 CurveID = iota | ||
CurveP256 | ||
CurveP384 | ||
CurveP521 | ||
) | ||
|
||
// CurveFlag describes a curve and implements the flags.Marshaler and | ||
// Unmarshaler interfaces so it can be used as a config struct field. | ||
type CurveFlag struct { | ||
curveID CurveID | ||
} | ||
|
||
// NewCurveFlag creates a CurveFlag with a default curve. | ||
func NewCurveFlag(defaultValue CurveID) *CurveFlag { | ||
return &CurveFlag{defaultValue} | ||
} | ||
|
||
// MarshalFlag satisifes the flags.Marshaler interface. | ||
func (f *CurveFlag) MarshalFlag() (name string, err error) { | ||
switch f.curveID { | ||
case CurveP224: | ||
name = "P-224" | ||
case CurveP256: | ||
name = "P-256" | ||
case CurveP384: | ||
name = "P-384" | ||
case CurveP521: | ||
name = "P-521" | ||
default: | ||
err = fmt.Errorf("unknown curve ID %v", int(f.curveID)) | ||
} | ||
return | ||
} | ||
|
||
// UnmarshalFlag satisifes the flags.Unmarshaler interface. | ||
func (f *CurveFlag) UnmarshalFlag(value string) error { | ||
switch value { | ||
case "P-224": | ||
f.curveID = CurveP224 | ||
case "P-256": | ||
f.curveID = CurveP256 | ||
case "P-384": | ||
f.curveID = CurveP384 | ||
case "P-521": | ||
f.curveID = CurveP521 | ||
default: | ||
return fmt.Errorf("unrecognized curve %v", value) | ||
} | ||
return nil | ||
} | ||
|
||
// Curve returns the elliptic.Curve specified by the flag. | ||
func (f *CurveFlag) Curve() elliptic.Curve { | ||
switch f.curveID { | ||
case CurveP224: | ||
return elliptic.P224() | ||
case CurveP256: | ||
return elliptic.P256() | ||
case CurveP384: | ||
return elliptic.P384() | ||
case CurveP521: | ||
return elliptic.P521() | ||
default: | ||
panic("unreachable") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters