You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
847 B
24 lines
847 B
5 years ago
|
#!/usr/bin/env python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
import hashlib
|
||
|
from Naked.toolshed.file import FileReader
|
||
|
|
||
|
# ------------------------------------------------------------------------------
|
||
|
# PUBLIC
|
||
|
# ------------------------------------------------------------------------------
|
||
|
def generate_hash(filepath):
|
||
|
"""Public function that reads a local file and generates a SHA256 hash digest for it"""
|
||
|
fr = FileReader(filepath)
|
||
|
data = fr.read_bin()
|
||
|
return _calculate_sha256(data)
|
||
|
|
||
|
|
||
|
# ------------------------------------------------------------------------------
|
||
|
# PRIVATE
|
||
|
# ------------------------------------------------------------------------------
|
||
|
def _calculate_sha256(binary_string):
|
||
|
"""Private function that calculates a SHA256 hash digest for a binary string argument"""
|
||
|
return hashlib.sha256(binary_string).hexdigest()
|
||
|
|