Skip to content

Commit

Permalink
change interface for []byte instead of [32]byte
Browse files Browse the repository at this point in the history
  • Loading branch information
phbnf committed Aug 15, 2024
1 parent bf979c6 commit 8c9a576
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 8 additions & 5 deletions personalities/sctfe/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ type Storage interface {
}

type IssuerStorage interface {
Exists(ctx context.Context, key [32]byte) (bool, error)
Add(ctx context.Context, key [32]byte, data []byte) error
Exists(ctx context.Context, key []byte) (bool, error)
Add(ctx context.Context, key []byte, data []byte) error
}

// CTStorage implements Storage.
Expand Down Expand Up @@ -66,17 +66,20 @@ func (cts *CTStorage) AddIssuerChain(ctx context.Context, chain []*x509.Certific
errG := errgroup.Group{}
for _, c := range chain {
errG.Go(func() error {
key := sha256.Sum256(c.Raw)
id := sha256.Sum256(c.Raw)
key := make([]byte, 32)
// TODO(phboneff): is this the same
_ = hex.Encode(key, id[:])
// We first try and see if this issuer cert has already been stored since reads
// are cheaper than writes.
// TODO(phboneff): monitor usage, eventually write directly depending on usage patterns
ok, err := cts.issuers.Exists(ctx, key)
if err != nil {
return fmt.Errorf("error checking if issuer %q exists: %s", hex.EncodeToString(key[:]), err)
return fmt.Errorf("error checking if issuer %q exists: %s", string(key), err)
}
if !ok {
if err = cts.issuers.Add(ctx, key, c.Raw); err != nil {
return fmt.Errorf("error adding certificate for issuer %q: %v", hex.EncodeToString(key[:]), err)
return fmt.Errorf("error adding certificate for issuer %q: %v", string(key), err)

}
}
Expand Down
9 changes: 4 additions & 5 deletions personalities/sctfe/storage/gcp/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package gcp

import (
"context"
"encoding/hex"
"fmt"
"net/http"
"path"
Expand Down Expand Up @@ -69,12 +68,12 @@ func NewGCSStorage(ctx context.Context, projectID string, bucket string, prefix
}

// keyToObjName converts bytes to a GCS object name.
func (s *GCSStorage) keyToObjName(key [32]byte) string {
return path.Join(s.prefix, hex.EncodeToString(key[:]))
func (s *GCSStorage) keyToObjName(key []byte) string {
return path.Join(s.prefix, string(key))
}

// Exists checks whether an object is stored under key.
func (s *GCSStorage) Exists(ctx context.Context, key [32]byte) (bool, error) {
func (s *GCSStorage) Exists(ctx context.Context, key []byte) (bool, error) {
objName := s.keyToObjName(key)
obj := s.bucket.Object(objName)
_, err := obj.Attrs(ctx)
Expand All @@ -92,7 +91,7 @@ func (s *GCSStorage) Exists(ctx context.Context, key [32]byte) (bool, error) {
//
// If there is already an object under that key, it does not override it, and returns.
// TODO(phboneff): consider reading the object to make sure it's identical
func (s *GCSStorage) Add(ctx context.Context, key [32]byte, data []byte) error {
func (s *GCSStorage) Add(ctx context.Context, key []byte, data []byte) error {
objName := s.keyToObjName(key)
obj := s.bucket.Object(objName)

Expand Down

0 comments on commit 8c9a576

Please sign in to comment.