Skip to content

Commit

Permalink
Adding a length check to seperate hex from b64 check
Browse files Browse the repository at this point in the history
  • Loading branch information
zveinn committed Jun 13, 2024
1 parent 6a02624 commit 6dadb1c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cmd/encryption-methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,16 @@ func parseSSEKey(sseKey string, keyType sseKeyType) (
return
}

keyB, de := hex.DecodeString(encodedKey)
if de != nil {
keyB, de = base64.RawStdEncoding.DecodeString(encodedKey)
if de != nil {
err = errSSEClientKeyFormat(fmt.Sprintf("Key (%s) was neither base64 raw encoded nor hex encoded.", encodedKey)).Trace(sseKey)
return
}
var keyB []byte
var decodeError error
if len(encodedKey) == 64 {
keyB, decodeError = hex.DecodeString(encodedKey)
} else {
keyB, decodeError = base64.RawStdEncoding.DecodeString(encodedKey)
}

if decodeError != nil {
err = errSSEClientKeyFormat(fmt.Sprintf("Key (%s) was neither base64 raw encoded nor hex encoded.", encodedKey)).Trace(sseKey)
}

key = string(keyB)
Expand Down

0 comments on commit 6dadb1c

Please sign in to comment.