comparison sat/memory/crypto.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents be6d91572633
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
45 @param leave_empty (bool): if True, empty text will be returned "as is" 45 @param leave_empty (bool): if True, empty text will be returned "as is"
46 @return (D(str)): base-64 encoded encrypted message 46 @return (D(str)): base-64 encoded encrypted message
47 """ 47 """
48 if leave_empty and text == "": 48 if leave_empty and text == "":
49 return "" 49 return ""
50 iv = BlockCipher.getRandomKey() 50 iv = BlockCipher.get_random_key()
51 key = key.encode() 51 key = key.encode()
52 key = ( 52 key = (
53 key[: BlockCipher.MAX_KEY_SIZE] 53 key[: BlockCipher.MAX_KEY_SIZE]
54 if len(key) >= BlockCipher.MAX_KEY_SIZE 54 if len(key) >= BlockCipher.MAX_KEY_SIZE
55 else BlockCipher.pad(key) 55 else BlockCipher.pad(key)
89 decryptor = cipher.decryptor() 89 decryptor = cipher.decryptor()
90 decrypted = decryptor.update(ciphertext) + decryptor.finalize() 90 decrypted = decryptor.update(ciphertext) + decryptor.finalize()
91 return BlockCipher.unpad(decrypted) 91 return BlockCipher.unpad(decrypted)
92 92
93 @staticmethod 93 @staticmethod
94 def getRandomKey(size=None, base64=False): 94 def get_random_key(size=None, base64=False):
95 """Return a random key suitable for block cipher encryption. 95 """Return a random key suitable for block cipher encryption.
96 96
97 Note: a good value for the key length is to make it as long as the block size. 97 Note: a good value for the key length is to make it as long as the block size.
98 98
99 @param size: key length in bytes, positive or null (default: BlockCipher.IV_SIZE) 99 @param size: key length in bytes, positive or null (default: BlockCipher.IV_SIZE)