Properly close file descriptor
Use system sha1 library instead of local implementation.
Merge pull request #1 from kukackajiri/securityfixes

Merged fixes from Jiri Kukacka