Skip to content

Commit

Permalink
fixes surname handling for RDNSequence (#46)
Browse files Browse the repository at this point in the history
* fixes surname handling for RDNSequence

surname used incosistent casing (:surName vs :surname) which led to
an error when providing a string with "SN=Doe" to RDNSequence.new for example.

Changes
- consistently use lowercase for the surname atom in RDNSequence.new_attr/1
- adds testcase to validate that a RDN Sequence with a provided "SN"
  returns without error in RDNSequenceTest

* improves testcase for RDNSequence surname

uses more meaningful and instructive values

Co-authored-by: Bram Verburg <[email protected]>

Co-authored-by: Bram Verburg <[email protected]>
  • Loading branch information
tofferoma and voltone authored Mar 1, 2022
1 parent 92ac8d5 commit cea3b97
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/x509/rdn_sequence.ex
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ defmodule X509.RDNSequence do
defp new_attr({"ST", value}), do: new_attr({:stateOrProvinceName, value})
defp new_attr({"CN", value}), do: new_attr({:commonName, value})
defp new_attr({"L", value}), do: new_attr({:localityName, value})
defp new_attr({"SN", value}), do: new_attr({:surName, value})
defp new_attr({"SN", value}), do: new_attr({:surname, value})
defp new_attr({"GN", value}), do: new_attr({:givenName, value})
defp new_attr({"DC", value}), do: new_attr({:domainComponent, value})
defp new_attr({"E", value}), do: new_attr({:emailAddress, value})
Expand Down
4 changes: 4 additions & 0 deletions test/x509/rdn_sequence_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ defmodule X509.RDNSequenceTest do
# the spec; OTP's :public_key does the same
assert {:rdnSequence, _} = X509.RDNSequence.new("/C=Germany/O=ACME GmbH")
end

test "surname" do
assert {:rdnSequence, _} = X509.RDNSequence.new("/SN=Erlang/GN=Agner Krarup")
end
end

0 comments on commit cea3b97

Please sign in to comment.