aboutsummaryrefslogtreecommitdiff
path: root/provider.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-01-11 18:31:08 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-01-11 18:31:08 +0100
commit19ae5a8bf500dd50c23b15c8e52d975f784ffa02 (patch)
tree56b11893705c30a3e4a462dde9751f321b310ac7 /provider.go
parent2d943e29468994f618f1cc5ff784f6b7f510ce05 (diff)
WIP solver
Diffstat (limited to 'provider.go')
-rw-r--r--provider.go27
1 files changed, 12 insertions, 15 deletions
diff --git a/provider.go b/provider.go
index 5ff00ab..ec765cf 100644
--- a/provider.go
+++ b/provider.go
@@ -165,22 +165,26 @@ func (p *Provider) Register(s Signer, c Contacts) error {
return err
}
-func pickChallanges(com []int, c []Challenge) bool {
+func canSatisfice(d *Desire, com []int, c []Challenge) bool {
for _, n := range com {
- if _, ok := canSolve[c[n].Type]; !ok {
+ if _, ok := d.solver[c[n].Type]; !ok {
return false
}
}
return true
}
-func pickCombination(a *Authorization) ([]int, error) {
+func (a Authorization) pick(d *Desire) (c []Challenge) {
for _, com := range a.Combinations {
- if pickChallanges(com, a.Challenges) {
- return com, nil
+ if canSatisfice(d, com, a.Challenges) {
+ for _, n := range com {
+ c = append(c, a.Challenges[n])
+ }
+ return
}
}
- return nil, errors.New("cannot solve any challenges")
+ log.Println("cannot solve any challenges")
+ return
}
func (p *Provider) Authorize(s ThumbSigner, d *Desire) error {
@@ -203,14 +207,7 @@ func (p *Provider) Authorize(s ThumbSigner, d *Desire) error {
return errStatus
}
- com, err := pickCombination(r)
- if err != nil {
- return err
- }
- log.Println("combination", com)
-
- for _, n := range com {
- ch := r.Challenges[n]
+ for _, ch := range r.pick(d) {
ka, _ := KeyAuthorization(s, ch.Token)
ans := &Challenge{
@@ -229,7 +226,7 @@ func (p *Provider) Authorize(s ThumbSigner, d *Desire) error {
return err
}
- sol := canSolve[ch.Type]
+ sol := d.solver[ch.Type]
err = sol.Solve(ch.Token, ka)
if err != nil {
return err