TOTP: left-pad with 0's as needed
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/0c0b438c Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/0c0b438c Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/0c0b438c Branch: refs/heads/2491-refactor-couch-httpd-auth Commit: 0c0b438c2648f11afd646fbebb1bf9c24f36a8a5 Parents: bfbf8eb Author: Robert Newson <[email protected]> Authored: Sun Nov 2 21:17:01 2014 +0000 Committer: Robert Newson <[email protected]> Committed: Sun Nov 2 21:17:01 2014 +0000 ---------------------------------------------------------------------- src/couch_httpd_auth.erl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/0c0b438c/src/couch_httpd_auth.erl ---------------------------------------------------------------------- diff --git a/src/couch_httpd_auth.erl b/src/couch_httpd_auth.erl index 5e528d9..752dd20 100644 --- a/src/couch_httpd_auth.erl +++ b/src/couch_httpd_auth.erl @@ -475,12 +475,15 @@ verify_token(Alg, Key, Len, Token) -> end. generate_token(Alg, Key, Len, Timestamp) -> - integer_to_binary(couch_totp:generate(Alg, Key, Timestamp, 30, Len)). + integer_to_binary(couch_totp:generate(Alg, Key, Timestamp, 30, Len), Len). -integer_to_binary(Int) when is_integer(Int) -> - case erlang:function_exported(erlang, integer_to_binary, 1) of +integer_to_binary(Int, Len) when is_integer(Int), is_integer(Len) -> + Unpadded = case erlang:function_exported(erlang, integer_to_binary, 1) of true -> erlang:integer_to_binary(Int); false -> - ?l2b(integer_to_list(Int)) - end. + ?l2b(integer_to_list(Int)) + end, + Padding = binary:copy(<<"0">>, Len), + Padded = <<Padding/binary, Unpadded/binary>>, + binary:part(Padded, byte_size(Padded), -Len).
