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:
parent
3e74d11b45
commit
9f86eda532
3 changed files with 19 additions and 14 deletions
|
@ -222,6 +222,10 @@ public class StringUtils {
|
||||||
return out;
|
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
|
* Hashes a String using the SHA-1 algorithm and returns the result as a
|
||||||
* String of hexadecimal numbers. This method is synchronized to avoid
|
* String of hexadecimal numbers. This method is synchronized to avoid
|
||||||
|
|
|
@ -60,8 +60,8 @@ public abstract class OmemoBundleElement implements ExtensionElement {
|
||||||
* @param preKeysB64 HashMap of base64 encoded preKeys
|
* @param preKeysB64 HashMap of base64 encoded preKeys
|
||||||
*/
|
*/
|
||||||
public OmemoBundleElement(int signedPreKeyId, String signedPreKeyB64, String signedPreKeySigB64, String identityKeyB64, HashMap<Integer, String> preKeysB64) {
|
public OmemoBundleElement(int signedPreKeyId, String signedPreKeyB64, String signedPreKeySigB64, String identityKeyB64, HashMap<Integer, String> preKeysB64) {
|
||||||
if (signedPreKeyId <= 0) {
|
if (signedPreKeyId < 0) {
|
||||||
throw new IllegalArgumentException("signedPreKeyId MUST be greater than 0.");
|
throw new IllegalArgumentException("signedPreKeyId MUST be greater than or equal to 0.");
|
||||||
}
|
}
|
||||||
this.signedPreKeyId = signedPreKeyId;
|
this.signedPreKeyId = signedPreKeyId;
|
||||||
this.signedPreKeyB64 = StringUtils.requireNotNullNorEmpty(signedPreKeyB64, "signedPreKeyB64 MUST NOT be null nor empty.");
|
this.signedPreKeyB64 = StringUtils.requireNotNullNorEmpty(signedPreKeyB64, "signedPreKeyB64 MUST NOT be null nor empty.");
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.HashMap;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||||
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||||
|
|
||||||
|
@ -59,39 +60,39 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider<OmemoB
|
||||||
case START_ELEMENT:
|
case START_ELEMENT:
|
||||||
final int attributeCount = parser.getAttributeCount();
|
final int attributeCount = parser.getAttributeCount();
|
||||||
// <signedPreKeyPublic>
|
// <signedPreKeyPublic>
|
||||||
if (name.equals(SIGNED_PRE_KEY_PUB)) {
|
if (SIGNED_PRE_KEY_PUB.equals(name)) {
|
||||||
for (int i = 0; i < attributeCount; i++) {
|
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));
|
int id = Integer.parseInt(parser.getAttributeValue(i));
|
||||||
signedPreKey = parser.nextText();
|
signedPreKey = StringUtils.removeNewLines(parser.nextText());
|
||||||
signedPreKeyId = id;
|
signedPreKeyId = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// <bundleGetSignedPreKeySignature>
|
// <bundleGetSignedPreKeySignature>
|
||||||
else if (name.equals(SIGNED_PRE_KEY_SIG)) {
|
else if (SIGNED_PRE_KEY_SIG.equals(name)) {
|
||||||
signedPreKeySignature = parser.nextText();
|
signedPreKeySignature = StringUtils.removeNewLines(parser.nextText());
|
||||||
}
|
}
|
||||||
// <deserializeIdentityKey>
|
// <deserializeIdentityKey>
|
||||||
else if (name.equals(IDENTITY_KEY)) {
|
else if (IDENTITY_KEY.equals(name)) {
|
||||||
identityKey = parser.nextText();
|
identityKey = StringUtils.removeNewLines(parser.nextText());
|
||||||
}
|
}
|
||||||
// <deserializeECPublicKeys>
|
// <deserializeECPublicKeys>
|
||||||
else if (name.equals(PRE_KEYS)) {
|
else if (PRE_KEYS.equals(name)) {
|
||||||
inPreKeys = true;
|
inPreKeys = true;
|
||||||
}
|
}
|
||||||
// <preKeyPublic preKeyId='424242'>
|
// <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++) {
|
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)),
|
preKeys.put(Integer.parseInt(parser.getAttributeValue(i)),
|
||||||
parser.nextText());
|
StringUtils.removeNewLines(parser.nextText()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case END_ELEMENT:
|
case END_ELEMENT:
|
||||||
if (name.equals(BUNDLE)) {
|
if (BUNDLE.equals(name)) {
|
||||||
stop = true;
|
stop = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue