use jsoniter for json marshal/unmarshal in KMS (#12146)

Signed-off-by: Harshavardhana <harsha@minio.io>
This commit is contained in:
Harshavardhana 2021-04-26 16:01:52 -07:00 committed by GitHub
parent d501c5e38b
commit 2966823818
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View file

@ -1499,7 +1499,6 @@ func (er erasureObjects) restoreTransitionedObject(ctx context.Context, bucket s
}
_, err = er.CompleteMultipartUpload(ctx, bucket, object, uploadID, uploadedParts, ObjectOptions{
VersionID: oi.VersionID,
MTime: oi.ModTime,
Versioned: globalBucketVersioningSys.Enabled(bucket),
VersionSuspended: globalBucketVersioningSys.Suspended(bucket),

View file

@ -20,6 +20,8 @@ package kms
import (
"encoding"
"encoding/json"
jsoniter "github.com/json-iterator/go"
)
// KMS is the generic interface that abstracts over
@ -106,6 +108,7 @@ func (d *DEK) UnmarshalText(text []byte) error {
Ciphertext []byte `json:"ciphertext"`
}
var v JSON
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(text, &v); err != nil {
return err
}

View file

@ -23,12 +23,12 @@ import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
jsoniter "github.com/json-iterator/go"
"github.com/secure-io/sio-go/sioutil"
"golang.org/x/crypto/chacha20"
"golang.org/x/crypto/chacha20poly1305"
@ -152,6 +152,7 @@ func (kms secretKey) GenerateKey(keyID string, context Context) (DEK, error) {
associatedData, _ := context.MarshalText()
ciphertext := aead.Seal(nil, nonce, plaintext, associatedData)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
ciphertext, err = json.Marshal(encryptedKey{
Algorithm: algorithm,
IV: iv,
@ -174,9 +175,11 @@ func (kms secretKey) DecryptKey(keyID string, ciphertext []byte, context Context
}
var encryptedKey encryptedKey
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(ciphertext, &encryptedKey); err != nil {
return nil, err
}
if n := len(encryptedKey.IV); n != 16 {
return nil, fmt.Errorf("kms: invalid iv size")
}