aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-01-25 14:50:28 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-01-25 14:50:28 +0100
commite20bb5c590dfd2f5a5b84e235920ca6550cb13df (patch)
treec3ef1cd124e63d39c75a857fc1c385efba024539
parentb0757dcf4d16d78188468f0a1d012be3a1364549 (diff)
KISS
-rw-r--r--messages.go141
1 files changed, 24 insertions, 117 deletions
diff --git a/messages.go b/messages.go
index 0b3e4dc..b566b1a 100644
--- a/messages.go
+++ b/messages.go
@@ -1,7 +1,6 @@
package acme
import (
- "fmt"
"net"
"time"
@@ -103,137 +102,45 @@ func (p Problem) Error() string {
}
// Status of request
-type Status int
+type Status string
// Statuses
const (
- StatusUnknown Status = iota + 1
- StatusPending
- StatusProcessing
- StatusValid
- StatusInvalid
- StatusRevoked
+ StatusUnknown Status = "unknown"
+ StatusPending Status = "pending"
+ StatusProcessing Status = "processing"
+ StatusValid Status = "valid"
+ StatusInvalid Status = "invalid"
+ StatusRevoked Status = "revoked"
)
-var status = map[Status]string{
- StatusUnknown: "unknown",
- StatusPending: "pending",
- StatusProcessing: "processing",
- StatusValid: "valid",
- StatusInvalid: "invalid",
- StatusRevoked: "revoked",
-}
-
-// UnmarshalText implemets json interface for status decoding
-func (s *Status) UnmarshalText(b []byte) error {
- for k, v := range status {
- if v == string(b) {
- *s = k
- return nil
- }
- }
- return fmt.Errorf("unknown status %v", string(b))
-}
-
-func (s Status) String() string {
- return status[s]
-}
-
-type Resource int
+type Resource string
const (
- ResNewReg Resource = iota + 1
- ResRecoverReg
- ResNewAuthz
- ResNewCert
- ResRevokeCert
- ResReg
- ResAuthz
- ResChallenge
- ResCert
+ ResNewReg Resource = "new-reg"
+ ResRecoverReg Resource = "recover-reg"
+ ResNewAuthz Resource = "new-authz"
+ ResNewCert Resource = "new-cert"
+ ResRevokeCert Resource = "revoke-cert"
+ ResReg Resource = "reg"
+ ResAuthz Resource = "authz"
+ ResChallenge Resource = "challenge"
+ ResCert Resource = "cert"
)
-var resources = map[Resource]string{
- ResNewReg: "new-reg",
- ResRecoverReg: "recover-reg",
- ResNewAuthz: "new-authz",
- ResNewCert: "new-cert",
- ResRevokeCert: "revoke-cert",
- ResReg: "reg",
- ResAuthz: "authz",
- ResChallenge: "challenge",
- ResCert: "cert",
-}
-
-func (r Resource) String() string {
- return resources[r]
-}
-
-// MarshalText implements text encoding marshaller
-func (r Resource) MarshalText() ([]byte, error) {
- return []byte(r.String()), nil
-}
-
-type IdentType int
-
-const IdentDNS IdentType = iota + 1
-
-var identTypes = map[IdentType]string{
- IdentDNS: "dns",
-}
-
-func (i IdentType) String() string {
- return identTypes[i]
-}
+type IdentType string
-func (i IdentType) MarshalText() ([]byte, error) {
- return []byte(i.String()), nil
-}
+const IdentDNS IdentType = "dns"
-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
+type ChallengeType string
const (
- ChallengeHTTP ChallengeType = iota + 1
- ChallengeTLS
- ChallengePOP
- ChallengeDNS
+ ChallengeHTTP ChallengeType = "http-01"
+ ChallengeTLS ChallengeType = "tls-sni-01"
+ ChallengePOP ChallengeType = "proofOfPossession-01"
+ ChallengeDNS ChallengeType = "dns-01"
)
-var challenges = map[ChallengeType]string{
- ChallengeHTTP: "http-01",
- ChallengeTLS: "tls-sni-01",
- ChallengePOP: "proofOfPossession-01",
- ChallengeDNS: "dns-01",
-}
-
-func (c ChallengeType) String() string {
- return challenges[c]
-}
-
-func (c ChallengeType) MarshalText() ([]byte, error) {
- return []byte(c.String()), 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))
-}
-
type CSR struct {
Resource Resource `json:"resource"` // new-cert
CSR string `json:"csr"`