File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 55More information: https://github.com/jlevy/strif
66"""
77
8+ import base64
89import hashlib
910import os
1011import random
@@ -191,7 +192,11 @@ class Hash:
191192 Base 36 format is good for short, friendly identifiers. Length of a SHA1 hash
192193 in base36 is ~32 chars.
193194
194- Example:
195+ Examples:
196+ hash_string("foo").value
197+ -> b'\n \n \x9f *gr\x94 %W\xab SU\xd7 j\xf4 B\xf8 \xf6 ^\x01 '
198+ hash_string("foo").base64
199+ -> 'CgqfKmdylCVXq1NV12r0Qvj2XgE='
195200 hash_string("foo").base36
196201 -> '1e6gpc3ehk0mu2jqu8cg42g009s796b'
197202 """
@@ -203,6 +208,10 @@ class Hash:
203208 def hex (self ) -> str :
204209 return self .value .hex ()
205210
211+ @property
212+ def base64 (self ) -> str :
213+ return base64 .b64encode (self .value ).decode ("utf-8" )
214+
206215 @property
207216 def base36 (self ) -> str :
208217 return base36_encode (int .from_bytes (self .value , byteorder = "big" ))
Original file line number Diff line number Diff line change 11import os
22
3- from strif import hash_file
3+ from strif import hash_file , hash_string
44
55
66def test_hash_file ():
@@ -12,3 +12,7 @@ def test_hash_file():
1212
1313 result_hash = hash_file (file_path , "sha1" ).with_prefix
1414 assert result_hash == "sha1:0a0a9f2a6772942557ab5355d76af442f8f65e01"
15+
16+ assert hash_string ("Hello, World!" ).with_prefix == result_hash
17+
18+ assert hash_string ("Hello, World!" ).base64 == "CgqfKmdylCVXq1NV12r0Qvj2XgE="
You can’t perform that action at this time.
0 commit comments