Skip to content

Commit

Permalink
Merge pull request #164 from pusher/strict-base64-variants
Browse files Browse the repository at this point in the history
use strict base64 variants
  • Loading branch information
Callum Oakley authored Oct 28, 2020
2 parents c6759c4 + 92c8451 commit 788f862
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Unreleased
==========

* Remove newline from end of base64 encoded strings, some decoders don't like
them.

1.4.2 / 2020-10-20
==================

Expand Down
8 changes: 4 additions & 4 deletions lib/pusher/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def initialize(options = {})

if options.has_key?(:encryption_master_key_base64)
@encryption_master_key =
Base64.decode64(options[:encryption_master_key_base64])
Base64.strict_decode64(options[:encryption_master_key_base64])
end

@http_proxy = nil
Expand Down Expand Up @@ -148,7 +148,7 @@ def timeout=(value)
# Set an encryption_master_key to use with private-encrypted channels from
# a base64 encoded string.
def encryption_master_key_base64=(s)
@encryption_master_key = s ? Base64.decode64(s) : nil
@encryption_master_key = s ? Base64.strict_decode64(s) : nil
end

## INTERACT WITH THE API ##
Expand Down Expand Up @@ -483,8 +483,8 @@ def encrypt(channel_name, encoded_data)
ciphertext = secret_box.encrypt(nonce, encoded_data)

MultiJson.encode({
"nonce" => Base64::encode64(nonce),
"ciphertext" => Base64::encode64(ciphertext),
"nonce" => Base64::strict_encode64(nonce),
"ciphertext" => Base64::strict_encode64(ciphertext),
})
end

Expand Down
8 changes: 4 additions & 4 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@
)

expect(MultiJson.decode(RbNaCl::SecretBox.new(key).decrypt(
Base64.decode64(data["nonce"]),
Base64.decode64(data["ciphertext"]),
Base64.strict_decode64(data["nonce"]),
Base64.strict_decode64(data["ciphertext"]),
))).to eq({ 'some' => 'data' })
}
end
Expand Down Expand Up @@ -461,8 +461,8 @@
)

expect(MultiJson.decode(RbNaCl::SecretBox.new(key).decrypt(
Base64.decode64(data["nonce"]),
Base64.decode64(data["ciphertext"]),
Base64.strict_decode64(data["nonce"]),
Base64.strict_decode64(data["ciphertext"]),
))).to eq({ 'some' => 'data' })

expect(batch[1]["channel"]).to eq("mychannel")
Expand Down

0 comments on commit 788f862

Please sign in to comment.