From 875db89d1893ca30e4989f856dc8046773ba9783 Mon Sep 17 00:00:00 2001 From: facelessuser Date: Sat, 17 May 2014 15:47:39 -0600 Subject: [PATCH] - Lint fixes --- hex_checksum.py | 30 +++++++++---------- hex_common.py | 12 ++++---- hex_editor.py | 42 +++++++++++++-------------- hex_finder.py | 6 ++-- hex_highlighter.py | 26 ++++++++--------- hex_inspector.py | 14 ++++----- hex_viewer.py | 26 ++++++++--------- hex_writer.py | 5 ++-- tiger.py | 16 +++++------ whirlpool.py | 72 +++++++++++++++++++++++----------------------- 10 files changed, 123 insertions(+), 126 deletions(-) diff --git a/hex_checksum.py b/hex_checksum.py index 77d1083..924f5bb 100755 --- a/hex_checksum.py +++ b/hex_checksum.py @@ -60,16 +60,16 @@ def algorithm(self, name, digest_size, arg): self.update(arg) def copy(self): - return None if self.__algorithm == None else self.__algorithm.copy() + return None if self.__algorithm is None else self.__algorithm.copy() def digest(self): - return None if self.__algorithm == None else self.__algorithm.digest() + return None if self.__algorithm is None else self.__algorithm.digest() def hexdigest(self): - return None if self.__algorithm == None else self.__algorithm.hexdigest() + return None if self.__algorithm is None else self.__algorithm.hexdigest() def update(self, arg): - if self.__algorithm != None: + if self.__algorithm is not None: self.__algorithm.update(arg) @@ -98,13 +98,13 @@ def copy(self): return self def digest(self): - return None if self.__algorithm == None else self.__hash & 0xffffffff + return None if self.__algorithm is None else self.__hash & 0xffffffff def hexdigest(self): - return None if self.__algorithm == None else '%08x' % (self.digest()) + return None if self.__algorithm is None else '%08x' % (self.digest()) def update(self, arg): - if self.__algorithm != None: + if self.__algorithm is not None: self.__hash = self.__algorithm(arg, self.__hash) @@ -149,9 +149,9 @@ class checksum(object): thread = None def __init__(self, hash_algorithm=None, data=b""): - if hash_algorithm == None or not hash_algorithm in VALID_HASH: + if hash_algorithm is None or hash_algorithm not in VALID_HASH: hash_algorithm = hv_settings("hash_algorithm", DEFAULT_CHECKSUM) - if not hash_algorithm in VALID_HASH: + if hash_algorithm not in VALID_HASH: hash_algorithm = DEFAULT_CHECKSUM self.hash = getattr(hashlib, hash_algorithm)(data) self.name = hash_algorithm @@ -175,7 +175,7 @@ def chunk_thread(self): message = "[" + "-" * percent + ">" + "-" * leftover + ("] %3d%%" % int(ratio * 100)) + " chunks hashed" sublime.status_message(message) if not self.thread.is_alive(): - if self.thread.abort == True: + if self.thread.abort is True: sublime.status_message("Hash calculation aborted!") sublime.set_timeout(lambda: self.reset_thread(), 500) else: @@ -187,7 +187,7 @@ def reset_thread(self): self.thread = None def display(self, window=None): - if window == None: + if window is None: window = sublime.active_window() window.show_input_panel(self.name + ":", str(self.hash.hexdigest()), None, None, None) @@ -217,7 +217,7 @@ class HashSelectionCommand(sublime_plugin.WindowCommand): def has_selections(self): single = False view = self.window.active_view() - if view != None: + if view is not None: if len(view.sel()) > 0: single = True return single @@ -274,7 +274,7 @@ def is_enabled(self): def run(self, hash_algorithm=None, panel=False): global active_thread - if active_thread != None and active_thread.thread != None and active_thread.thread.is_alive(): + if active_thread is not None and active_thread.thread is not None and active_thread.thread.is_alive(): active_thread.thread.abort = True else: if not panel: @@ -288,7 +288,7 @@ def select_checksum(self, value): def get_checksum(self, hash_algorithm=None): view = self.window.active_view() - if view != None: + if view is not None: sublime.set_timeout(lambda: sublime.status_message("Checksumming..."), 0) hex_hash = checksum(hash_algorithm) r_buffer = view.split_by_newlines(sublime.Region(0, view.size())) @@ -315,7 +315,7 @@ def get_checksum(self, hash_algorithm=None): ] ) -#Define extra hash classes as members of hashlib +# Define extra hash classes as members of hashlib hashlib.md2 = md2 hashlib.mdc2 = mdc2 hashlib.md4 = md4 diff --git a/hex_common.py b/hex_common.py index e62893d..b9df32a 100755 --- a/hex_common.py +++ b/hex_common.py @@ -14,17 +14,17 @@ def is_enabled(current_view=None): window = sublime.active_window() - if window == None: + if window is None: return False view = window.active_view() - if view == None: + if view is None: return False # Check not only if active main view is hex, # check if current view is the main active view - if current_view != None and current_view.id() != view.id(): + if current_view is not None and current_view.id() != view.id(): return False syntax = view.settings().get('syntax') - language = basename(syntax).replace('.tmLanguage', '').lower() if syntax != None else "plain text" + language = basename(syntax).replace('.tmLanguage', '').lower() if syntax is not None else "plain text" return bool(language == "hex") @@ -71,7 +71,7 @@ def adjust_hex_sel(view, start, end, group_size): else: start = None # Adjust ending of selection to end of last selected byte - if size == 0 and start != None: + if size == 0 and start is not None: end = start + 1 bytes = 1 elif view.score_selector(end, 'raw.nibble.lower') == 0: @@ -79,7 +79,7 @@ def adjust_hex_sel(view, start, end, group_size): end -= 1 else: end -= 2 - if start != None and end != None: + if start is not None and end is not None: bytes = get_byte_count(start, end, group_size) return start, end, bytes diff --git a/hex_editor.py b/hex_editor.py index 0fcc5be..36ff0aa 100755 --- a/hex_editor.py +++ b/hex_editor.py @@ -39,9 +39,9 @@ class HexEditorListenerCommand(sublime_plugin.EventListener): def restore(self, value): window = sublime.active_window() view = None - if value.strip().lower() == "yes" and self.fail_safe_view != None: + if value.strip().lower() == "yes" and self.fail_safe_view is not None: # Quit if cannot find window - if window == None: + if window is None: self.reset() return @@ -52,11 +52,11 @@ def restore(self, value): view = v # Reset handshake so view won't be closed self.handshake = -1 - if view == None: + if view is None: view = window.new_file() # Restore view - if view != None: + if view is not None: # Get highlight settings highlight_scope = hv_settings("highlight_edit_scope", HIGHLIGHT_EDIT_SCOPE) highlight_icon = hv_settings("highlight_edit_icon", HIGHLIGHT_EDIT_ICON) @@ -104,7 +104,7 @@ def restore(self, value): def reset(self): window = sublime.active_window() - if window != None and self.handshake != -1: + if window is not None and self.handshake != -1: for v in window.views(): if self.handshake == v.id(): window.focus_view(v) @@ -117,11 +117,11 @@ def on_close(self, view): window = sublime.active_window() file_name = file_name = view.settings().get("hex_viewer_file_name") - if window != None and file_name != None: + if window is not None and file_name is not None: # Save hex view settings self.fail_safe_view = { "buffer": view.substr(sublime.Region(0, view.size())), - "bits": view.settings().get("hex_viewer_bits"), + "bits": view.settings().get("hex_viewer_bits"), "bytes": view.settings().get("hex_viewer_bytes"), "actual": view.settings().get("hex_viewer_actual_bytes"), "name": file_name, @@ -139,7 +139,7 @@ def on_close(self, view): count += 1 if count == 1: view = sublime.active_window().new_file() - if view != None: + if view is not None: self.handshake = view.id() # Alert user that they can restore @@ -191,8 +191,8 @@ def init(self): # Get Seetings from settings file group_size = self.view.settings().get("hex_viewer_bits", None) self.bytes_wide = self.view.settings().get("hex_viewer_actual_bytes", None) - #Process hex grouping - if group_size != None and self.bytes_wide != None: + # Process hex grouping + if group_size is not None and self.bytes_wide is not None: self.group_size = group_size / BITS_PER_BYTE init_status = True return init_status @@ -210,7 +210,7 @@ def apply_edit(self, value): selection = self.line["selection"].replace(" ", "") # Transform string if provided - if re.match("^s\:", value) != None: + if re.match("^s\:", value) is not None: edits = hexlify(value[2:len(value)].encode("ascii")).decode("ascii") else: edits = value.replace(" ", "").lower() @@ -219,7 +219,7 @@ def apply_edit(self, value): if len(edits) != total_chars: self.edit_panel(value, "Unexpected # of bytes!") return - elif re.match("[\da-f]{" + str(total_chars) + "}", edits) == None: + elif re.match("[\da-f]{" + str(total_chars) + "}", edits) is None: self.edit_panel(value, "Invalid data!") return elif selection != edits: @@ -247,7 +247,7 @@ def apply_edit(self, value): # Diff data and mark changed bytes if value != original[start:byte_end]: - if change_start == None: + if change_start is None: change_start = [hex_start_pos, ascii_start_pos] # Check if group end if count == self.group_size: @@ -255,18 +255,18 @@ def apply_edit(self, value): change_start[0] = None else: # Check if after group end - if change_start[0] == None: + if change_start[0] is None: change_start[0] = hex_start_pos # Check if group end if count == self.group_size: regions.append(sublime.Region(change_start[0], hex_start_pos + 2)) change_start[0] = None - elif change_start != None: + elif change_start is not None: if self.view.score_selector(hex_start_pos - 1, 'raw.nibble.lower'): - if change_start[0] != None: + if change_start[0] is not None: regions.append(sublime.Region(change_start[0], hex_start_pos)) else: - if change_start[0] != None: + if change_start[0] is not None: regions.append(sublime.Region(change_start[0], hex_start_pos - 1)) regions.append(sublime.Region(change_start[1], ascii_start_pos)) change_start = None @@ -287,8 +287,8 @@ def apply_edit(self, value): ascii_start_pos += 1 # Check for end of line case for highlight - if change_start != None: - if change_start[0] != None: + if change_start is not None: + if change_start[0] is not None: regions.append(sublime.Region(change_start[0], hex_start_pos)) regions.append(sublime.Region(change_start[1], ascii_start_pos)) change_start = None @@ -351,7 +351,7 @@ def ascii_to_hex(self, start, end): hex_pos = self.view.text_point(row, column) start = hex_pos - # Traverse row finding the specified bytes + # Traverse row finding the specified bytes byte_count = bytes while byte_count: # Byte rising edge @@ -366,7 +366,7 @@ def ascii_to_hex(self, start, end): return start, end, bytes def edit_panel(self, value, error=None): - msg = "Edit:" if error == None else "Edit (" + error + "):" + msg = "Edit:" if error is None else "Edit (" + error + "):" self.window.show_input_panel( msg, value, diff --git a/hex_finder.py b/hex_finder.py index 2177940..bd56146 100755 --- a/hex_finder.py +++ b/hex_finder.py @@ -13,14 +13,14 @@ class HexFinderCommand(sublime_plugin.WindowCommand): handshake = -1 def go_to_address(self, address): - #init + # init view = self.window.active_view() if self.handshake != -1 and self.handshake == view.id(): # Adress offset for line group_size = view.settings().get("hex_viewer_bits", None) bytes_wide = view.settings().get("hex_viewer_actual_bytes", None) - if group_size == None and bytes_wide == None: + if group_size is None and bytes_wide is None: return group_size = group_size / BITS_PER_BYTE @@ -60,7 +60,7 @@ def is_enabled(self): return is_enabled() def run(self): - # Identify view + # Identify view view = self.window.active_view() if self.handshake != -1 and self.handshake == view.id(): self.reset() diff --git a/hex_highlighter.py b/hex_highlighter.py index 7b2cd51..8a707a5 100755 --- a/hex_highlighter.py +++ b/hex_highlighter.py @@ -80,8 +80,8 @@ def init(self): elif style == "underline": self.highlight_style = sublime.DRAW_EMPTY_AS_OVERWRITE - #Process hex grouping - if group_size != None and self.bytes_wide != None: + # Process hex grouping + if group_size is not None and self.bytes_wide is not None: self.group_size = group_size / BITS_PER_BYTE self.hex_char_range = get_hex_char_range(self.group_size, self.bytes_wide) init_status = True @@ -144,7 +144,7 @@ def hex_selection(self, start, bytes, first_pos): if self.first_all == -1: self.first_all = hex_pos - # Traverse row finding the specified bytes + # Traverse row finding the specified bytes highlight_start = -1 byte_count = bytes while byte_count: @@ -175,13 +175,13 @@ def ascii_to_hex(self, sel): # Determine if selection is within ascii range if ( - start >= ascii_range.begin() and - ( - # Single selection should ignore the end of line selection - (end == start and end < ascii_range.end() - 1) or - (end != start and end < ascii_range.end()) - ) - ): + start >= ascii_range.begin() and + ( + # Single selection should ignore the end of line selection + (end == start and end < ascii_range.end() - 1) or + (end != start and end < ascii_range.end()) + ) + ): # Single char selection if sel.size() == 0: bytes = 1 @@ -238,7 +238,7 @@ def get_highlights(self): self.hex_to_ascii(sel) def run(self, window): - if window == None: + if window is None: return self.window = window view = self.window.active_view() @@ -309,7 +309,7 @@ def hh_run(): # be ignored and then accounted for with one match by this thread def hh_loop(): while not HhThreadMgr.restart: - if Pref.modified == True and time() - Pref.time > Pref.wait_time: + if Pref.modified is True and time() - Pref.time > Pref.wait_time: sublime.set_timeout(lambda: hh_run(), 0) sleep(0.5) @@ -322,7 +322,7 @@ def plugin_loaded(): global hh_highlight hh_highlight = HexHighlighter().run - if not 'running_hh_loop' in globals(): + if 'running_hh_loop' not in globals(): global running_hh_loop running_hh_loop = True thread.start_new_thread(hh_loop, ()) diff --git a/hex_inspector.py b/hex_inspector.py index 947ecd4..1b7c447 100755 --- a/hex_inspector.py +++ b/hex_inspector.py @@ -120,7 +120,7 @@ def display(self, view, byte8, bytes16, bytes32, bytes64): nl = "\n" endian = ">" if self.endian == "big" else "<" i_buffer = "%28s:%-28s" % ("Hex Inspector ", (" Big Endian" if self.endian == "big" else " Little Endian")) + nl - if byte8 != None: + if byte8 is not None: i_buffer += item_dec * 2 % ( "byte", unpack(endian + "B", unhexlify(byte8))[0], "short", unpack(endian + "b", unhexlify(byte8))[0] @@ -130,7 +130,7 @@ def display(self, view, byte8, bytes16, bytes32, bytes64): "byte", "--", "short", "--" ) + nl - if bytes16 != None: + if bytes16 is not None: i_buffer += item_dec * 2 % ( "word", unpack(endian + "H", unhexlify(bytes16))[0], "int", unpack(endian + "h", unhexlify(bytes16))[0] @@ -140,7 +140,7 @@ def display(self, view, byte8, bytes16, bytes32, bytes64): "word", "--", "int", "--" ) + nl - if bytes32 != None: + if bytes32 is not None: i_buffer += item_dec * 2 % ( "dword", unpack(endian + "I", unhexlify(bytes32))[0], "longint", unpack(endian + "i", unhexlify(bytes32))[0] @@ -150,7 +150,7 @@ def display(self, view, byte8, bytes16, bytes32, bytes64): "dword", "--", "longint", "--" ) + nl - if bytes32 != None: + if bytes32 is not None: s_float = unpack(endian + "f", unhexlify(bytes32))[0] if math.isnan(s_float): i_buffer += item_str % ("float", "NaN") @@ -160,7 +160,7 @@ def display(self, view, byte8, bytes16, bytes32, bytes64): ) else: i_buffer += item_str % ("float", "--") - if bytes64 != None: + if bytes64 is not None: d_float = unpack(endian + "d", unhexlify(bytes64))[0] if math.isnan(d_float): i_buffer += item_str % ("double", "NaN") + nl @@ -170,7 +170,7 @@ def display(self, view, byte8, bytes16, bytes32, bytes64): ) + nl else: i_buffer += item_str % ("double", "--") + nl - if byte8 != None: + if byte8 is not None: i_buffer += item_bin % ("binary", '{0:08b}'.format(unpack(endian + "B", unhexlify(byte8))[0])) + nl else: i_buffer += item_str % ("binary", "--") + nl @@ -191,7 +191,7 @@ def run(self, first_byte=None, bytes_wide=None, reset=False): self.view = self.window.active_view() self.endian = hv_endianness byte8, bytes16, bytes32, bytes64 = None, None, None, None - if not reset and first_byte != None and bytes_wide != None: + if not reset and first_byte is not None and bytes_wide is not None: byte8, bytes16, bytes32, bytes64 = self.get_bytes(int(first_byte), int(bytes_wide)) self.display(self.window.get_output_panel('hex_viewer_inspector'), byte8, bytes16, bytes32, bytes64) diff --git a/hex_viewer.py b/hex_viewer.py index 12ae449..979d61d 100755 --- a/hex_viewer.py +++ b/hex_viewer.py @@ -132,13 +132,13 @@ def is_bin_file(self, file_path): def open_bin_file(self, view=None, window=None): open_now = False - if view != None and window != None: + if view is not None and window is not None: # Direct open file open_now = True else: # Preview view of file window = sublime.active_window() - if window != None: + if window is not None: view = window.active_view() # Open bin file in hex viewer if window and view and (open_now or view.file_name() == self.open_me): @@ -151,7 +151,7 @@ def open_bin_file(self, view=None, window=None): def auto_load(self, view, window, is_preview): file_name = view.file_name() # Make sure we have a file name and that we haven't already processed the view - if file_name != None and not view.settings().get("hex_no_auto_open", False): + if file_name is not None and not view.settings().get("hex_no_auto_open", False): # Make sure the file is specified in our binary file list if self.is_bin_file(file_name): # Handle previw or direct open @@ -222,12 +222,12 @@ def set_format(self): def buffer_init(self, bits, bytearray): self.view = self.window.active_view() file_name = None - if self.view != None: + if self.view is not None: # Get font settings self.font = hv_settings('custom_font', 'None') self.font_size = hv_settings('custom_font_size', 0) - #Get file name + # Get file name file_name = self.view.settings().get("hex_viewer_file_name", self.view.file_name()) # Get current bit and byte settings from view @@ -242,8 +242,8 @@ def buffer_init(self, bits, bytearray): hv_settings('bytes_per_line', DEFAULT_BYTES_WIDE) ) # Use passed in bit and byte settings if available - self.bits = bits if bits != None else int(current_bits) - self.bytes = bytearray if bytearray != None else int(current_bytes) + self.bits = bits if bits is not None else int(current_bits) + self.bytes = bytearray if bytearray is not None else int(current_bytes) self.set_format() return file_name @@ -309,7 +309,7 @@ def reset_thread(self): self.thread = None def handle_thread(self): - if self.abort == True: + if self.abort is True: self.thread.abort = True sublime.status_message("Hex View aborted!") sublime.set_timeout(lambda: self.reset_thread(), 500) @@ -360,7 +360,7 @@ def is_enabled(self): def run(self, bits=None, bytearray=None): # If thread is active cancel thread - if self.thread != None and self.thread.is_alive(): + if self.thread is not None and self.thread.is_alive(): self.abort_hex_load() return @@ -372,19 +372,19 @@ def run(self, bits=None, bytearray=None): self.reset() self.handshake = self.view.id() - if file_name != None: + if file_name is not None: # Decide whether to read in as a binary file or a traditional file if self.view.settings().has("hex_viewer_file_name"): self.view_type = "hex" if is_hex_dirty(self.view): self.file_name = file_name - if bits == None and bytearray == None: + if bits is None and bytearray is None: self.switch_type = "file" else: self.switch_type = "hex" self.discard_panel() else: - if bits == None and bytearray == None: + if bits is None and bytearray is None: # Switch back to traditional output self.read_file(file_name) else: @@ -420,7 +420,7 @@ def run(self, option): self.view = self.window.active_view() file_name = self.view.settings().get("hex_viewer_file_name", self.view.file_name()) self.valid_bytes = hv_settings("valid_bytes_per_line", VALID_BYTES) - if file_name != None: + if file_name is not None: if self.view.settings().has("hex_viewer_file_name"): option_list = [] if option == "bits": diff --git a/hex_writer.py b/hex_writer.py index b25b472..5d4044e 100755 --- a/hex_writer.py +++ b/hex_writer.py @@ -11,7 +11,6 @@ from HexViewer.hex_common import * from HexViewer.hex_checksum import checksum from binascii import unhexlify -import traceback USE_CHECKSUM_ON_SAVE = True @@ -72,9 +71,9 @@ def export(self): for line in r_buffer: hex_data = unhexlify(re.sub(r'[\da-z]{8}:[\s]{2}((?:[\da-z]+[\s]{1})*)\s*\:[\w\W]*', r'\1', self.view.substr(line)).replace(" ", "")) bin.write(hex_data) - if hex_hash != None: + if hex_hash is not None: h_buffer.append(hex_data) - if hex_hash != None: + if hex_hash is not None: # Checksum will be threaded and will show the result when done sublime.set_timeout(lambda: sublime.status_message("Checksumming..."), 0) hex_hash.threaded_update(h_buffer) diff --git a/tiger.py b/tiger.py index 036acad..033c2a0 100644 --- a/tiger.py +++ b/tiger.py @@ -15,9 +15,7 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -import array import struct -from binascii import hexlify BIG_ENDIAN = True @@ -628,7 +626,7 @@ def tiger_pass(a, b, c, mul, mystr): def tiger_compress(str, res): - #setup + # setup a = res[0] b = res[1] c = res[2] @@ -734,7 +732,7 @@ def tiger_finalize(tig): def test_tiger_hash(): # TODO: Re-generate hashes with default endian - #Tests + # Tests assert tiger('').hexdigest() == \ '24f0130c63ac933216166e76b1bb925ff373de2d49584e7a' assert tiger('abc').hexdigest() == \ @@ -748,22 +746,22 @@ def test_tiger_hash(): assert tiger("Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham").hexdigest() == \ '0c410a042968868a1671da5a3fd29a725ec1e457d3cdb303' assert tiger( - "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, " \ + "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, " "proceedings of Fast Software Encryption 3, Cambridge." ).hexdigest() == \ 'ebf591d5afa655ce7f22894ff87f54ac89c811b6b0da3193' assert tiger( - "Tiger - A Fast New Hash Function, by Ross Anderson and" \ + "Tiger - A Fast New Hash Function, by Ross Anderson and" " Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996." ).hexdigest() == \ '3d9aeb03d1bd1a6357b2774dfd6d5b24dd68151d503974fc' assert tiger( - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01" \ - "23456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345" \ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01" + "23456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345" "6789+-" ).hexdigest() == \ '00b83eb4e53440c576ac6aaee0a7485825fd15e70a59ffe4' - #Chunked + # Chunked test = tiger('The quick brown fox jumps over the lazy dog') test.update('The quick brown fox jumps over the lazy dog') test.update('The quick brown fox jumps over the lazy dog') diff --git a/whirlpool.py b/whirlpool.py index f6bd51f..bd633c8 100644 --- a/whirlpool.py +++ b/whirlpool.py @@ -1,29 +1,29 @@ -## whirlpool.py - pure Python implementation of the Whirlpool algorithm. -## Bjorn Edstrom 16 december 2007. -## -## Copyrights -## ========== -## -## This code is based on the reference implementation by -## Paulo S.L.M. Barreto and Vincent Rijmen. The reference implementation -## is placed in the public domain but has the following headers: -## -## * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS -## * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -## * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -## * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE -## * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -## * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -## * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -## * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -## * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -## * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -## * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -## * -## */ -## /* The code contained in this file (Whirlpool.c) is in the public domain. */ -## -## This Python implementation is therefore also placed in the public domain. +# whirlpool.py - pure Python implementation of the Whirlpool algorithm. +# Bjorn Edstrom 16 december 2007. +# +# Copyrights +# ========== +# +# This code is based on the reference implementation by +# Paulo S.L.M. Barreto and Vincent Rijmen. The reference implementation +# is placed in the public domain but has the following headers: +# +# * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS +# * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE +# * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +# * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# * +# */ +# /* The code contained in this file (Whirlpool.c) is in the public domain. */ +# +# This Python implementation is therefore also placed in the public domain. DIGESTBYTES = 64 DIGESTBITS = 512 @@ -35,7 +35,7 @@ class whirlpool(object): def __init__(self, arg=b''): self.ctx = WhirlpoolStruct() - if arg != b'' and arg != None: + if arg != b'' and arg is not None: self.update(arg) self.digest_status = 0 @@ -48,7 +48,7 @@ def digest_size(self): return self.__digest_size def update(self, arg): - if arg != b'' and arg != None: + if arg != b'' and arg is not None: WhirlpoolAdd(arg, len(arg) * 8, self.ctx) self.digest_status = 0 @@ -61,7 +61,7 @@ def digest(self): def hexdigest(self): digest = self.digest() - if digest == None: + if digest is None: return None hex_digest = '' for byte in digest: @@ -721,13 +721,13 @@ def WhirlpoolFinalize(ctx): def CDo(buf, a0, a1, a2, a3, a4, a5, a6, a7): return C0[((buf[a0] >> 56) % 0x100000000) & 0xff] ^ \ - C1[((buf[a1] >> 48) % 0x100000000) & 0xff] ^ \ - C2[((buf[a2] >> 40) % 0x100000000) & 0xff] ^ \ - C3[((buf[a3] >> 32) % 0x100000000) & 0xff] ^ \ - C4[((buf[a4] >> 24) % 0x100000000) & 0xff] ^ \ - C5[((buf[a5] >> 16) % 0x100000000) & 0xff] ^ \ - C6[((buf[a6] >> 8) % 0x100000000) & 0xff] ^ \ - C7[((buf[a7] >> 0) % 0x100000000) & 0xff] + C1[((buf[a1] >> 48) % 0x100000000) & 0xff] ^ \ + C2[((buf[a2] >> 40) % 0x100000000) & 0xff] ^ \ + C3[((buf[a3] >> 32) % 0x100000000) & 0xff] ^ \ + C4[((buf[a4] >> 24) % 0x100000000) & 0xff] ^ \ + C5[((buf[a5] >> 16) % 0x100000000) & 0xff] ^ \ + C6[((buf[a6] >> 8) % 0x100000000) & 0xff] ^ \ + C7[((buf[a7] >> 0) % 0x100000000) & 0xff] def processBuffer(ctx):