diff options
| author | Matthias Radestock <matthias@rabbitmq.com> | 2011-11-23 00:37:47 +0000 |
|---|---|---|
| committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-11-23 00:37:47 +0000 |
| commit | eb9fa45f9d3bfc280c1bd3c2b28e8e1f95dae15f (patch) | |
| tree | be7135d29d85fa80a15b6c9284f81550bb40423b | |
| parent | 73a31048797f70aafae8ab7ff7c1aea5efbb8a4f (diff) | |
| download | rabbitmq-server-git-eb9fa45f9d3bfc280c1bd3c2b28e8e1f95dae15f.tar.gz | |
base64url-encode for string guid generation
this works well for AMQP (with its restrictions on queue name
characters) but also when used as part of filenames, urls, etc
| -rw-r--r-- | src/rabbit_guid.erl | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/rabbit_guid.erl b/src/rabbit_guid.erl index 523af7492d..2d0f5014f2 100644 --- a/src/rabbit_guid.erl +++ b/src/rabbit_guid.erl @@ -89,8 +89,15 @@ guid() -> erlang:md5(term_to_binary(G)). %% generate a readable string representation of a GUID. +%% +%% employs base64url encoding, which is safer in more contexts than +%% plain base64. string_guid(Prefix) -> - Prefix ++ "-" ++ base64:encode_to_string(guid()). + Prefix ++ "-" ++ lists:foldl(fun ($\+, Acc) -> [$\- | Acc]; + ($\/, Acc) -> [$\_ | Acc]; + ($\=, Acc) -> Acc; + (Chr, Acc) -> [Chr | Acc] + end, [], base64:encode_to_string(guid())). binstring_guid(Prefix) -> list_to_binary(string_guid(Prefix)). |
