From f66f049ef342cb9b42666288d390c03e1f18e676 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Tue, 22 Jun 2010 03:10:41 +1000 Subject: [PATCH] Added support for all hash functions required by XEP-0115 --- src/mod_caps.erl | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/mod_caps.erl b/src/mod_caps.erl index dc20a9ae3..7fb011ef9 100644 --- a/src/mod_caps.erl +++ b/src/mod_caps.erl @@ -277,10 +277,20 @@ feature_response(#iq{type = result, Host, From, Caps, [SubNode | SubNodes]) -> BinaryNode = node_to_binary(Caps#caps.node, SubNode), IsValid = case Caps#caps.hash of - "sha-1" -> - Caps#caps.version == make_disco_hash(Els, sha1); + "md2" -> + Caps#caps.version == make_disco_hash(Els, md2); "md5" -> Caps#caps.version == make_disco_hash(Els, md5); + "sha-1" -> + Caps#caps.version == make_disco_hash(Els, sha1); + "sha-224" -> + Caps#caps.version == make_disco_hash(Els, sha224); + "sha-256" -> + Caps#caps.version == make_disco_hash(Els, sha256); + "sha-384" -> + Caps#caps.version == make_disco_hash(Els, sha384); + "sha-512" -> + Caps#caps.version == make_disco_hash(Els, sha512); _ -> true end, @@ -339,15 +349,25 @@ make_my_disco_hash(Host) -> "" end. -make_disco_hash(DiscoEls, Algo) when Algo == sha1; Algo == md5 -> +make_disco_hash(DiscoEls, Algo) -> Concat = [concat_identities(DiscoEls), concat_features(DiscoEls), concat_info(DiscoEls)], base64:encode_to_string( - if Algo == sha1 -> - crypto:sha(Concat); + if Algo == md2 -> + sha:md2(Concat); Algo == md5 -> - crypto:md5(Concat) + crypto:md5(Concat); + Algo == sha1 -> + crypto:sha(Concat); + Algo == sha224 -> + sha:sha224(Concat); + Algo == sha256 -> + sha:sha256(Concat); + Algo == sha384 -> + sha:sha384(Concat); + Algo == sha512 -> + sha:sha512(Concat) end). concat_features(Els) ->