Skip to content

Commit

Permalink
Fix Encryption Algorithm field. (#118)
Browse files Browse the repository at this point in the history
* fix encryption algo logic

Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com>

* comments

Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com>

---------

Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com>
  • Loading branch information
MDarmawan committed Aug 25, 2023
1 parent 167b674 commit ffa8c25
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,25 @@ func WithDescription(description string) CreateKeyOption {
func WithPayload(payload string, encryptedNonce, iv *string, sha1 bool) CreateKeyOption {
return func(key *Key) {
key.Payload = payload
if !key.Extractable && payload != "" {
algorithm := AlgorithmRSAOAEP256
if sha1 {
algorithm = AlgorithmRSAOAEP1
}
key.EncryptionAlgorithm = algorithm

if encryptedNonce != nil {
if !key.Extractable {
hasNonce := encryptedNonce != nil && *encryptedNonce != ""
hasIV := iv != nil && *iv != ""
if hasNonce {
key.EncryptedNonce = *encryptedNonce
}
if iv != nil {
if hasIV {
key.IV = *iv
}
// Encryption algo field is only for secure import.
// Only included it if either nonce or IV are specified.
// API will error if only one of IV or nonce are specified but the other is empty.
if hasNonce || hasIV {
algorithm := AlgorithmRSAOAEP256
if sha1 {
algorithm = AlgorithmRSAOAEP1
}
key.EncryptionAlgorithm = algorithm
}
}
}
}
Expand Down

0 comments on commit ffa8c25

Please sign in to comment.