Skip to content

Commit

Permalink
Rename the Getter to a commonly used one in Go.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxki committed Sep 27, 2023
1 parent 50e925a commit a8be571
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cache_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (c *CacheBatch) Run(ctx context.Context) {
// Update cache store
invs := c.cacheStore.Update(caches)
for _, inv := range invs {
logger.Error().Msgf("Invalid response cache: %s", inv.GetEntry().Serial)
logger.Error().Msgf("Invalid response cache: %s", inv.Entry().Serial)
}
logger.Info().Msg("Response cache updated.")

Expand Down
14 changes: 7 additions & 7 deletions cache_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ func TestCacheBatch_Run_DBNotChanged(t *testing.T) {

cache := testGetCache(t, targetSerialStr, store)

if cache.GetEntry().Serial.Cmp(targetSerial) != 0 {
if cache.Entry().Serial.Cmp(targetSerial) != 0 {
t.Fatalf("Expected serial is %s but got %s.",
cache.GetEntry().Serial.Text(db.SerialBase),
cache.GetEntry().Serial.Text(db.SerialBase))
cache.Entry().Serial.Text(db.SerialBase),
cache.Entry().Serial.Text(db.SerialBase))
}
}

Expand Down Expand Up @@ -153,8 +153,8 @@ func TestCacheBatch_Run_DBChanged(t *testing.T) {
// Do Assertion
cache := testGetCache(t, targetSerial, store)

if string(cache.GetEntry().RevType) != wantType {
t.Fatalf("Expected rev type is %s but got %s.", wantType, string(cache.GetEntry().RevType))
if string(cache.Entry().RevType) != wantType {
t.Fatalf("Expected rev type is %s but got %s.", wantType, string(cache.Entry().RevType))
}
}

Expand Down Expand Up @@ -196,7 +196,7 @@ func TestCacheBatch_Run_DelegatedResponder(t *testing.T) {

cache := testGetCache(t, targetSerialStr, store)

if cache.GetTemplate().Certificate == nil {
if cache.Template().Certificate == nil {
t.Fatal("Delegated signing responder may contain itself certificate.")
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestCacheBatch_Run_DirectResponder(t *testing.T) {

cache := testGetCache(t, targetSerialStr, store)

if cache.GetTemplate().Certificate != nil {
if cache.Template().Certificate != nil {
t.Fatalf("Direct signing responder may not contain itself certificate.")
}
}
8 changes: 4 additions & 4 deletions cache_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ func verifyIssuer(req *ocsp.Request, responder *Responder) error {
func addSuccessOCSPResHeader(w http.ResponseWriter, cache *cache.ResponseCache, nowT time.Time, cacheCtlMaxAge int) {
// Configured max-age cannot be over nextUpdate
maxAge := cacheCtlMaxAge
durToNext := cache.GetTemplate().NextUpdate.Sub(nowT)
durToNext := cache.Template().NextUpdate.Sub(nowT)
if durToNext < time.Second*time.Duration(cacheCtlMaxAge) {
maxAge = int(durToNext / time.Second)
}

w.Header().Add("Cache-Control", fmt.Sprintf("max-age=%d, public, no-transform, must-revalidate", maxAge))
w.Header().Add("Last-Modified", cache.GetTemplate().ProducedAt.Format(http.TimeFormat))
w.Header().Add("Expires", cache.GetTemplate().NextUpdate.Format(http.TimeFormat))
w.Header().Add("Last-Modified", cache.Template().ProducedAt.Format(http.TimeFormat))
w.Header().Add("Expires", cache.Template().NextUpdate.Format(http.TimeFormat))
w.Header().Add("Date", nowT.Format(http.TimeFormat))
w.Header().Add("ETag", cache.SHA1HashHexString())
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func (c CacheHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

nowT := c.now()
if cmp := nowT.Compare(cache.GetTemplate().NextUpdate); cmp > 0 {
if cmp := nowT.Compare(cache.Template().NextUpdate); cmp > 0 {
logger.Error().Msgf("nextUpdate of found cache is set in the past.")
_, err = w.Write(ocsp.UnauthorizedErrorResponse)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cache_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func testHTTPResContent(t *testing.T, responder *Responder, res *http.Response,
t.Fatal(err)
}

if ocspRes.SerialNumber.Cmp(cache.GetTemplate().SerialNumber) != 0 {
if ocspRes.SerialNumber.Cmp(cache.Template().SerialNumber) != 0 {
t.Fatal("Cached response is not match with requested response")
}
}
Expand Down Expand Up @@ -350,7 +350,7 @@ func TestCacheHandler_ServeHTTP_ResponseSuccess(t *testing.T) {
res := testHandler(t, "8090", handler, responder)
defer res.Body.Close()

template := resCache.GetTemplate()
template := resCache.Template()
testHTTPResHeader(t, res.Header, &template)
testHTTPResContent(t, responder, res, resCache)
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/cache/res_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ func CreatePreSignedResponseCache(
}, nil
}

// GetTemplate returns a CertificateEntry object.
func (r *ResponseCache) GetEntry() db.CertificateEntry {
// Entry returns a CertificateEntry object.
func (r *ResponseCache) Entry() db.CertificateEntry {
return r.entry
}

// GetTemplate returns the ocsp.Response as template of signed response.
func (r *ResponseCache) GetTemplate() ocsp.Response {
// Template returns the ocsp.Response as template of signed response.
func (r *ResponseCache) Template() ocsp.Response {
return r.template
}

Expand All @@ -144,8 +144,8 @@ func (r *ResponseCache) SetResponse(response []byte) (*ResponseCache, error) {
return r, nil
}

// GetResponse returns a copy of the signed response cache.
func (r *ResponseCache) GetResponse() []byte {
// Response returns a copy of the signed response cache.
func (r *ResponseCache) Response() []byte {
if r.response == nil {
return nil
}
Expand All @@ -154,8 +154,8 @@ func (r *ResponseCache) GetResponse() []byte {
return res
}

// GetSHA1Hash returns the copy of the SHA1 hash of the OCSP response.
func (r *ResponseCache) GetSHA1Hash() []byte {
// SHA1Hash returns the copy of the SHA1 hash of the OCSP response.
func (r *ResponseCache) SHA1Hash() []byte {
if r.sha1Hash == nil {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/res_cache_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *ResponseCacheStore) Update(caches []ResponseCache) []ResponseCache {

for _, cache := range caches {
// Check if it is possible to retrieve the serial number
key, ok := cacheMapKey(cache.GetTemplate().SerialNumber)
key, ok := cacheMapKey(cache.Template().SerialNumber)
if !ok {
invalids = append(invalids, cache)
continue
Expand All @@ -80,7 +80,7 @@ func (r *ResponseCacheStore) Update(caches []ResponseCache) []ResponseCache {
}

// Check if the OCSP response exists
if res := cache.GetResponse(); res == nil {
if res := cache.Response(); res == nil {
invalids = append(invalids, cache)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func (r *Responder) SignCacheResponse(cache cache.ResponseCache) (cache.Response
}
}

res, err := ocsp.CreateResponse(r.issuerCert, r.rCert, cache.GetTemplate(), priv)
res, err := ocsp.CreateResponse(r.issuerCert, r.rCert, cache.Template(), priv)
if err != nil {
return cache, err
}
Expand Down
26 changes: 13 additions & 13 deletions responder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,34 +386,34 @@ func TestResponder_SignCacheResponse(t *testing.T) {
return
}

res, err := ocsp.ParseResponse(resCache.GetResponse(), responder.rCert)
res, err := ocsp.ParseResponse(resCache.Response(), responder.rCert)
if err != nil {
t.Fatal(err)
}

if len(resCache.GetSHA1Hash()) != 20 {
if len(resCache.SHA1Hash()) != 20 {
t.Errorf(
"resCache.sha1Hash is not may not be a SHA1 hash of the OCSPResponse: %#v", resCache.GetSHA1Hash())
"resCache.sha1Hash is not may not be a SHA1 hash of the OCSPResponse: %#v", resCache.SHA1Hash())
}

if res.Status != resCache.GetTemplate().Status {
t.Errorf("State %#v is changed: %#v", resCache.GetTemplate().Status, res.Status)
if res.Status != resCache.Template().Status {
t.Errorf("State %#v is changed: %#v", resCache.Template().Status, res.Status)
}

if !reflect.DeepEqual(res.SerialNumber, resCache.GetTemplate().SerialNumber) {
t.Errorf("State %#v is changed: %#v", resCache.GetTemplate().SerialNumber, res.SerialNumber)
if !reflect.DeepEqual(res.SerialNumber, resCache.Template().SerialNumber) {
t.Errorf("State %#v is changed: %#v", resCache.Template().SerialNumber, res.SerialNumber)
}

if !reflect.DeepEqual(res.ThisUpdate, resCache.GetTemplate().ThisUpdate) {
t.Errorf("State %#v is changed: %#v", resCache.GetTemplate().ThisUpdate, res.ThisUpdate)
if !reflect.DeepEqual(res.ThisUpdate, resCache.Template().ThisUpdate) {
t.Errorf("State %#v is changed: %#v", resCache.Template().ThisUpdate, res.ThisUpdate)
}

if !reflect.DeepEqual(res.NextUpdate, resCache.GetTemplate().NextUpdate) {
t.Errorf("State %#v is changed: %#v", resCache.GetTemplate().NextUpdate, res.NextUpdate)
if !reflect.DeepEqual(res.NextUpdate, resCache.Template().NextUpdate) {
t.Errorf("State %#v is changed: %#v", resCache.Template().NextUpdate, res.NextUpdate)
}

if !reflect.DeepEqual(res.RevocationReason, resCache.GetTemplate().RevocationReason) {
t.Errorf("State %#v is changed: %#v", resCache.GetTemplate().RevocationReason, res.RevocationReason)
if !reflect.DeepEqual(res.RevocationReason, resCache.Template().RevocationReason) {
t.Errorf("State %#v is changed: %#v", resCache.Template().RevocationReason, res.RevocationReason)
}
})
}
Expand Down

0 comments on commit a8be571

Please sign in to comment.