Skip to content

Commit

Permalink
don't try to decode nil
Browse files Browse the repository at this point in the history
avoid throwing an exception in case there are no encryptionDetails in the response
  • Loading branch information
mreinsch committed Sep 3, 2021
1 parent e45bf90 commit 5d84780
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/amz_sp_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def inflate_document(body, document_response_payload)

# from https://github.com/amzn/selling-partner-api-models/blob/main/clients/sellingpartner-api-documents-helper-java/src/main/java/com/amazon/spapi/documents/impl/AESCryptoStreamFactory.java
def document_cipher(response, encrypt:)
if key = Base64.decode64(response.dig(:encryptionDetails, :key))
if key = response.dig(:encryptionDetails, :key)
key = Base64.decode64(key)
cipher = case response.dig(:encryptionDetails, :standard)
when "AES"
OpenSSL::Cipher.new("AES-#{key.size * 8}-CBC")
Expand Down

0 comments on commit 5d84780

Please sign in to comment.