mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 00:59:39 +02:00
Bump ErrorProne to 2.5.1 and refactor Providers a bit
This also resulted in a refactoring of the Providers and parsing Exceptions. NumberFormatException and ParseException can now be thrown directly, the wrapping in a SmackParsingException is down at a higher layer, i.e. in AbstractProvider.
This commit is contained in:
parent
1df0763f92
commit
a7b3303f3e
136 changed files with 574 additions and 551 deletions
|
@ -425,7 +425,7 @@ public final class OpenPgpManager extends Manager {
|
|||
*
|
||||
* @see <a href="https://xmpp.org/extensions/xep-0373.html#synchro-pep">XEP-0373 §5</a>
|
||||
*
|
||||
* @param selectKeyCallback callback, which will receive the users choice of which keys will be backed up. @param selectKeyCallback
|
||||
* @param selectKeyCallback callback, which will receive the users choice of which keys will be backed up.
|
||||
* @param passphrase secret key passphrase
|
||||
*
|
||||
* @throws InterruptedException if the thread is interrupted.
|
||||
|
@ -631,7 +631,7 @@ public final class OpenPgpManager extends Manager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a {@link PubkeyElement} which contains the given {@code data} base64 encoded.
|
||||
* Create a {@link PubkeyElement} which contains the given {@code date} base64 encoded.
|
||||
*
|
||||
* @param bytes byte representation of an OpenPGP public key
|
||||
* @param date date of creation of the element
|
||||
|
|
|
@ -138,6 +138,8 @@ public final class PublicKeysListElement implements ExtensionElement {
|
|||
return getV4Fingerprint().hashCode() + 3 * getDate().hashCode();
|
||||
}
|
||||
|
||||
@SuppressWarnings("UndefinedEquals")
|
||||
// TODO: Fix the UndefinedEquals due using Date.equals(Date)
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017-2019 Florian Schmaus.
|
||||
* Copyright 2017-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.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.jivesoftware.smackx.ox.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
|
@ -33,7 +34,8 @@ public class CryptElementProvider extends OpenPgpContentElementProvider<CryptEle
|
|||
public static final CryptElementProvider INSTANCE = new CryptElementProvider();
|
||||
|
||||
@Override
|
||||
public CryptElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
public CryptElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
|
||||
throws XmlPullParserException, IOException, SmackParsingException, ParseException {
|
||||
OpenPgpContentElementData data = parseOpenPgpContentElementData(parser, initialDepth);
|
||||
|
||||
return new CryptElement(data.to, data.rpad, data.timestamp, data.payload);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017-2019 Florian Schmaus, 2018 Paul Schaub.
|
||||
* Copyright 2017-2021 Florian Schmaus, 2018 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.jivesoftware.smackx.ox.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
|
@ -78,10 +79,11 @@ public abstract class OpenPgpContentElementProvider<O extends OpenPgpContentElem
|
|||
}
|
||||
|
||||
@Override
|
||||
public abstract O parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException;
|
||||
public abstract O parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
|
||||
throws XmlPullParserException, IOException, SmackParsingException, ParseException;
|
||||
|
||||
protected static OpenPgpContentElementData parseOpenPgpContentElementData(XmlPullParser parser, int initialDepth)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
throws XmlPullParserException, IOException, SmackParsingException, ParseException {
|
||||
Set<Jid> to = new HashSet<>();
|
||||
Date timestamp = null;
|
||||
String rpad = null;
|
||||
|
@ -155,10 +157,10 @@ public abstract class OpenPgpContentElementProvider<O extends OpenPgpContentElem
|
|||
}
|
||||
|
||||
protected static final class OpenPgpContentElementData {
|
||||
protected final Set<Jid> to;
|
||||
protected final Date timestamp;
|
||||
protected final String rpad;
|
||||
protected final List<ExtensionElement> payload;
|
||||
final Set<Jid> to;
|
||||
final Date timestamp;
|
||||
final String rpad;
|
||||
final List<ExtensionElement> payload;
|
||||
|
||||
private OpenPgpContentElementData(Set<Jid> to, Date timestamp, String rpad, List<ExtensionElement> payload) {
|
||||
this.to = to;
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
package org.jivesoftware.smackx.ox.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException.SmackTextParseException;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
@ -36,7 +36,8 @@ public class PubkeyElementProvider extends ExtensionElementProvider<PubkeyElemen
|
|||
public static final PubkeyElementProvider INSTANCE = new PubkeyElementProvider();
|
||||
|
||||
@Override
|
||||
public PubkeyElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackTextParseException {
|
||||
public PubkeyElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
|
||||
throws XmlPullParserException, IOException, ParseException {
|
||||
String dateString = parser.getAttributeValue(null, PubkeyElement.ATTR_DATE);
|
||||
Date date = ParserUtils.getDateFromOptionalXep82String(dateString);
|
||||
while (true) {
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
package org.jivesoftware.smackx.ox.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException.SmackTextParseException;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
@ -35,7 +35,8 @@ public final class PublicKeysListElementProvider extends ExtensionElementProvide
|
|||
public static final PublicKeysListElementProvider TEST_INSTANCE = new PublicKeysListElementProvider();
|
||||
|
||||
@Override
|
||||
public PublicKeysListElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackTextParseException {
|
||||
public PublicKeysListElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
|
||||
throws XmlPullParserException, IOException, ParseException {
|
||||
|
||||
PublicKeysListElement.Builder builder = PublicKeysListElement.builder();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017-2019 Florian Schmaus.
|
||||
* Copyright 2017-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.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.jivesoftware.smackx.ox.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
|
@ -36,7 +37,8 @@ public class SignElementProvider extends OpenPgpContentElementProvider<SignEleme
|
|||
public static final SignElementProvider INSTANCE = new SignElementProvider();
|
||||
|
||||
@Override
|
||||
public SignElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
public SignElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
|
||||
throws XmlPullParserException, IOException, SmackParsingException, ParseException {
|
||||
OpenPgpContentElementData data = parseOpenPgpContentElementData(parser, initialDepth);
|
||||
|
||||
if (StringUtils.isNotEmpty(data.rpad)) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017-2019 Florian Schmaus, 2018 Paul Schaub.
|
||||
* Copyright 2017-2021 Florian Schmaus, 2018 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.jivesoftware.smackx.ox.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
|
@ -33,7 +34,8 @@ public class SigncryptElementProvider extends OpenPgpContentElementProvider<Sign
|
|||
public static final SigncryptElementProvider INSTANCE = new SigncryptElementProvider();
|
||||
|
||||
@Override
|
||||
public SigncryptElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
public SigncryptElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
|
||||
throws XmlPullParserException, IOException, SmackParsingException, ParseException {
|
||||
OpenPgpContentElementData data = parseOpenPgpContentElementData(parser, initialDepth);
|
||||
return new SigncryptElement(data.to, data.rpad, data.timestamp, data.payload);
|
||||
}
|
||||
|
|
|
@ -88,6 +88,7 @@ public class OpenPgpElementTest extends SmackTestSuite {
|
|||
assertNotNull(element.getTimestamp());
|
||||
}
|
||||
|
||||
@SuppressWarnings("UndefinedEquals")
|
||||
@Test
|
||||
public void signElementProviderTest() throws Exception {
|
||||
String expected =
|
||||
|
@ -114,6 +115,7 @@ public class OpenPgpElementTest extends SmackTestSuite {
|
|||
assertEquals(element.getExtensions(), parsed.getExtensions());
|
||||
}
|
||||
|
||||
@SuppressWarnings("UndefinedEquals")
|
||||
@Test
|
||||
public void cryptElementProviderTest() throws Exception {
|
||||
String expected =
|
||||
|
@ -144,6 +146,7 @@ public class OpenPgpElementTest extends SmackTestSuite {
|
|||
assertEquals(element.getExtensions(), parsed.getExtensions());
|
||||
}
|
||||
|
||||
@SuppressWarnings("UndefinedEquals")
|
||||
@Test
|
||||
public void signcryptElementProviderTest() throws Exception {
|
||||
String expected =
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.jxmpp.util.XmppDateTime;
|
|||
|
||||
public class PubkeyElementTest extends SmackTestSuite {
|
||||
|
||||
@SuppressWarnings("UndefinedEquals")
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void providerTest(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue