Skip to content
Snippets Groups Projects
Commit 6eef06aa authored by Donald Stufft's avatar Donald Stufft
Browse files

Merge pull request #2 from dstufft/fix-strings-with-nulls

Properly handle strings with internal nul
parents 225976c1 ab404970
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ def sha256(message, binary=False):
digest = nacl.ffi.new("unsigned char[]", nacl.lib.crypto_hash_sha256_BYTES)
if not nacl.lib.crypto_hash_sha256(digest, message, len(message)):
raise CryptoError("Hashing failed")
digest = nacl.ffi.string(digest)
digest = nacl.ffi.buffer(digest, nacl.lib.crypto_hash_sha256_BYTES)[:]
if binary:
return digest
......@@ -19,7 +19,7 @@ def sha512(message, binary=False):
digest = nacl.ffi.new("unsigned char[]", nacl.lib.crypto_hash_sha512_BYTES)
if not nacl.lib.crypto_hash_sha512(digest, message, len(message)):
raise CryptoError("Hashing failed")
digest = nacl.ffi.string(digest)
digest = nacl.ffi.buffer(digest, nacl.lib.crypto_hash_sha512_BYTES)[:]
if binary:
return digest
......
......@@ -4,4 +4,4 @@ from . import nacl
def random(size=32):
data = nacl.ffi.new("unsigned char[]", size)
nacl.lib.randombytes(data, size)
return nacl.ffi.string(data)
return nacl.ffi.buffer(data, size)[:]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment