Skip to content

Commit 92c8451

Browse files
committed
use strict base64 variants
1 parent c6759c4 commit 92c8451

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Unreleased
2+
==========
3+
4+
* Remove newline from end of base64 encoded strings, some decoders don't like
5+
them.
6+
17
1.4.2 / 2020-10-20
28
==================
39

lib/pusher/client.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def initialize(options = {})
5959

6060
if options.has_key?(:encryption_master_key_base64)
6161
@encryption_master_key =
62-
Base64.decode64(options[:encryption_master_key_base64])
62+
Base64.strict_decode64(options[:encryption_master_key_base64])
6363
end
6464

6565
@http_proxy = nil
@@ -148,7 +148,7 @@ def timeout=(value)
148148
# Set an encryption_master_key to use with private-encrypted channels from
149149
# a base64 encoded string.
150150
def encryption_master_key_base64=(s)
151-
@encryption_master_key = s ? Base64.decode64(s) : nil
151+
@encryption_master_key = s ? Base64.strict_decode64(s) : nil
152152
end
153153

154154
## INTERACT WITH THE API ##
@@ -483,8 +483,8 @@ def encrypt(channel_name, encoded_data)
483483
ciphertext = secret_box.encrypt(nonce, encoded_data)
484484

485485
MultiJson.encode({
486-
"nonce" => Base64::encode64(nonce),
487-
"ciphertext" => Base64::encode64(ciphertext),
486+
"nonce" => Base64::strict_encode64(nonce),
487+
"ciphertext" => Base64::strict_encode64(ciphertext),
488488
})
489489
end
490490

spec/client_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@
385385
)
386386

387387
expect(MultiJson.decode(RbNaCl::SecretBox.new(key).decrypt(
388-
Base64.decode64(data["nonce"]),
389-
Base64.decode64(data["ciphertext"]),
388+
Base64.strict_decode64(data["nonce"]),
389+
Base64.strict_decode64(data["ciphertext"]),
390390
))).to eq({ 'some' => 'data' })
391391
}
392392
end
@@ -461,8 +461,8 @@
461461
)
462462

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

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

0 commit comments

Comments
 (0)