mirror of
https://github.com/minio/minio.git
synced 2025-11-20 01:50:24 -05:00
use jsoniter for json marshal/unmarshal in KMS (#12146)
Signed-off-by: Harshavardhana <harsha@minio.io>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user