Skip to content

Commit

Permalink
Switch to base32 library
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtj committed Mar 5, 2012
1 parent 4161a70 commit 5715d8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
6 changes: 5 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
{cover_print_enabled, true}.
{edoc_opts, [{overview, "priv/overview.edoc"}, {def, []}, {dir, "doc"}]}.
{erl_opts, [warnings_as_errors]}.
{deps, [{sha2, ".*", {git, "https://github.com/andrewtj/sha2_erlang.git", "master"}}]}.
{deps, [{sha2, ".*",
{git, "https://github.com/andrewtj/sha2_erlang.git", "master"}},
{base32, ".*",
{git, "https://github.com/andrewtj/base32_erlang.git", "master"}}
]}.
{eunit_opts, [verbose]}.
15 changes: 1 addition & 14 deletions src/dnssec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
-export([add_keytag_to_dnskey/1]).
-export([canonical_rrdata_form/1]).
-export([ih/4]).
-export([base32hex_encode/1]).

-include("dns.hrl").
-include("DNS-ASN1.hrl").
Expand Down Expand Up @@ -147,7 +146,7 @@ gen_nsec3(RRs, ZoneName, Alg, Salt, Iterations, TTL, Class, Opts) ->
fun({{Name, SClass}, Types}, Acc) when SClass =:= Class ->
DName = dns:encode_dname(Name),
HashedName = ih(Alg, Salt, DName, Iterations),
HexdHashName = base32hex_encode(HashedName),
HexdHashName = base32:encode(HashedName, [hex,nopad]),
NewName = <<HexdHashName/binary, $., ZoneName/binary>>,
Data = #dns_rrdata_nsec3{hash_alg = Alg,
opt_out = false,
Expand Down Expand Up @@ -469,18 +468,6 @@ canonical_rrdata_form(#dns_rrdata_srv{target = Target} = Data) ->
Data#dns_rrdata_srv{target = dns:dname_to_lower(Target)};
canonical_rrdata_form(X) -> X.

%% @doc Base 32 hex encoding suitable for generating NSEC3 labels.
-spec base32hex_encode(binary()) -> dns:label().
base32hex_encode(Bin) when bit_size(Bin) rem 5 =/= 0 ->
PadBy = 5 - (byte_size(Bin) rem 5),
base32hex_encode(<<Bin/bitstring, 0:PadBy>>);
base32hex_encode(Bin) when bit_size(Bin) rem 5 =:= 0 ->
<< <<(base32hex_encode_i(I))>> || <<I:5>> <= Bin >>.
base32hex_encode_i(Int)
when is_integer(Int) andalso Int >= 0 andalso Int =< 9 -> Int + 48;
base32hex_encode_i(Int)
when is_integer(Int) andalso Int >= 10 andalso Int =< 31 -> Int + 87.

name_ancestors(Name, ZoneName) ->
NameLwr = dns:dname_to_lower(iolist_to_binary(Name)),
ZoneNameLwr = dns:dname_to_lower(iolist_to_binary(ZoneName)),
Expand Down

0 comments on commit 5715d8c

Please sign in to comment.