forked from TrueCloudLab/frostfs-s3-gw
[#595] Simplify encryption.Params struct
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
94a6a55919
commit
7ab473a688
3 changed files with 14 additions and 11 deletions
|
@ -334,7 +334,12 @@ func (h handler) formEncryptionParams(header http.Header) (enc encryption.Params
|
||||||
return enc, errors.GetAPIError(errors.ErrSSECustomerKeyMD5Mismatch)
|
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) {
|
func (h *handler) PostObject(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -15,7 +15,6 @@ import (
|
||||||
|
|
||||||
// Params contains encryption key info.
|
// Params contains encryption key info.
|
||||||
type Params struct {
|
type Params struct {
|
||||||
enabled bool
|
|
||||||
customerKey []byte
|
customerKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,25 +65,24 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewParams creates new params to encrypt with provided key.
|
// NewParams creates new params to encrypt with provided key.
|
||||||
func NewParams(key []byte) (Params, error) {
|
func NewParams(key []byte) (*Params, error) {
|
||||||
var p Params
|
|
||||||
if len(key) != aes256KeySize {
|
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)
|
p.customerKey = make([]byte, aes256KeySize)
|
||||||
copy(p.customerKey, key)
|
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 {
|
func (p Params) Key() []byte {
|
||||||
return p.customerKey[:]
|
return p.customerKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enabled returns true if key isn't empty.
|
// Enabled returns true if key isn't empty.
|
||||||
func (p Params) Enabled() bool {
|
func (p Params) Enabled() bool {
|
||||||
return p.enabled
|
return len(p.customerKey) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// HMAC computes salted HMAC.
|
// HMAC computes salted HMAC.
|
||||||
|
|
|
@ -58,7 +58,7 @@ func getDecrypter(t *testing.T) *Decrypter {
|
||||||
|
|
||||||
return &Decrypter{
|
return &Decrypter{
|
||||||
parts: parts,
|
parts: parts,
|
||||||
encryption: params,
|
encryption: *params,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue