From b681a146b28c2668906c01afbd08ad588fe446f5 Mon Sep 17 00:00:00 2001 From: Zach Steindler Date: Wed, 8 Nov 2023 09:29:27 -0500 Subject: [PATCH] Remove go-playground/validator dependency from pkg/pki (#1817) See https://github.com/sigstore/sigstore-go/issues/23. It might seem silly, but this reduces the size of sigstore-go by over 1 MB. We're already using asaskevich/govalidator elsewhere in Rekor, so no new dependencies added. If we wanted to remove go-playground/validator entirely from Rekor (which would shrink rekor-cli by over 1 MB as well), we'd need additional work to rekor-cli/app/ files pflags.go and validate.go. Signed-off-by: Zach Steindler --- pkg/pki/pgp/pgp.go | 6 ++---- pkg/pki/x509/x509.go | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/pki/pgp/pgp.go b/pkg/pki/pgp/pgp.go index 19501bc1d..0914db227 100644 --- a/pkg/pki/pgp/pgp.go +++ b/pkg/pki/pgp/pgp.go @@ -28,7 +28,7 @@ import ( "io" "net/http" - validator "github.com/go-playground/validator/v10" + "github.com/asaskevich/govalidator" //TODO: https://github.com/sigstore/rekor/issues/286 "golang.org/x/crypto/openpgp" //nolint:staticcheck @@ -295,9 +295,7 @@ func (k PublicKey) EmailAddresses() []string { // Extract from cert for _, entity := range k.key { for _, identity := range entity.Identities { - validate := validator.New() - errs := validate.Var(identity.UserId.Email, "required,email") - if errs == nil { + if govalidator.IsEmail(identity.UserId.Email) { names = append(names, identity.UserId.Email) } } diff --git a/pkg/pki/x509/x509.go b/pkg/pki/x509/x509.go index 2589849c4..b8d0148ee 100644 --- a/pkg/pki/x509/x509.go +++ b/pkg/pki/x509/x509.go @@ -28,7 +28,7 @@ import ( "io" "strings" - validator "github.com/go-playground/validator/v10" + "github.com/asaskevich/govalidator" "github.com/sigstore/rekor/pkg/pki/identity" "github.com/sigstore/sigstore/pkg/cryptoutils" sigsig "github.com/sigstore/sigstore/pkg/signature" @@ -184,10 +184,8 @@ func (k PublicKey) EmailAddresses() []string { cert = k.certs[0] } if cert != nil { - validate := validator.New() for _, name := range cert.EmailAddresses { - errs := validate.Var(name, "required,email") - if errs == nil { + if govalidator.IsEmail(name) { names = append(names, strings.ToLower(name)) } }