From bfeba6089e5eaf07f0a8141c800e91cf0842f4ba Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 12 Dec 2015 23:45:39 +0100 Subject: Add challenge type --- messages.go | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'messages.go') 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)) +} -- cgit v1.2.3