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

IH-524 Bugfix, validate sign with whitespaces #4

Merged
merged 2 commits into from
Feb 23, 2018
Merged
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
2 changes: 1 addition & 1 deletion lib/hm_crypto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule HmCrypto do
def valid?(message, encoded_signature, digest_type \\ @default_digest_type,
public_key \\ @default_public_key)
when is_binary(message) do
case Base.decode64(encoded_signature) do
case Base.decode64(encoded_signature, ignore: :whitespace) do
{:ok, signature} ->
:public_key.verify(message, digest_type, signature, parse_pem(public_key))
_ -> false
Expand Down
Empty file added mix.lock
Empty file.
14 changes: 14 additions & 0 deletions test/hm_crypto_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@ defmodule HmCryptoTest do
test "HmCrypto.valid? returns false when signature is not base64 string" do
assert false == HmCrypto.valid?("message", "not base64 string")
end

test "should be able to validate signature with whitespaces" do
signature =
"""
sJqzygg4bBVOBs216w8yJLvlG3aazM59cFKujqxIJEbh4FiFbUKfEPtaUSNa
YPJGHILAo1+Bdro1m6O1lVSsNdZU2zfUtZFKeRSiTE2em6KorbfqsZ0wsyGN
FXMptaidpCTpCAl2jWsD5T6yaamU7Da9LS4lGUaFe55GONmdgH7T3QYUS5vD
hM2l2Az6J9B62zKOX/PVMBAeEDuyW/4bUlQuuOxlG2jScpA2z/uQi5EiTyJ+
4rRnUfiM5ifdzCAgLrhCJu/5mD9IkceQJyrKHZbjb+5Q/KQ6FTCj0+imiv0A
a7YyDyA28uMSR2PhwfhNuASBgy/vX6k2s71I4sWVWA==
"""

assert true == HmCrypto.valid?("message", signature)
end
end