1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 12:32:06 +01:00

OMEMO: converse.js compatibility

This commit is contained in:
Paul Schaub 2019-08-04 15:00:25 +02:00
parent 3e74d11b45
commit 9f86eda532
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 19 additions and 14 deletions

View file

@ -222,6 +222,10 @@ public class StringUtils {
return out;
}
public static String removeNewLines(String s) {
return s.trim().replaceAll("\n", "");
}
/**
* Hashes a String using the SHA-1 algorithm and returns the result as a
* String of hexadecimal numbers. This method is synchronized to avoid

View file

@ -60,8 +60,8 @@ public abstract class OmemoBundleElement implements ExtensionElement {
* @param preKeysB64 HashMap of base64 encoded preKeys
*/
public OmemoBundleElement(int signedPreKeyId, String signedPreKeyB64, String signedPreKeySigB64, String identityKeyB64, HashMap<Integer, String> preKeysB64) {
if (signedPreKeyId <= 0) {
throw new IllegalArgumentException("signedPreKeyId MUST be greater than 0.");
if (signedPreKeyId < 0) {
throw new IllegalArgumentException("signedPreKeyId MUST be greater than or equal to 0.");
}
this.signedPreKeyId = signedPreKeyId;
this.signedPreKeyB64 = StringUtils.requireNotNullNorEmpty(signedPreKeyB64, "signedPreKeyB64 MUST NOT be null nor empty.");

View file

@ -30,6 +30,7 @@ import java.util.HashMap;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
@ -59,39 +60,39 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider<OmemoB
case START_ELEMENT:
final int attributeCount = parser.getAttributeCount();
// <signedPreKeyPublic>
if (name.equals(SIGNED_PRE_KEY_PUB)) {
if (SIGNED_PRE_KEY_PUB.equals(name)) {
for (int i = 0; i < attributeCount; i++) {
if (parser.getAttributeName(i).equals(SIGNED_PRE_KEY_ID)) {
if (SIGNED_PRE_KEY_ID.equals(parser.getAttributeName(i))) {
int id = Integer.parseInt(parser.getAttributeValue(i));
signedPreKey = parser.nextText();
signedPreKey = StringUtils.removeNewLines(parser.nextText());
signedPreKeyId = id;
}
}
}
// <bundleGetSignedPreKeySignature>
else if (name.equals(SIGNED_PRE_KEY_SIG)) {
signedPreKeySignature = parser.nextText();
else if (SIGNED_PRE_KEY_SIG.equals(name)) {
signedPreKeySignature = StringUtils.removeNewLines(parser.nextText());
}
// <deserializeIdentityKey>
else if (name.equals(IDENTITY_KEY)) {
identityKey = parser.nextText();
else if (IDENTITY_KEY.equals(name)) {
identityKey = StringUtils.removeNewLines(parser.nextText());
}
// <deserializeECPublicKeys>
else if (name.equals(PRE_KEYS)) {
else if (PRE_KEYS.equals(name)) {
inPreKeys = true;
}
// <preKeyPublic preKeyId='424242'>
else if (inPreKeys && name.equals(PRE_KEY_PUB)) {
else if (inPreKeys && PRE_KEY_PUB.equals(name)) {
for (int i = 0; i < attributeCount; i++) {
if (parser.getAttributeName(i).equals(PRE_KEY_ID)) {
if (PRE_KEY_ID.equals(parser.getAttributeName(i))) {
preKeys.put(Integer.parseInt(parser.getAttributeValue(i)),
parser.nextText());
StringUtils.removeNewLines(parser.nextText()));
}
}
}
break;
case END_ELEMENT:
if (name.equals(BUNDLE)) {
if (BUNDLE.equals(name)) {
stop = true;
}
break;