[#595] Simplify encryption.Params struct

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-08-12 09:56:38 +03:00 committed by Kirillov Denis
parent 94a6a55919
commit 7ab473a688
3 changed files with 14 additions and 11 deletions

View file

@ -334,7 +334,12 @@ func (h handler) formEncryptionParams(header http.Header) (enc encryption.Params
return enc, errors.GetAPIError(errors.ErrSSECustomerKeyMD5Mismatch)
}
return encryption.NewParams(key)
params, err := encryption.NewParams(key)
if err == nil {
enc = *params
}
return enc, err
}
func (h *handler) PostObject(w http.ResponseWriter, r *http.Request) {

View file

@ -15,7 +15,6 @@ import (
// Params contains encryption key info.
type Params struct {
enabled bool
customerKey []byte
}
@ -66,25 +65,24 @@ const (
)
// NewParams creates new params to encrypt with provided key.
func NewParams(key []byte) (Params, error) {
var p Params
func NewParams(key []byte) (*Params, error) {
if len(key) != aes256KeySize {
return p, fmt.Errorf("invalid key size: %d", len(key))
return nil, fmt.Errorf("invalid key size: %d", len(key))
}
p.enabled = true
var p Params
p.customerKey = make([]byte, aes256KeySize)
copy(p.customerKey, key)
return p, nil
return &p, nil
}
// Key returns encryption key as slice.
// Key returns encryption key.
func (p Params) Key() []byte {
return p.customerKey[:]
return p.customerKey
}
// Enabled returns true if key isn't empty.
func (p Params) Enabled() bool {
return p.enabled
return len(p.customerKey) > 0
}
// HMAC computes salted HMAC.

View file

@ -58,7 +58,7 @@ func getDecrypter(t *testing.T) *Decrypter {
return &Decrypter{
parts: parts,
encryption: params,
encryption: *params,
}
}