/bindings/Microsoft.NET/MHashDotNet384.Wrapper/obj
/bindings/Microsoft.NET/bin
/bindings/Microsoft.NET/ipch
-/bindings/Python/wrapper/bin
-/bindings/Python/wrapper/obj
+/bindings/Python/native/bin
+/bindings/Python/native/obj
/ipch
/obj
/out
del /Q /S /F "%~dp0\bindings\Java\%%i\*.*"
)
-for %%i in (wrapper\obj,wrapper\out) do (
+for %%i in (native\obj,native\out) do (
del /Q /S /F "%~dp0\bindings\Python\%%i\*.*"
)
set "MSVC_PROJECTS=MHashLib.sln"
set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Microsoft.NET\MHashDotNet384.sln"
set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Java\native\MHashJava384.sln"
-set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Python\wrapper\MHashPy384.sln"
+set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Python\native\MHashPy384_Native.sln"
for %%q in (%MSVC_PROJECTS%) do (
for %%p in (x86,x64) do (
"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_JNI_X86%" "%~dp0\bindings\Java\native\bin\x86\Release\MHashJava384.x86.dll" "%~dp0\bindings\Java\wrapper\out\MHashJava384-Wrapper.jar" "%~dp0\bindings\Java\example\out\MHashJava384-Example.jar" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_JNI_X64%" "%~dp0\bindings\Java\native\bin\x64\Release\MHashJava384.x64.dll" "%~dp0\bindings\Java\wrapper\out\MHashJava384-Wrapper.jar" "%~dp0\bindings\Java\example\out\MHashJava384-Example.jar" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X86%" "%~dp0\bindings\Python\wrapper\bin\x86\Release\MHashPy384_Impl.x86.pyd" "%~dp0\bindings\Python\include\MHashPy384.py" "%~dp0\bindings\Python\include\mhash.pth" "%~dp0\bindings\Python\example\Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
-"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X64%" "%~dp0\bindings\Python\wrapper\bin\x64\Release\MHashPy384_Impl.x64.pyd" "%~dp0\bindings\Python\include\MHashPy384.py" "%~dp0\bindings\Python\include\mhash.pth" "%~dp0\bindings\Python\example\Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X86%" "%~dp0\bindings\Python\native\bin\x86\Release\MHashPy384_Native.x86.pyd" "%~dp0\bindings\Python\wrapper\MHashPy384_Wrapper.py" "%~dp0\bindings\Python\wrapper\mhash.pth" "%~dp0\bindings\Python\example\Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
+"%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X64%" "%~dp0\bindings\Python\native\bin\x64\Release\MHashPy384_Native.x64.pyd" "%~dp0\bindings\Python\wrapper\MHashPy384_Wrapper.py" "%~dp0\bindings\Python\wrapper\mhash.pth" "%~dp0\bindings\Python\example\Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
"%GIT2_PATH%\git.exe" archive --format tar.gz -9 --verbose --output "%OUT_PATH_SRC_GEN%" HEAD
import sys
import binascii
-
-from MHashPy384 import MHash384
+from MHashPy384_Wrapper import MHash384
def read_chunks(fs, chunk_size=4096):
while True:
break
yield data
-def main():
+def main(argv):
+ if(len(argv) < 1):
+ print("Command-line argument is missing!")
+ return
with MHash384() as digest:
- with open('E:\\ViDeOz\\Helges gitarrensolo in Texas.mp4', 'rb') as fs:
+ with open(argv[0], 'rb') as fs:
for chunk in read_chunks(fs):
digest.update(chunk)
print(binascii.hexlify(digest.result()))
if __name__ == "__main__":
- main()
+ main(sys.argv[1:])
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MHashPy384", "MHashPy384.vcxproj", "{98971AF0-1B4D-4B5A-A174-9B099F7977B8}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MHashPy384_Native", "MHashPy384_Native.vcxproj", "{98971AF0-1B4D-4B5A-A174-9B099F7977B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
<PropertyGroup Label="Globals">
<ProjectGuid>{98971AF0-1B4D-4B5A-A174-9B099F7977B8}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
- <RootNamespace>MHashPy384_Impl</RootNamespace>
+ <RootNamespace>MHashPy384_Native</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
- <ProjectName>MHashPy384_Impl</ProjectName>
+ <ProjectName>MHashPy384_Native</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
static PyObject *MHashPy384_Update(PyObject *const self, PyObject *const args)
{
- PyObject *instance = NULL, *data = NULL;
- if (PyArg_UnpackTuple(args, "MHash384_Update", 2, 2, &instance, &data))
+ PyObject *instance = NULL, *data = NULL, *offset = NULL, *len = NULL;
+ if (PyArg_UnpackTuple(args, "MHash384_Update", 2, 4, &instance, &data, &offset, &len))
{
if (PyLong_Check(instance) && PyBytes_Check(data))
{
void *const inst_ptr = PyLong_AsVoidPtr(instance);
if (inst_ptr)
{
- reinterpret_cast<mhash::MHash384*>(inst_ptr)->update(reinterpret_cast<uint8_t*>(PyBytes_AsString(data)), PyBytes_Size(data));
- Py_RETURN_TRUE;
+ const size_t total_size = PyBytes_Size(data);
+ const size_t offset_val = offset ? PyLong_AsSize_t(offset) : 0U;
+ if (offset_val < total_size)
+ {
+ const size_t len_val = len ? PyLong_AsSize_t(len) : (total_size - offset_val);
+ const size_t sum = offset_val + len_val;
+ if ((sum >= offset_val) && (sum >= len_val) && (sum < total_size))
+ {
+ reinterpret_cast<mhash::MHash384*>(inst_ptr)->update(reinterpret_cast<uint8_t*>(PyBytes_AsString(data)) + offset_val, len_val);
+ Py_RETURN_TRUE;
+ }
+ }
}
}
}
static struct PyModuleDef MHash384_ModuleDef =
{
- PyModuleDef_HEAD_INIT, "MHashPy384_Impl", "", -1, MHashPy384_Methods
+ PyModuleDef_HEAD_INIT, "MHashPy384_Native", "", -1, MHashPy384_Methods
};
PyMODINIT_FUNC
-PyInit_MHashPy384_Impl(void)
+PyInit_MHashPy384_Native(void)
{
return PyModule_Create(&MHash384_ModuleDef);
}
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
##################################################################################################
-import MHashPy384_Impl as impl
+import MHashPy384_Native as native
class MHash384:
def __init__(self):
self.__handle = None
def __enter__(self):
- self.__handle = impl.create()
+ self.__handle = native.create()
return self
def update(self, data):
- impl.update(self.__handle, data)
+ native.update(self.__handle, data)
def result(self):
- return impl.result(self.__handle)
+ return native.result(self.__handle)
def __exit__(self, type, value, traceback):
- impl.freeup(self.__handle)
+ native.freeup(self.__handle)