Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Aug 12, 2024
1 parent ad3fd90 commit e98bb65
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/encrypted_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
message = f'crypto_module({type(config.crypto_module)})'

pubnub.publish().channel('example').message(message).sync()
print(f'published: {message}')
2 changes: 1 addition & 1 deletion pubnub/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def extract_random_iv(self, message, use_random_iv):

def get_initialization_vector(self, use_random_iv):
if self.pubnub_configuration.use_random_initialization_vector or use_random_iv:
return secrets.token_hex(16)[0:16]
return secrets.token_urlsafe(16)[:16]
else:
return Initial16bytes

Expand Down
3 changes: 1 addition & 2 deletions pubnub/crypto_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import hashlib
import json
import random
import secrets

from abc import abstractmethod
Expand Down Expand Up @@ -111,7 +110,7 @@ def extract_random_iv(self, message, use_random_iv):

def get_initialization_vector(self, use_random_iv) -> bytes:
if self.use_random_iv or use_random_iv:
return bytes("{0:016}".format(random.randint(0, 9999999999999999)), 'utf-8')
return secrets.token_bytes(16)
else:
return self.Initial16bytes

Expand Down
2 changes: 1 addition & 1 deletion pubnub/endpoints/pubsub/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def build_data(self):
stringified_message = utils.write_value_as_string(self._message)

if self.pubnub.config.crypto_module:
stringified_message = self.pubnub.config.crypto_module.encrypt(stringified_message)
stringified_message = '"' + self.pubnub.config.crypto_module.encrypt(stringified_message) + '"'
elif self.pubnub.config.cipher_key is not None: # The legacy way
stringified_message = '"' + self.pubnub.config.crypto.encrypt(
self.pubnub.config.cipher_key,
Expand Down

0 comments on commit e98bb65

Please sign in to comment.