From e35e9e9df65156bdbcd71a946d1e1ffdf2ee056f Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 11 Dec 2022 14:03:45 +0100 Subject: [PATCH] Cleanup command and response types - use consistent method recipient names - move ErrorResponse to the end of the messages - fix email address output in SignCertificateCommand String() method --- pkg/messages/messages.go | 62 ++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/pkg/messages/messages.go b/pkg/messages/messages.go index 3403a75..bfc63f6 100644 --- a/pkg/messages/messages.go +++ b/pkg/messages/messages.go @@ -150,8 +150,8 @@ type CAInfoCommand struct { Name string `msgpack:"name"` } -func (r *CAInfoCommand) String() string { - return fmt.Sprintf("name=%s", r.Name) +func (c *CAInfoCommand) String() string { + return fmt.Sprintf("name=%s", c.Name) } type CAInfoResponse struct { @@ -161,16 +161,8 @@ type CAInfoResponse struct { Profiles []CAProfile `msgpack:"profiles"` } -func (i CAInfoResponse) String() string { - return fmt.Sprintf("certificate name=%s, signing=%t, profiles=[%s]", i.Name, i.Signing, i.Profiles) -} - -type ErrorResponse struct { - Message string `msgpack:"message"` -} - -func (e *ErrorResponse) String() string { - return fmt.Sprintf("message=%s", e.Message) +func (r CAInfoResponse) String() string { + return fmt.Sprintf("certificate name=%s, signing=%t, profiles=[%s]", r.Name, r.Signing, r.Profiles) } type FetchCRLCommand struct { @@ -178,13 +170,13 @@ type FetchCRLCommand struct { LastKnownID []byte `msgpack:"last_known_id"` } -func (f *FetchCRLCommand) String() string { +func (c *FetchCRLCommand) String() string { builder := &strings.Builder{} - _, _ = fmt.Fprintf(builder, "issuerId='%s'", f.IssuerID) + _, _ = fmt.Fprintf(builder, "issuerId='%s'", c.IssuerID) - if f.LastKnownID != nil { - _, _ = fmt.Fprintf(builder, ", lastKnownId=0x%x", new(big.Int).SetBytes(f.LastKnownID)) + if c.LastKnownID != nil { + _, _ = fmt.Fprintf(builder, ", lastKnownId=0x%x", new(big.Int).SetBytes(c.LastKnownID)) } return builder.String() @@ -246,7 +238,7 @@ func (r *FetchCRLResponse) String() string { type HealthCommand struct{} -func (h *HealthCommand) String() string { +func (c *HealthCommand) String() string { return "" } @@ -289,14 +281,14 @@ type HealthResponse struct { Info []*HealthInfo } -func (h *HealthResponse) String() string { +func (r *HealthResponse) String() string { builder := &strings.Builder{} - _, _ = fmt.Fprintf(builder, "signer version=%s, healthy=%v, health data=[", h.Version, h.Healthy) + _, _ = fmt.Fprintf(builder, "signer version=%s, healthy=%v, health data=[", r.Version, r.Healthy) - infos := make([]string, len(h.Info)) + infos := make([]string, len(r.Info)) - for i, info := range h.Info { + for i, info := range r.Info { infos[i] = fmt.Sprintf("{%s}", info) } @@ -319,33 +311,33 @@ type SignCertificateCommand struct { PreferredHash crypto.Hash `msgpack:"preferred_hash"` } -func (s *SignCertificateCommand) String() string { +func (c *SignCertificateCommand) String() string { builder := &strings.Builder{} _, _ = fmt.Fprintf( - builder, "issuer_id=%s, profile_name=%s, cn=%s", s.IssuerID, s.ProfileName, s.CommonName, + builder, "issuer_id=%s, profile_name=%s, cn=%s", c.IssuerID, c.ProfileName, c.CommonName, ) - if s.Organization != "" { - _, _ = fmt.Fprintf(builder, ", o=%s", s.Organization) + if c.Organization != "" { + _, _ = fmt.Fprintf(builder, ", o=%s", c.Organization) } - if s.OrganizationalUnit != "" { - _, _ = fmt.Fprintf(builder, ", ou=%s", s.OrganizationalUnit) + if c.OrganizationalUnit != "" { + _, _ = fmt.Fprintf(builder, ", ou=%s", c.OrganizationalUnit) } - if len(s.Hostnames) > 0 { + if len(c.Hostnames) > 0 { builder.WriteString(", hostnames=[") - builder.WriteString(strings.Join(s.Hostnames, ", ")) + builder.WriteString(strings.Join(c.Hostnames, ", ")) builder.WriteRune(']') } - if len(s.EmailAddresses) > 0 { + if len(c.EmailAddresses) > 0 { builder.WriteString(", email_addresses=[") - builder.WriteString(strings.Join(s.Hostnames, ", ")) + builder.WriteString(strings.Join(c.EmailAddresses, ", ")) builder.WriteRune(']') } @@ -428,3 +420,11 @@ type SignOpenPGPResponse struct { func (r *SignOpenPGPResponse) String() string { return fmt.Sprintf("sig_data of %d bytes", len(r.SignatureData)) } + +type ErrorResponse struct { + Message string `msgpack:"message"` +} + +func (r *ErrorResponse) String() string { + return fmt.Sprintf("message=%s", r.Message) +}