aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/generator/AbstractGenerator.java
blob: c96d116d0e46e55cb4c9d5ab73f91d9caca14fb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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 eu.siacs.conversations.services.XmppConnectionService;

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",
			"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",
			"http://jabber.org/protocol/disco#info",
			"urn:xmpp:avatar:metadata+notify" };
	public final String IDENTITY_NAME = "Conversations 0.7";
	public final String IDENTITY_TYPE = "phone";

	protected XmppConnectionService mXmppConnectionService;

	protected AbstractGenerator(XmppConnectionService service) {
		this.mXmppConnectionService = service;
	}

	public String getCapHash() {
		StringBuilder s = new StringBuilder();
		s.append("client/" + IDENTITY_TYPE + "//" + IDENTITY_NAME + "<");
		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance("SHA-1");
		} catch (NoSuchAlgorithmException e) {
			return null;
		}
		List<String> features = Arrays.asList(FEATURES);
		Collections.sort(features);
		for (String feature : features) {
			s.append(feature + "<");
		}
		byte[] sha1 = md.digest(s.toString().getBytes());
		return new String(Base64.encode(sha1, Base64.DEFAULT)).trim();
	}
}