From 617bd7fa5b319f7518c0f65f37910d2feb99267f Mon Sep 17 00:00:00 2001 From: Junjie Gao Date: Wed, 18 Sep 2024 06:41:06 +0000 Subject: [PATCH] fix: update Signed-off-by: Junjie Gao --- revocation/crl/cache/bundle.go | 8 -------- revocation/crl/cache/errors.go | 6 ++---- revocation/crl/cache/file.go | 14 ++++++++++---- revocation/revocation.go | 9 +++++---- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/revocation/crl/cache/bundle.go b/revocation/crl/cache/bundle.go index d5e0603c..e6529c73 100644 --- a/revocation/crl/cache/bundle.go +++ b/revocation/crl/cache/bundle.go @@ -19,14 +19,6 @@ import ( "time" ) -const ( - // PathBaseCRL is the file name of the base CRL - PathBaseCRL = "base.crl" - - // PathMetadata is the file name of the metadata - PathMetadata = "metadata.json" -) - // CRLMetadata stores the URL of the CRL type CRLMetadata struct { // URL stores the URL of the CRL diff --git a/revocation/crl/cache/errors.go b/revocation/crl/cache/errors.go index adfb8a13..f5968297 100644 --- a/revocation/crl/cache/errors.go +++ b/revocation/crl/cache/errors.go @@ -28,7 +28,5 @@ func (e *BrokenFileError) Error() string { return e.Err.Error() } -var ( - // ErrCacheMiss is an error type for when a cache miss occurs - ErrCacheMiss = errors.New("cache miss") -) +// ErrCacheMiss is an error type for when a cache miss occurs +var ErrCacheMiss = errors.New("cache miss") diff --git a/revocation/crl/cache/file.go b/revocation/crl/cache/file.go index 3c417211..87d9bc19 100644 --- a/revocation/crl/cache/file.go +++ b/revocation/crl/cache/file.go @@ -28,6 +28,12 @@ import ( ) const ( + // pathBaseCRL is the file name of the base CRL + pathBaseCRL = "base.crl" + + // pathMetadata is the file name of the metadata + pathMetadata = "metadata.json" + // tempFileName is the prefix of the temporary file tempFileName = "notation-*" ) @@ -167,7 +173,7 @@ func parseBundleFromTar(data io.Reader) (*Bundle, error) { } switch header.Name { - case PathBaseCRL: + case pathBaseCRL: // parse base.crl data, err := io.ReadAll(tar) if err != nil { @@ -182,7 +188,7 @@ func parseBundleFromTar(data io.Reader) (*Bundle, error) { } } bundle.BaseCRL = baseCRL - case PathMetadata: + case pathMetadata: // parse metadata var metadata Metadata if err := json.NewDecoder(tar).Decode(&metadata); err != nil { @@ -225,7 +231,7 @@ func saveTar(w io.Writer, bundle *Bundle) (err error) { }() // Add base.crl - if err := addToTar(PathBaseCRL, bundle.BaseCRL.Raw, bundle.Metadata.CreatedAt, tarWriter); err != nil { + if err := addToTar(pathBaseCRL, bundle.BaseCRL.Raw, bundle.Metadata.CreatedAt, tarWriter); err != nil { return err } @@ -234,7 +240,7 @@ func saveTar(w io.Writer, bundle *Bundle) (err error) { if err != nil { return err } - return addToTar(PathMetadata, metadataBytes, time.Now(), tarWriter) + return addToTar(pathMetadata, metadataBytes, time.Now(), tarWriter) } func addToTar(fileName string, data []byte, modTime time.Time, tw *tar.Writer) error { diff --git a/revocation/revocation.go b/revocation/revocation.go index b04783ad..a06932aa 100644 --- a/revocation/revocation.go +++ b/revocation/revocation.go @@ -134,19 +134,20 @@ func NewWithOptions(opts Options) (Validator, error) { return nil, fmt.Errorf("unsupported certificate chain purpose %v", opts.CertChainPurpose) } - if opts.CRLCache == nil { - memoryCache, err := cache.NewMemoryCache() + crlCache := opts.CRLCache + if crlCache == nil { + newCache, err := cache.NewMemoryCache() if err != nil { return nil, fmt.Errorf("failed to create memory cache: %v", err) } - opts.CRLCache = memoryCache + crlCache = newCache } return &revocation{ ocspHTTPClient: opts.OCSPHTTPClient, crlHTTPClient: opts.CRLHTTPClient, certChainPurpose: opts.CertChainPurpose, - crlCache: opts.CRLCache, + crlCache: crlCache, }, nil }