Skip to content

Commit

Permalink
0.19.1 fix hash funcs (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
scravy committed May 13, 2023
1 parent a7b61b8 commit c4db87d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion jinsi/__pkginfo__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.19.0"
version = "0.19.1"
24 changes: 12 additions & 12 deletions jinsi/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,28 @@ def implode(separator, items):
# hashes

@staticmethod
def md5(value):
return hashlib.new("md5", value).hexdigest()
def md5(value, charset='utf8'):
return hashlib.new("md5", value.encode(charset)).hexdigest()

@staticmethod
def sha1(value):
return hashlib.new("sha1", value).hexdigest()
def sha1(value, charset='utf8'):
return hashlib.new("sha1", value.encode(charset)).hexdigest()

@staticmethod
def sha256(value):
return hashlib.new("sha256", value).hexdigest()
def sha256(value, charset='utf8'):
return hashlib.new("sha256", value.encode(charset)).hexdigest()

@staticmethod
def sha512(value):
return hashlib.new("sha512", value).hexdigest()
def sha512(value, charset='utf8'):
return hashlib.new("sha512", value.encode(charset)).hexdigest()

@staticmethod
def sha3_256(value):
return hashlib.new("sha3_256", value).hexdigest()
def sha3_256(value, charset='utf8'):
return hashlib.new("sha3_256", value.encode(charset)).hexdigest()

@staticmethod
def sha3_512(value):
return hashlib.new("sha3_512", value).hexdigest()
def sha3_512(value, charset='utf8'):
return hashlib.new("sha3_512", value.encode(charset)).hexdigest()

# value tests

Expand Down
15 changes: 15 additions & 0 deletions tests/test_functions_integrated.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ def test_select_range_from_string(self):

self.check(expected, doc)

def test_sha256(self):
doc = """\
::let:
v: "value"
xs:
::sha256:
- ::get: v
"""

expected = {
'xs': 'cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619'
}

self.check(expected, doc)


if __name__ == '__main__':
unittest.main()

0 comments on commit c4db87d

Please sign in to comment.