aboutsummaryrefslogtreecommitdiff
path: root/messages.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-12 23:45:39 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-12 23:45:39 +0100
commitbfeba6089e5eaf07f0a8141c800e91cf0842f4ba (patch)
treee20963de175e8150fe74f8a8c49eb30e4a539a54 /messages.go
parentb0aa5a6da8f5426e83c9fb8be0d7c344e40c3363 (diff)
Add challenge type
Diffstat (limited to 'messages.go')
-rw-r--r--messages.go48
1 files changed, 44 insertions, 4 deletions
diff --git a/messages.go b/messages.go
index f444c5c..7527aa3 100644
--- a/messages.go
+++ b/messages.go
@@ -70,10 +70,10 @@ type Identifier struct {
// Challege ...
type Challenge struct {
- Type string `json:"type"` // http-01
- Status Status `json:"status"` // e.g. valid
- Validated string `json:"validated"` // 2006-01-02T15:04Z
- KeyAuthorization string `json:"keyAuthorization"`
+ Type ChallengeType `json:"type"` // http-01
+ Status Status `json:"status"` // e.g. valid
+ Validated string `json:"validated"` // 2006-01-02T15:04Z
+ KeyAuthorization string `json:"keyAuthorization"`
}
// Problem description
@@ -158,3 +158,43 @@ var identTypes = map[IdentType]string{
func (i IdentType) MarshalText() ([]byte, error) {
return []byte(identTypes[i]), nil
}
+
+func (i *IdentType) UnmarshalText(b []byte) error {
+ for k, v := range identTypes {
+ if v == string(b) {
+ *i = k
+ return nil
+ }
+ }
+ return fmt.Errorf("unknown type %v", string(b))
+}
+
+type ChallengeType int
+
+const (
+ ChallengeHTTP ChallengeType = iota
+ ChallengeTLS
+ ChallengePOP
+ ChallengeDNS
+)
+
+var challenges = map[ChallengeType]string{
+ ChallengeHTTP: "http-01",
+ ChallengeTLS: "tls-sni-01",
+ ChallengePOP: "proofOfPossession-01",
+ ChallengeDNS: "dns-01",
+}
+
+func (c ChallengeType) MarshalText() ([]byte, error) {
+ return []byte(challenges[c]), nil
+}
+
+func (c *ChallengeType) UnmarshalText(b []byte) error {
+ for k, v := range challenges {
+ if v == string(b) {
+ *c = k
+ return nil
+ }
+ }
+ return fmt.Errorf("unknown challenge %v", string(b))
+}