mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 00:59:39 +02:00
Do not call XmlPullParser.getName() when the event is unknown
XmlPullParser.getName() only returns a result if the current parser event is START_ELEMENT or END_ELEMENT. If this is not the case, then the method may throw (if StAX is used).
This commit is contained in:
parent
4120b42761
commit
5eef31e49c
25 changed files with 74 additions and 90 deletions
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.omemo.provider;
|
||||
|
||||
import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.BUNDLE;
|
||||
import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.IDENTITY_KEY;
|
||||
import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.PRE_KEYS;
|
||||
import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.PRE_KEY_ID;
|
||||
|
@ -43,7 +42,6 @@ import org.jivesoftware.smackx.omemo.element.OmemoBundleElement_VAxolotl;
|
|||
public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider<OmemoBundleElement_VAxolotl> {
|
||||
@Override
|
||||
public OmemoBundleElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
|
||||
boolean stop = false;
|
||||
boolean inPreKeys = false;
|
||||
|
||||
int signedPreKeyId = -1;
|
||||
|
@ -52,11 +50,11 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider<OmemoB
|
|||
String identityKey = null;
|
||||
HashMap<Integer, String> preKeys = new HashMap<>();
|
||||
|
||||
while (!stop) {
|
||||
outerloop: while (true) {
|
||||
XmlPullParser.Event tag = parser.next();
|
||||
String name = parser.getName();
|
||||
switch (tag) {
|
||||
case START_ELEMENT:
|
||||
String name = parser.getName();
|
||||
final int attributeCount = parser.getAttributeCount();
|
||||
// <signedPreKeyPublic>
|
||||
if (name.equals(SIGNED_PRE_KEY_PUB)) {
|
||||
|
@ -91,8 +89,8 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider<OmemoB
|
|||
}
|
||||
break;
|
||||
case END_ELEMENT:
|
||||
if (name.equals(BUNDLE)) {
|
||||
stop = true;
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
* Copyright 2017 Paul Schaub, 2021 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,7 +18,6 @@ package org.jivesoftware.smackx.omemo.provider;
|
|||
|
||||
import static org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement.DEVICE;
|
||||
import static org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement.ID;
|
||||
import static org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement.LIST;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
|
@ -41,12 +40,11 @@ public class OmemoDeviceListVAxolotlProvider extends ExtensionElementProvider<Om
|
|||
@Override
|
||||
public OmemoDeviceListElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
|
||||
Set<Integer> deviceListIds = new HashSet<>();
|
||||
boolean stop = false;
|
||||
while (!stop) {
|
||||
outerloop: while (true) {
|
||||
XmlPullParser.Event tag = parser.next();
|
||||
String name = parser.getName();
|
||||
switch (tag) {
|
||||
case START_ELEMENT:
|
||||
String name = parser.getName();
|
||||
if (name.equals(DEVICE)) {
|
||||
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
||||
if (parser.getAttributeName(i).equals(ID)) {
|
||||
|
@ -57,8 +55,8 @@ public class OmemoDeviceListVAxolotlProvider extends ExtensionElementProvider<Om
|
|||
}
|
||||
break;
|
||||
case END_ELEMENT:
|
||||
if (name.equals(LIST)) {
|
||||
stop = true;
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.jivesoftware.smackx.omemo.provider;
|
||||
|
||||
import static org.jivesoftware.smackx.omemo.element.OmemoElement.ATTR_PAYLOAD;
|
||||
import static org.jivesoftware.smackx.omemo.element.OmemoElement.NAME_ENCRYPTED;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -42,17 +41,16 @@ public class OmemoVAxolotlProvider extends ExtensionElementProvider<OmemoElement
|
|||
|
||||
@Override
|
||||
public OmemoElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
|
||||
boolean inEncrypted = true;
|
||||
int sid = -1;
|
||||
ArrayList<OmemoKeyElement> keys = new ArrayList<>();
|
||||
byte[] iv = null;
|
||||
byte[] payload = null;
|
||||
|
||||
while (inEncrypted) {
|
||||
outerloop: while (true) {
|
||||
XmlPullParser.Event tag = parser.next();
|
||||
String name = parser.getName();
|
||||
switch (tag) {
|
||||
case START_ELEMENT:
|
||||
String name = parser.getName();
|
||||
switch (name) {
|
||||
case OmemoHeaderElement.ELEMENT:
|
||||
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
||||
|
@ -82,8 +80,8 @@ public class OmemoVAxolotlProvider extends ExtensionElementProvider<OmemoElement
|
|||
}
|
||||
break;
|
||||
case END_ELEMENT:
|
||||
if (name.equals(NAME_ENCRYPTED)) {
|
||||
inEncrypted = false;
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue