Skip to content

Commit

Permalink
stores: return deep copy in secretKey.Scan
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Nov 30, 2023
1 parent 22f903d commit dca1f91
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions stores/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"go.sia.tech/core/types"
)

const (
secretKeySize = 32
)

var zeroCurrency = currency(types.ZeroCurrency)

type (
Expand Down Expand Up @@ -47,8 +51,10 @@ func (k *secretKey) Scan(value interface{}) error {
bytes, ok := value.([]byte)
if !ok {
return errors.New(fmt.Sprint("failed to unmarshal secretKey value:", value))
} else if len(bytes) != secretKeySize {
return fmt.Errorf("failed to unmarshal secretKey value due to invalid number of bytes %v != %v: %v", len(bytes), secretKeySize, value)
}
*k = secretKey(bytes)
*k = append(secretKey{}, secretKey(bytes)...)
return nil
}

Expand All @@ -68,7 +74,7 @@ func (h *hash256) Scan(value interface{}) error {
if !ok {
return errors.New(fmt.Sprint("failed to unmarshal hash256 value:", value))
}
if len(bytes) < len(hash256{}) {
if len(bytes) != len(hash256{}) {
return fmt.Errorf("failed to unmarshal hash256 value due to insufficient bytes %v < %v: %v", len(bytes), len(fileContractID{}), value)
}
*h = *(*hash256)(bytes)
Expand Down

0 comments on commit dca1f91

Please sign in to comment.