Skip to content

Commit

Permalink
fix: use Reasoncode type instead of raw string (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
pimg authored Aug 1, 2024
1 parent 71207c2 commit 65f60d5
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func runInteractiveCertGuard(cmd *cobra.Command, args []string) error {
return err
}

_, err = crl.NewStorage(libsqlStorage, cacheDir) // TODO consider better setup for this
_, err = crl.NewStorage(libsqlStorage, cacheDir)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/adapter/db/certificate_revocation_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s *LibSqlStorage) List(ctx context.Context) ([]*crl.CertificateRevocationL
ThisUpdate: thisUpdate,
NextUpdate: nextUpdate,
Raw: dbCrl.Raw,
URL: url, // TODO convert to URL
URL: url,
}
}

Expand Down Expand Up @@ -133,7 +133,7 @@ func (s *LibSqlStorage) SaveRevokedCertificates(ctx context.Context, revocationL
err := qtx.CreateRevokedCertificates(ctx, queries.CreateRevokedCertificatesParams{
Serialnumber: revokedCertificateEntry.SerialNumber.String(),
RevocationDate: revokedCertificateEntry.RevocationTime,
Reason: reason,
Reason: reason.String(),
RevocationList: revocationListId,
})
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/ports/models/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (i item) FilterValue() string { return i.serialnumber }

const TOP_INFO_HEIGHT = 12

// TODO refactor model to not use x509.RevocationList but a domain model or refactor commands/revoked_certificate to return a x.509 revoked certificate
type ListModel struct {
keys listKeyMap
styles *styles.Styles
Expand Down
2 changes: 1 addition & 1 deletion internal/ports/models/revoked_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (r RevokedCertificateModel) View() string {
if err != nil {
revocationReason = "Unknown revocation reason"
} else {
revocationReason = r.styles.RevokedCertificateText.Render("Revocation reason: ") + crl.RevocationReasons[revocationReasonCode]
revocationReason = r.styles.RevokedCertificateText.Render("Revocation reason: ") + crl.RevocationReasons[revocationReasonCode].String()
}

return fmt.Sprintf("%s%s%s", serialnumber, revocationDate, revocationReason)
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/crl/certificate_revocation_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type CertificateRevocationList struct {
}

// TODO changeto map[int]RevocationReason
var RevocationReasons = map[int]string{
var RevocationReasons = map[int]RevocationReason{
0: "unspecified",
1: "keyCompromise",
2: "cACompromise",
Expand Down
4 changes: 4 additions & 0 deletions pkg/domain/crl/revoked_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ type RevokedCertificate struct {

type RevocationReason string

func (r RevocationReason) String() string {
return string(r)
}

const (
RevocationReasonUnspecified RevocationReason = "unspecified"
RevocationReasonKeyCompromise RevocationReason = "keyCompromise"
Expand Down

0 comments on commit 65f60d5

Please sign in to comment.