From 92c845199f0e1f72d21550be8359be223b25ef63 Mon Sep 17 00:00:00 2001 From: Callum Oakley Date: Wed, 28 Oct 2020 12:00:03 +0000 Subject: [PATCH] use strict base64 variants --- CHANGELOG.md | 6 ++++++ lib/pusher/client.rb | 8 ++++---- spec/client_spec.rb | 8 ++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88283af..43ba973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ================== diff --git a/lib/pusher/client.rb b/lib/pusher/client.rb index a2ae67d..fe76d7d 100644 --- a/lib/pusher/client.rb +++ b/lib/pusher/client.rb @@ -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 @@ -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 ## @@ -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 diff --git a/spec/client_spec.rb b/spec/client_spec.rb index be17aab..aeb1237 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -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 @@ -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")