Skip to content
Browse files

add md5 based conf helpers

  • Loading branch information...
1 parent adf3b66 commit aa6707577191b7b359199fb2481bc6224e1acba5 @mojombo committed
Showing with 27 additions and 2 deletions.
  1. +11 −2 elibs/conf.erl
  2. +16 −0 elibs/md5.erl
View
13 elibs/conf.erl
@@ -1,5 +1,6 @@
-module(conf).
--export([read_conf/1, convert_path/2, eval_erlang_expr/1, eval_erlang_expr/2, concat/2, namespace3/1]).
+-export([read_conf/1, convert_path/2, eval_erlang_expr/1, eval_erlang_expr/2,
+ concat/2, namespace3/1, md5_namespace3/1, hexmod8/1]).
read_conf(Conf) ->
{ok, DataBinary} = file:read_file(Conf),
@@ -56,4 +57,12 @@ concat(A, B) ->
namespace3(Name) ->
SafeName = Name ++ Name ++ Name,
[A, B, C | _RestName] = SafeName,
- string:join([[A], [B], [C]], "/").
+ string:join([[A], [B], [C]], "/").
+
+md5_namespace3(Name) ->
+ [A, B, C, D, E, F | _T] = md5:hex(Name),
+ [A, B, $/, C, D, $/, E, F].
+
+hexmod8(Name) ->
+ <<A:4, _:124>> = erlang:md5(Name),
+ A rem 8.
View
16 elibs/md5.erl
@@ -0,0 +1,16 @@
+-module(md5).
+-export([hex/1]).
+
+hex(String) ->
+ transform(binary_to_list(erlang:md5(String))).
+
+transform(L) ->
+ lists:flatten([[hex0((I band 16#f0) bsr 4), hex0(I band 16#0f)] || I <- L]).
+
+hex0(10) -> $a;
+hex0(11) -> $b;
+hex0(12) -> $c;
+hex0(13) -> $d;
+hex0(14) -> $e;
+hex0(15) -> $f;
+hex0(I) -> $0 + I.

0 comments on commit aa67075

Please sign in to comment.
Something went wrong with that request. Please try again.