Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode both smessage and signature in VerifyKey.verify() #256

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/nacl/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ def verify(self, smessage, signature=None, encoder=encoding.RawEncoder):
if signature is not None:
# If we were given the message and signature separately, combine
# them.
smessage = signature + smessage

# Decode the signed message
smessage = encoder.decode(smessage)
smessage = encoder.decode(signature) + encoder.decode(smessage)
else:
# Decode the signed message
smessage = encoder.decode(smessage)

return nacl.bindings.crypto_sign_open(smessage, self._key)

Expand Down
30 changes: 29 additions & 1 deletion tests/test_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from utils import assert_equal, assert_not_equal

from nacl.bindings import crypto_sign_PUBLICKEYBYTES, crypto_sign_SEEDBYTES
from nacl.encoding import HexEncoder
from nacl.encoding import Base64Encoder, HexEncoder
from nacl.exceptions import BadSignatureError
from nacl.signing import SignedMessage, SigningKey, VerifyKey

Expand Down Expand Up @@ -180,6 +180,34 @@ def test_invalid_signed_message(self):
forged = SignedMessage(signature + message)
skey.verify_key.verify(forged)

def test_both_verify_uses_are_equal_with_b64encoder(self):
sk = SigningKey.generate()
vk = sk.verify_key

smsg = sk.sign(b"Hello World", encoder=Base64Encoder)

msg = smsg.message
sig = smsg.signature

assert vk.verify(
msg, sig, encoder=Base64Encoder
) == vk.verify(
smsg, encoder=Base64Encoder)

def test_both_verify_uses_are_equal_with_hexencoder(self):
sk = SigningKey.generate()
vk = sk.verify_key

smsg = sk.sign(b"Hello World", encoder=HexEncoder)

msg = smsg.message
sig = smsg.signature

assert vk.verify(
msg, sig, encoder=HexEncoder
) == vk.verify(
smsg, encoder=HexEncoder)

def test_key_conversion(self):
keypair_seed = (b"421151a459faeade3d247115f94aedae"
b"42318124095afabe4d1451a559faedee")
Expand Down