aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-01-21 21:24:57 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-01-21 21:24:57 +0100
commitd0cb3267a05fae23bf15adb2df80402f97f83cab (patch)
tree86e550d911e950ab6839e0970355de83a992545c
parentac0883b44c37dac955c39e9c43b960201836da09 (diff)
Move picker into authz
-rw-r--r--desire.go25
-rw-r--r--messages.go24
-rw-r--r--provider.go2
3 files changed, 25 insertions, 26 deletions
diff --git a/desire.go b/desire.go
index 6c5a163..702cbcb 100644
--- a/desire.go
+++ b/desire.go
@@ -95,28 +95,3 @@ func (d *Desire) CSR() (string, error) {
}
return base64.RawURLEncoding.EncodeToString(der), nil
}
-
-func (d Desire) supported(c []Challenge, com []int) bool {
- for _, n := range com {
- if _, ok := d.solver[c[n].Type]; !ok {
- return false
- }
- }
- return true
-}
-
-func (d Desire) pick(a *Authorization) []Challenge {
- var c []Challenge
- for _, com := range a.Combinations {
- if d.supported(a.Challenges, com) {
- for _, n := range com {
- ch := a.Challenges[n]
- ch.Solver = d.solver[ch.Type]
- a.Challenges[n] = ch
- c = append(c, ch)
- }
- return c
- }
- }
- return c
-}
diff --git a/messages.go b/messages.go
index 26caeac..0b3e4dc 100644
--- a/messages.go
+++ b/messages.go
@@ -47,6 +47,30 @@ type Authorization struct {
Combinations [][]int `json:"combinations,omitempty"`
}
+func (a Authorization) Supported(sol map[ChallengeType]Solver) []Challenge {
+ supported := func(c []int) bool {
+ for _, com := range c {
+ ch := a.Challenges[com]
+ if _, ok := sol[ch.Type]; !ok {
+ return false
+ }
+ }
+ return true
+ }
+ for _, com := range a.Combinations {
+ if supported(com) {
+ var c []Challenge
+ for _, n := range com {
+ ch := a.Challenges[n]
+ ch.Solver = sol[ch.Type]
+ c = append(c, ch)
+ }
+ return c
+ }
+ }
+ return nil
+}
+
// Identifier ...
type Identifier struct {
Type IdentType `json:"type"` // dns
diff --git a/provider.go b/provider.go
index 275e3d7..0c4ebde 100644
--- a/provider.go
+++ b/provider.go
@@ -211,7 +211,7 @@ func (p *Provider) Authz(s Signer, d *Desire) error {
}
// second step: choose and start solver
- for _, ch := range d.pick(r) {
+ for _, ch := range r.Supported(d.solver) {
if err = p.solve(s, ch); err != nil {
return err
}