Skip to content

Commit

Permalink
update the name of a package
Browse files Browse the repository at this point in the history
  • Loading branch information
spikelu2016 committed Apr 8, 2024
1 parent 7e0573c commit 524a2e8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions internal/authenticator/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net/http"
"strings"

"github.com/bricks-cloud/bricksllm/internal/encrypter"
internal_errors "github.com/bricks-cloud/bricksllm/internal/errors"
"github.com/bricks-cloud/bricksllm/internal/hasher"
"github.com/bricks-cloud/bricksllm/internal/stats"

"github.com/bricks-cloud/bricksllm/internal/key"
Expand Down Expand Up @@ -191,7 +191,7 @@ func (a *Authenticator) AuthenticateHttpRequest(req *http.Request) (*key.Respons
return nil, nil, err
}

hash := encrypter.Encrypt(raw)
hash := hasher.Hash(raw)

key := a.kms.GetKey(hash)
if key != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cache
import (
"time"

"github.com/bricks-cloud/bricksllm/internal/encrypter"
"github.com/bricks-cloud/bricksllm/internal/hasher"
)

type store interface {
Expand All @@ -22,7 +22,7 @@ func NewCache(s store) *Cache {
}

func (c *Cache) computeHashKey(value string) string {
return encrypter.Encrypt(value)
return hasher.Hash(value)
}

func (c *Cache) StoreBytes(key string, value []byte, ttl time.Duration) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/encrypter/encrypter.go → internal/hasher/hasher.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package encrypter
package hasher

import (
"crypto/sha256"
"encoding/hex"
)

func Encrypt(secret string) string {
func Hash(secret string) string {
h := sha256.New()
h.Write([]byte(secret))
sha := hex.EncodeToString(h.Sum(nil))
Expand Down
10 changes: 3 additions & 7 deletions internal/manager/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"time"

"github.com/bricks-cloud/bricksllm/internal/encrypter"
"github.com/bricks-cloud/bricksllm/internal/hasher"
"github.com/bricks-cloud/bricksllm/internal/key"
"github.com/bricks-cloud/bricksllm/internal/policy"
"github.com/bricks-cloud/bricksllm/internal/provider"
Expand Down Expand Up @@ -34,10 +34,6 @@ type accessCache interface {
Delete(keyId string) error
}

type Encrypter interface {
Encrypt(secret string) string
}

type Manager struct {
s Storage
clc costLimitCache
Expand Down Expand Up @@ -68,7 +64,7 @@ func (m *Manager) CreateKey(rk *key.RequestKey) (*key.ResponseKey, error) {
}

if !rk.IsKeyNotHashed {
rk.Key = encrypter.Encrypt(rk.Key)
rk.Key = hasher.Hash(rk.Key)
}

if len(rk.SettingId) != 0 {
Expand Down Expand Up @@ -111,7 +107,7 @@ func (m *Manager) UpdateKey(id string, uk *key.UpdateKey) (*key.ResponseKey, err
}

if uk.IsKeyNotHashed != nil && !*uk.IsKeyNotHashed {
uk.Key = encrypter.Encrypt(existing.Key)
uk.Key = hasher.Hash(existing.Key)
}

if uk.IsKeyNotHashed == nil || (uk.IsKeyNotHashed != nil && *uk.IsKeyNotHashed) {
Expand Down

0 comments on commit 524a2e8

Please sign in to comment.