Re: sha256 on files - different hashes

2016-10-15 Thread sky_khan
I think this ( below ) works but IMO this library should provide a way works on 
arrays, not strings. This is inefficient.


import nimSHA2, os, strutils

proc main(): string =
   const blockSize = 8192
   var bytesRead: int = 0
   var buffer: string
   
   var f: File = open("./file.bin")
   var sha: SHA256
   sha.initSHA()
   
   buffer = newString(blockSize)
   bytesRead = f.readBuffer(buffer[0].addr, blockSize)
   setLen(buffer,bytesRead)
   
   while bytesRead > 0:
 echo bytesRead
 sha.update(buffer)
 
 setLen(buffer,blockSize)
 bytesRead = f.readBuffer(buffer[0].addr, blockSize)
 setLen(buffer,bytesRead)
   
   let digest = sha.final()
   
   result = digest.hex()


when isMainModule:
  echo main()



Re: sha256 on files - different hashes

2016-10-15 Thread pyloor
Hi Stefan,

thanks for the hint. I will digg deeper to find the problem.