Conversations/src/eu/siacs/conversations/generator/AbstractGenerator.java

41 lines
1.3 KiB
Java
Raw Normal View History

package eu.siacs.conversations.generator;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import android.util.Base64;
public abstract class AbstractGenerator {
public final String[] FEATURES = { "urn:xmpp:jingle:1",
"urn:xmpp:jingle:apps:file-transfer:3",
"urn:xmpp:jingle:transports:s5b:1",
2014-08-30 08:51:55 +02:00
"urn:xmpp:jingle:transports:ibb:1", "urn:xmpp:receipts",
"urn:xmpp:chat-markers:0", "http://jabber.org/protocol/muc",
"jabber:x:conference", "http://jabber.org/protocol/caps",
2014-08-05 01:36:17 +02:00
"http://jabber.org/protocol/disco#info",
2014-08-30 08:51:55 +02:00
"urn:xmpp:avatar:metadata+notify" };
public final String IDENTITY_NAME = "Conversations 0.6";
public final String IDENTITY_TYPE = "phone";
2014-08-30 08:51:55 +02:00
public String getCapHash() {
StringBuilder s = new StringBuilder();
2014-08-30 08:51:55 +02:00
s.append("client/" + IDENTITY_TYPE + "//" + IDENTITY_NAME + "<");
MessageDigest md = null;
2014-08-30 08:51:55 +02:00
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
return null;
}
List<String> features = Arrays.asList(FEATURES);
Collections.sort(features);
2014-08-30 08:51:55 +02:00
for (String feature : features) {
s.append(feature + "<");
}
byte[] sha1 = md.digest(s.toString().getBytes());
2014-08-30 08:51:55 +02:00
return new String(Base64.encode(sha1, Base64.DEFAULT)).trim();
}
}