-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
131 additions
and
46 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
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,41 @@ | ||
package ndncert | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
type ChallengePin struct { | ||
// Callback to get the code from the user. | ||
CodeCallback func(status string) string | ||
} | ||
|
||
func (*ChallengePin) Name() string { | ||
return KwPin | ||
} | ||
|
||
func (c *ChallengePin) Request(input ParamMap, status *string) (ParamMap, error) { | ||
// Validate challenge configuration | ||
if c.CodeCallback == nil { | ||
return nil, errors.New("pin challenge not configured") | ||
} | ||
|
||
// Initial request parameters | ||
if input == nil { | ||
return ParamMap{}, nil | ||
} | ||
|
||
// Challenge response code | ||
if status != nil && (*status == "need-code" || *status == "wrong-code") { | ||
code := c.CodeCallback(*status) | ||
if code == "" { | ||
return nil, errors.New("no code provided") | ||
} | ||
|
||
return ParamMap{ | ||
KwCode: []byte(code), | ||
}, nil | ||
} | ||
|
||
// Unknown status | ||
return nil, errors.New("unknown input to pin challenge") | ||
} |
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