Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed Aug 21, 2024
1 parent 1e8f43b commit a6a4214
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
4 changes: 2 additions & 2 deletions command/ca/renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func (r *renewer) Renew(outFile string) (resp *api.SignResponse, err error) {
return nil, errors.Wrap(err, "error renewing certificate")
}

if resp.CertChainPEM == nil || len(resp.CertChainPEM) == 0 {
if len(resp.CertChainPEM) == 0 {

Check warning on line 475 in command/ca/renew.go

View check run for this annotation

Codecov / codecov/patch

command/ca/renew.go#L475

Added line #L475 was not covered by tests
resp.CertChainPEM = []api.Certificate{resp.ServerPEM, resp.CaPEM}
}
var data []byte
Expand Down Expand Up @@ -503,7 +503,7 @@ func (r *renewer) Rekey(priv interface{}, outCert, outKey string, writePrivateKe
if err != nil {
return nil, errors.Wrap(err, "error rekeying certificate")
}
if resp.CertChainPEM == nil || len(resp.CertChainPEM) == 0 {
if len(resp.CertChainPEM) == 0 {

Check warning on line 506 in command/ca/renew.go

View check run for this annotation

Codecov / codecov/patch

command/ca/renew.go#L506

Added line #L506 was not covered by tests
resp.CertChainPEM = []api.Certificate{resp.ServerPEM, resp.CaPEM}
}
var data []byte
Expand Down
48 changes: 26 additions & 22 deletions internal/crlutil/crl_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,106 +85,110 @@ func (d distributionPoint) FullNames() []string {
type Extension struct {
Name string `json:"-"`
Details []string `json:"-"`
json map[string]interface{}
json map[string]any
}

func (e *Extension) MarshalJSON() ([]byte, error) {
return json.Marshal(e.json)
}

func (e *Extension) AddDetailf(format string, args ...interface{}) {
func (e *Extension) AddDetailf(format string, args ...any) {

Check warning on line 95 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L95

Added line #L95 was not covered by tests
e.Details = append(e.Details, fmt.Sprintf(format, args...))
}

func (e *Extension) AddDetail(detail string) {
e.Details = append(e.Details, detail)

Check warning on line 100 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L99-L100

Added lines #L99 - L100 were not covered by tests
}

func newExtension(e pkix.Extension) Extension {
var ext Extension
switch {
case e.Id.Equal(oidExtensionReasonCode):
ext.Name = "X509v3 CRL Reason Code:"
value := parseReasonCode(e.Value)
ext.AddDetailf(value)
ext.json = map[string]interface{}{
ext.AddDetail(value)
ext.json = map[string]any{

Check warning on line 110 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L109-L110

Added lines #L109 - L110 were not covered by tests
"crl_reason_code": value,
}

case e.Id.Equal(oidExtensionCRLNumber):
ext.Name = "X509v3 CRL Number:"
var n *big.Int
if _, err := asn1.Unmarshal(e.Value, &n); err == nil {
ext.AddDetailf(n.String())
ext.json = map[string]interface{}{
ext.AddDetail(n.String())
ext.json = map[string]any{

Check warning on line 119 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L118-L119

Added lines #L118 - L119 were not covered by tests
"crl_number": n.String(),
}
} else {
ext.AddDetailf(sanitizeBytes(e.Value))
ext.json = map[string]interface{}{
ext.AddDetail(sanitizeBytes(e.Value))
ext.json = map[string]any{

Check warning on line 124 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L123-L124

Added lines #L123 - L124 were not covered by tests
"crl_number": e.Value,
}
}

case e.Id.Equal(oidExtensionAuthorityKeyID):
var v authorityKeyID
ext.Name = "X509v3 Authority Key Identifier:"
ext.json = map[string]interface{}{
ext.json = map[string]any{

Check warning on line 132 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L132

Added line #L132 was not covered by tests
"authority_key_id": hex.EncodeToString(e.Value),
}
if _, err := asn1.Unmarshal(e.Value, &v); err == nil {
var s string
for _, b := range v.ID {
s += fmt.Sprintf(":%02X", b)
}
ext.AddDetailf("keyid" + s)
ext.AddDetail("keyid" + s)

Check warning on line 140 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L140

Added line #L140 was not covered by tests
} else {
ext.AddDetailf(sanitizeBytes(e.Value))
ext.AddDetail(sanitizeBytes(e.Value))

Check warning on line 142 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L142

Added line #L142 was not covered by tests
}
case e.Id.Equal(oidExtensionIssuingDistributionPoint):
ext.Name = "X509v3 Issuing Distribution Point:"

var v distributionPoint
if _, err := asn1.Unmarshal(e.Value, &v); err != nil {
ext.AddDetailf(sanitizeBytes(e.Value))
ext.json = map[string]interface{}{
ext.AddDetail(sanitizeBytes(e.Value))
ext.json = map[string]any{

Check warning on line 150 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L149-L150

Added lines #L149 - L150 were not covered by tests
"issuing_distribution_point": e.Value,
}
} else {
names := v.FullNames()
if len(names) > 0 {
ext.AddDetailf("Full Name:")
ext.AddDetail("Full Name:")

Check warning on line 156 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L156

Added line #L156 was not covered by tests
for _, n := range names {
ext.AddDetailf(" " + n)
ext.AddDetail(" " + n)

Check warning on line 158 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L158

Added line #L158 was not covered by tests
}
}
js := map[string]interface{}{
js := map[string]any{

Check warning on line 161 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L161

Added line #L161 was not covered by tests
"full_names": names,
}

// Only one of this should be set to true. But for inspect we
// will allow more than one.
if v.OnlyContainsUserCerts {
ext.AddDetailf("Only User Certificates")
ext.AddDetail("Only User Certificates")

Check warning on line 168 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L168

Added line #L168 was not covered by tests
js["only_user_certificates"] = true
}
if v.OnlyContainsCACerts {
ext.AddDetailf("Only CA Certificates")
ext.AddDetail("Only CA Certificates")

Check warning on line 172 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L172

Added line #L172 was not covered by tests
js["only_ca_certificates"] = true
}
if v.OnlyContainsAttributeCerts {
ext.AddDetailf("Only Attribute Certificates")
ext.AddDetail("Only Attribute Certificates")

Check warning on line 176 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L176

Added line #L176 was not covered by tests
js["only_attribute_certificates"] = true
}
if len(v.OnlySomeReasons.Bytes) > 0 {
ext.AddDetailf("Reasons: %x", v.OnlySomeReasons.Bytes)
js["only_some_reasons"] = v.OnlySomeReasons.Bytes
}

ext.json = map[string]interface{}{
ext.json = map[string]any{

Check warning on line 184 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L184

Added line #L184 was not covered by tests
"issuing_distribution_point": js,
}
}
default:
ext.Name = e.Id.String()
ext.AddDetailf(sanitizeBytes(e.Value))
ext.json = map[string]interface{}{
ext.AddDetail(sanitizeBytes(e.Value))
ext.json = map[string]any{

Check warning on line 191 in internal/crlutil/crl_extensions.go

View check run for this annotation

Codecov / codecov/patch

internal/crlutil/crl_extensions.go#L190-L191

Added lines #L190 - L191 were not covered by tests
ext.Name: e.Value,
}
}
Expand Down
4 changes: 1 addition & 3 deletions internal/sshutil/sshutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package sshutil

import (
"crypto"
//nolint:staticcheck // Maintain support for deprecated algorithms.
"crypto/dsa"
"crypto/dsa" // Maintain support for deprecated algorithms.
"crypto/ecdsa"
"crypto/ed25519"
"crypto/elliptic"
Expand Down Expand Up @@ -202,7 +201,6 @@ func parseECDSA(in []byte) (*ecdsa.PublicKey, error) {
return nil, errors.Errorf("unsupported curve %s", w.Curve)
}

//nolint:staticcheck // ignore this deprecation warning - golang will fix
key.X, key.Y = elliptic.Unmarshal(key.Curve, w.KeyBytes)
if key.X == nil || key.Y == nil {
return nil, errors.New("invalid curve point")
Expand Down
2 changes: 1 addition & 1 deletion utils/cautils/certificate_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (f *CertificateFlow) Sign(ctx *cli.Context, tok string, csr api.Certificate
return err
}

if resp.CertChainPEM == nil || len(resp.CertChainPEM) == 0 {
if len(resp.CertChainPEM) == 0 {

Check warning on line 265 in utils/cautils/certificate_flow.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/certificate_flow.go#L265

Added line #L265 was not covered by tests
resp.CertChainPEM = []api.Certificate{resp.ServerPEM, resp.CaPEM}
}
var data []byte
Expand Down
2 changes: 1 addition & 1 deletion utils/cautils/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func NewAdminClient(ctx *cli.Context, opts ...ca.ClientOption) (*ca.AdminClient,
if err != nil {
return nil, err
}
if signResponse.CertChainPEM == nil || len(signResponse.CertChainPEM) == 0 {
if len(signResponse.CertChainPEM) == 0 {

Check warning on line 187 in utils/cautils/client.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/client.go#L187

Added line #L187 was not covered by tests
signResponse.CertChainPEM = []api.Certificate{signResponse.ServerPEM, signResponse.CaPEM}
}
adminCert = make([]*x509.Certificate, len(signResponse.CertChainPEM))
Expand Down

0 comments on commit a6a4214

Please sign in to comment.