Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <[email protected]>
  • Loading branch information
JeyJeyGao committed Sep 18, 2024
1 parent 75f5f6c commit 617bd7f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
8 changes: 0 additions & 8 deletions revocation/crl/cache/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions revocation/crl/cache/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
14 changes: 10 additions & 4 deletions revocation/crl/cache/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-*"
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions revocation/revocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 617bd7f

Please sign in to comment.