From 247ca872f67f29e05783bd94e1f588f6872eaf3c Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Sat, 31 Dec 2016 13:47:35 +0300 Subject: Improve return values in cyrsasl API --- src/cyrsasl_plain.erl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/cyrsasl_plain.erl') diff --git a/src/cyrsasl_plain.erl b/src/cyrsasl_plain.erl index 8e9b32b99..bbac8deff 100644 --- a/src/cyrsasl_plain.erl +++ b/src/cyrsasl_plain.erl @@ -27,11 +27,13 @@ -author('alexey@process-one.net'). --export([start/1, stop/0, mech_new/4, mech_step/2, parse/1]). +-export([start/1, stop/0, mech_new/4, mech_step/2, parse/1, format_error/1]). -behaviour(cyrsasl). -record(state, {check_password}). +-type error_reason() :: parser_failed | not_authorized. +-export_type([error_reason/0]). start(_Opts) -> cyrsasl:register_mechanism(<<"PLAIN">>, ?MODULE, plain), @@ -39,6 +41,12 @@ start(_Opts) -> stop() -> ok. +-spec format_error(error_reason()) -> {atom(), binary()}. +format_error(parser_failed) -> + {'bad-protocol', <<"Response decoding failed">>}; +format_error(not_authorized) -> + {'not-authorized', <<"Invalid username or password">>}. + mech_new(_Host, _GetPassword, CheckPassword, _CheckPasswordDigest) -> {ok, #state{check_password = CheckPassword}}. @@ -50,9 +58,9 @@ mech_step(State, ClientIn) -> {ok, [{username, User}, {authzid, AuthzId}, {auth_module, AuthModule}]}; - _ -> {error, 'not-authorized', User} + _ -> {error, not_authorized, User} end; - _ -> {error, 'bad-protocol'} + _ -> {error, parser_failed} end. prepare(ClientIn) -> -- cgit v1.2.3