mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Merge upstream
This commit is contained in:
commit
aeab6504a7
35 changed files with 262 additions and 357 deletions
|
@ -23,11 +23,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
|
||||
import org.jivesoftware.smack.AbstractConnectionListener;
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.ExceptionCallback;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.SmackFuture;
|
||||
import org.jivesoftware.smack.StanzaListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
|
@ -42,6 +42,8 @@ import org.jivesoftware.smack.filter.StanzaTypeFilter;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.ExceptionCallback;
|
||||
import org.jivesoftware.smack.util.SuccessCallback;
|
||||
|
||||
import org.jivesoftware.smackx.carbons.packet.Carbon;
|
||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||
|
@ -245,10 +247,9 @@ public final class CarbonManager extends Manager {
|
|||
* </p>
|
||||
*
|
||||
* @param exceptionCallback the optional exception callback.
|
||||
* @throws InterruptedException if the thread got interrupted while this action is performed.
|
||||
* @since 4.2
|
||||
*/
|
||||
public void enableCarbonsAsync(ExceptionCallback exceptionCallback) throws InterruptedException {
|
||||
public void enableCarbonsAsync(ExceptionCallback<Exception> exceptionCallback) {
|
||||
sendUseCarbons(true, exceptionCallback);
|
||||
}
|
||||
|
||||
|
@ -262,29 +263,24 @@ public final class CarbonManager extends Manager {
|
|||
* </p>
|
||||
*
|
||||
* @param exceptionCallback the optional exception callback.
|
||||
* @throws InterruptedException if the thread got interrupted while this action is performed.
|
||||
* @since 4.2
|
||||
*/
|
||||
public void disableCarbonsAsync(ExceptionCallback exceptionCallback) throws InterruptedException {
|
||||
public void disableCarbonsAsync(ExceptionCallback<Exception> exceptionCallback) {
|
||||
sendUseCarbons(false, exceptionCallback);
|
||||
}
|
||||
|
||||
private void sendUseCarbons(final boolean use, ExceptionCallback exceptionCallback) throws InterruptedException {
|
||||
private void sendUseCarbons(final boolean use, ExceptionCallback<Exception> exceptionCallback) {
|
||||
IQ setIQ = carbonsEnabledIQ(use);
|
||||
|
||||
try {
|
||||
connection().sendIqWithResponseCallback(setIQ, new StanzaListener() {
|
||||
@Override
|
||||
public void processStanza(Stanza packet) {
|
||||
enabled_state = use;
|
||||
}
|
||||
}, exceptionCallback);
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
if (exceptionCallback != null) {
|
||||
exceptionCallback.processException(e);
|
||||
SmackFuture<IQ, Exception> future = connection().sendIqRequestAsync(setIQ);
|
||||
|
||||
future.onSuccess(new SuccessCallback<IQ>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(IQ result) {
|
||||
enabled_state = use;
|
||||
}
|
||||
}
|
||||
}).onError(exceptionCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.hashes;
|
||||
|
||||
import static org.jivesoftware.smack.util.StringUtils.encodeHex;
|
||||
import static org.jivesoftware.smack.util.StringUtils.toUtf8Bytes;
|
||||
import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.BLAKE2B160;
|
||||
import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.BLAKE2B256;
|
||||
import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.BLAKE2B384;
|
||||
|
@ -31,8 +33,6 @@ import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.SHA_256;
|
|||
import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.SHA_384;
|
||||
import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.SHA_512;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
|
@ -44,7 +44,6 @@ import java.util.WeakHashMap;
|
|||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||
|
@ -52,7 +51,10 @@ import org.jivesoftware.smackx.hashes.element.HashElement;
|
|||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
/**
|
||||
* Manager that can be used to determine support for hash functions.
|
||||
* Manager that can be used to determine support for hash functions. By default the Manager announces support for
|
||||
* XEP-0300, as well as for the recommended set of hash algorithms. Those contain SHA256, SHA384, SHA512, SHA3-256,
|
||||
* SHA3-384, SHA3-512, BLAKE2B256, BLAKE2B384 and BLAKE2B512. Those algorithms got recommended here:
|
||||
* <a href="https://xmpp.org/extensions/xep-0300.html#recommendations">https://xmpp.org/extensions/xep-0300.html#recommendations</a>.
|
||||
*/
|
||||
public final class HashManager extends Manager {
|
||||
|
||||
|
@ -88,9 +90,7 @@ public final class HashManager extends Manager {
|
|||
|
||||
/**
|
||||
* Constructor of the HashManager.
|
||||
* By default the Manager announces support for XEP-0300, as well as for the RECOMMENDED set of hash algorithms.
|
||||
* Those contain SHA256, SHA384, SHA512, SHA3-256, SHA3-384, SHA3-512, BLAKE2B256, BLAKE2B384 and BLAKE2B512.
|
||||
* Those algorithms got recommended here: https://xmpp.org/extensions/xep-0300.html#recommendations
|
||||
*
|
||||
* @param connection connection
|
||||
*/
|
||||
private HashManager(XMPPConnection connection) {
|
||||
|
@ -122,9 +122,9 @@ public final class HashManager extends Manager {
|
|||
/**
|
||||
* Get an instance of the HashManager for the given connection.
|
||||
* @param connection
|
||||
* @return
|
||||
* @return the manager for the given connection.
|
||||
*/
|
||||
public HashManager getInstanceFor(XMPPConnection connection) {
|
||||
public static synchronized HashManager getInstanceFor(XMPPConnection connection) {
|
||||
HashManager hashManager = INSTANCES.get(connection);
|
||||
if (hashManager == null) {
|
||||
hashManager = new HashManager(connection);
|
||||
|
@ -142,26 +142,36 @@ public final class HashManager extends Manager {
|
|||
return PREFIX_NS_ALGO + algorithm.toString();
|
||||
}
|
||||
|
||||
public enum ALGORITHM { // RECOMMENDATION:
|
||||
MD5 ("md5"), // MUST NOT use this
|
||||
SHA_1 ("sha-1"), // SHOULD NOT use this
|
||||
SHA_224 ("sha-224"),
|
||||
SHA_256 ("sha-256"), // MUST use this
|
||||
SHA_384 ("sha-384"),
|
||||
SHA_512 ("sha-512"), // SHOULD use this
|
||||
SHA3_224 ("sha3-224"),
|
||||
SHA3_256 ("sha3-256"), // MUST use this
|
||||
SHA3_384 ("sha3-384"),
|
||||
SHA3_512 ("sha3-512"), // SHOULD use this
|
||||
BLAKE2B160("id-blake2b160"),
|
||||
BLAKE2B256("id-blake2b256"), // MUST use this
|
||||
BLAKE2B384("id-blake2b384"),
|
||||
BLAKE2B512("id-blake2b512"); // SHOULD use this
|
||||
enum AlgorithmRecommendation {
|
||||
unknown,
|
||||
must_not,
|
||||
should_not,
|
||||
should,
|
||||
must,
|
||||
}
|
||||
|
||||
public enum ALGORITHM {
|
||||
MD5 ("md5", AlgorithmRecommendation.must_not),
|
||||
SHA_1 ("sha-1", AlgorithmRecommendation.should_not),
|
||||
SHA_224 ("sha-224", AlgorithmRecommendation.unknown),
|
||||
SHA_256 ("sha-256", AlgorithmRecommendation.must),
|
||||
SHA_384 ("sha-384", AlgorithmRecommendation.unknown),
|
||||
SHA_512 ("sha-512", AlgorithmRecommendation.should),
|
||||
SHA3_224 ("sha3-224", AlgorithmRecommendation.unknown),
|
||||
SHA3_256 ("sha3-256", AlgorithmRecommendation.must),
|
||||
SHA3_384 ("sha3-384", AlgorithmRecommendation.unknown),
|
||||
SHA3_512 ("sha3-512", AlgorithmRecommendation.should),
|
||||
BLAKE2B160("id-blake2b160", AlgorithmRecommendation.unknown),
|
||||
BLAKE2B256("id-blake2b256", AlgorithmRecommendation.must),
|
||||
BLAKE2B384("id-blake2b384", AlgorithmRecommendation.unknown),
|
||||
BLAKE2B512("id-blake2b512", AlgorithmRecommendation.should);
|
||||
|
||||
private final String name;
|
||||
private final AlgorithmRecommendation recommendation;
|
||||
|
||||
ALGORITHM(String name) {
|
||||
ALGORITHM(String name, AlgorithmRecommendation recommendation) {
|
||||
this.name = name;
|
||||
this.recommendation = recommendation;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,10 +183,16 @@ public final class HashManager extends Manager {
|
|||
return this.name;
|
||||
}
|
||||
|
||||
public AlgorithmRecommendation getRecommendation() {
|
||||
return recommendation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compensational method for static 'valueOf' function.
|
||||
*
|
||||
* @param s
|
||||
* @return
|
||||
* @return the algorithm for the given string.
|
||||
* @throws IllegalArgumentException if no algorithm for the given string is known.
|
||||
*/
|
||||
public static ALGORITHM valueOfName(String s) {
|
||||
for (ALGORITHM a : ALGORITHM.values()) {
|
||||
|
@ -190,16 +206,17 @@ public final class HashManager extends Manager {
|
|||
|
||||
/**
|
||||
* Calculate the hash sum of data using algorithm.
|
||||
* @param algorithm
|
||||
* @param data
|
||||
* @return
|
||||
*
|
||||
* @param algorithm the algorithm to use.
|
||||
* @param data the data to calculate the hash for.
|
||||
* @return the hash value produced by the given algorithm for the given data.
|
||||
*/
|
||||
public static byte[] hash(ALGORITHM algorithm, byte[] data) {
|
||||
return getMessageDigest(algorithm).digest(data);
|
||||
}
|
||||
|
||||
public static byte[] hash(ALGORITHM algorithm, String data) {
|
||||
return hash(algorithm, utf8(data));
|
||||
return hash(algorithm, toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static MessageDigest getMessageDigest(ALGORITHM algorithm) {
|
||||
|
@ -249,7 +266,7 @@ public final class HashManager extends Manager {
|
|||
md = MessageDigest.getInstance("BLAKE2b-512", PROVIDER);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Invalid enum value.");
|
||||
throw new AssertionError("Invalid enum value: " + algorithm);
|
||||
}
|
||||
return md;
|
||||
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
|
||||
|
@ -262,15 +279,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] md5(String data) {
|
||||
return md5(utf8(data));
|
||||
return md5(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String md5HexString(byte[] data) {
|
||||
return hex(md5(data));
|
||||
return encodeHex(md5(data));
|
||||
}
|
||||
|
||||
public static String md5HexString(String data) {
|
||||
return hex(md5(data));
|
||||
return encodeHex(md5(data));
|
||||
}
|
||||
|
||||
public static byte[] sha_1(byte[] data) {
|
||||
|
@ -278,15 +295,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] sha_1(String data) {
|
||||
return sha_1(utf8(data));
|
||||
return sha_1(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String sha_1HexString(byte[] data) {
|
||||
return hex(sha_1(data));
|
||||
return encodeHex(sha_1(data));
|
||||
}
|
||||
|
||||
public static String sha_1HexString(String data) {
|
||||
return hex(sha_1(data));
|
||||
return encodeHex(sha_1(data));
|
||||
}
|
||||
|
||||
public static byte[] sha_224(byte[] data) {
|
||||
|
@ -294,15 +311,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] sha_224(String data) {
|
||||
return sha_224(utf8(data));
|
||||
return sha_224(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String sha_224HexString(byte[] data) {
|
||||
return hex(sha_224(data));
|
||||
return encodeHex(sha_224(data));
|
||||
}
|
||||
|
||||
public static String sha_224HexString(String data) {
|
||||
return hex(sha_224(data));
|
||||
return encodeHex(sha_224(data));
|
||||
}
|
||||
|
||||
public static byte[] sha_256(byte[] data) {
|
||||
|
@ -310,15 +327,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] sha_256(String data) {
|
||||
return sha_256(utf8(data));
|
||||
return sha_256(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String sha_256HexString(byte[] data) {
|
||||
return hex(sha_256(data));
|
||||
return encodeHex(sha_256(data));
|
||||
}
|
||||
|
||||
public static String sha_256HexString(String data) {
|
||||
return hex(sha_256(data));
|
||||
return encodeHex(sha_256(data));
|
||||
}
|
||||
|
||||
public static byte[] sha_384(byte[] data) {
|
||||
|
@ -326,15 +343,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] sha_384(String data) {
|
||||
return sha_384(utf8(data));
|
||||
return sha_384(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String sha_384HexString(byte[] data) {
|
||||
return hex(sha_384(data));
|
||||
return encodeHex(sha_384(data));
|
||||
}
|
||||
|
||||
public static String sha_384HexString(String data) {
|
||||
return hex(sha_384(data));
|
||||
return encodeHex(sha_384(data));
|
||||
}
|
||||
|
||||
public static byte[] sha_512(byte[] data) {
|
||||
|
@ -342,15 +359,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] sha_512(String data) {
|
||||
return sha_512(utf8(data));
|
||||
return sha_512(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String sha_512HexString(byte[] data) {
|
||||
return hex(sha_512(data));
|
||||
return encodeHex(sha_512(data));
|
||||
}
|
||||
|
||||
public static String sha_512HexString(String data) {
|
||||
return hex(sha_512(data));
|
||||
return encodeHex(sha_512(data));
|
||||
}
|
||||
|
||||
public static byte[] sha3_224(byte[] data) {
|
||||
|
@ -358,15 +375,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] sha3_224(String data) {
|
||||
return sha3_224(utf8(data));
|
||||
return sha3_224(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String sha3_224HexString(byte[] data) {
|
||||
return hex(sha3_224(data));
|
||||
return encodeHex(sha3_224(data));
|
||||
}
|
||||
|
||||
public static String sha3_224HexString(String data) {
|
||||
return hex(sha3_224(data));
|
||||
return encodeHex(sha3_224(data));
|
||||
}
|
||||
|
||||
public static byte[] sha3_256(byte[] data) {
|
||||
|
@ -374,15 +391,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] sha3_256(String data) {
|
||||
return sha3_256(utf8(data));
|
||||
return sha3_256(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String sha3_256HexString(byte[] data) {
|
||||
return hex(sha3_256(data));
|
||||
return encodeHex(sha3_256(data));
|
||||
}
|
||||
|
||||
public static String sha3_256HexString(String data) {
|
||||
return hex(sha3_256(data));
|
||||
return encodeHex(sha3_256(data));
|
||||
}
|
||||
|
||||
public static byte[] sha3_384(byte[] data) {
|
||||
|
@ -390,15 +407,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] sha3_384(String data) {
|
||||
return sha3_384(utf8(data));
|
||||
return sha3_384(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String sha3_384HexString(byte[] data) {
|
||||
return hex(sha3_384(data));
|
||||
return encodeHex(sha3_384(data));
|
||||
}
|
||||
|
||||
public static String sha3_384HexString(String data) {
|
||||
return hex(sha3_384(data));
|
||||
return encodeHex(sha3_384(data));
|
||||
}
|
||||
|
||||
public static byte[] sha3_512(byte[] data) {
|
||||
|
@ -406,15 +423,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] sha3_512(String data) {
|
||||
return sha3_512(utf8(data));
|
||||
return sha3_512(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String sha3_512HexString(byte[] data) {
|
||||
return hex(sha3_512(data));
|
||||
return encodeHex(sha3_512(data));
|
||||
}
|
||||
|
||||
public static String sha3_512HexString(String data) {
|
||||
return hex(sha3_512(data));
|
||||
return encodeHex(sha3_512(data));
|
||||
}
|
||||
|
||||
public static byte[] blake2b160(byte[] data) {
|
||||
|
@ -422,15 +439,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] blake2b160(String data) {
|
||||
return blake2b160(utf8(data));
|
||||
return blake2b160(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String blake2b160HexString(byte[] data) {
|
||||
return hex(blake2b160(data));
|
||||
return encodeHex(blake2b160(data));
|
||||
}
|
||||
|
||||
public static String blake2b160HexString(String data) {
|
||||
return hex(blake2b160(data));
|
||||
return encodeHex(blake2b160(data));
|
||||
}
|
||||
|
||||
public static byte[] blake2b256(byte[] data) {
|
||||
|
@ -438,15 +455,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] blake2b256(String data) {
|
||||
return blake2b256(utf8(data));
|
||||
return blake2b256(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static String blake2b256HexString(byte[] data) {
|
||||
return hex(blake2b256(data));
|
||||
return encodeHex(blake2b256(data));
|
||||
}
|
||||
|
||||
public static String blake2b256HexString(String data) {
|
||||
return hex(blake2b256(data));
|
||||
return encodeHex(blake2b256(data));
|
||||
}
|
||||
|
||||
public static byte[] blake2b384(byte[] data) {
|
||||
|
@ -454,15 +471,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] blake2b384(String data) {
|
||||
return blake2b384(utf8(data));
|
||||
return blake2b384(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public String blake2b384HexString(byte[] data) {
|
||||
return hex(blake2b384(data));
|
||||
public static String blake2b384HexString(byte[] data) {
|
||||
return encodeHex(blake2b384(data));
|
||||
}
|
||||
|
||||
public String blake2b384HexString(String data) {
|
||||
return hex(blake2b384(data));
|
||||
public static String blake2b384HexString(String data) {
|
||||
return encodeHex(blake2b384(data));
|
||||
}
|
||||
|
||||
public static byte[] blake2b512(byte[] data) {
|
||||
|
@ -470,32 +487,15 @@ public final class HashManager extends Manager {
|
|||
}
|
||||
|
||||
public static byte[] blake2b512(String data) {
|
||||
return blake2b512(utf8(data));
|
||||
return blake2b512(toUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public String blake2b512HexString(byte[] data) {
|
||||
return hex(blake2b512(data));
|
||||
public static String blake2b512HexString(byte[] data) {
|
||||
return encodeHex(blake2b512(data));
|
||||
}
|
||||
|
||||
public String blake2b512HexString(String data) {
|
||||
return hex(blake2b512(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a byte array in HEX.
|
||||
* @param hash
|
||||
* @return
|
||||
*/
|
||||
public static String hex(byte[] hash) {
|
||||
return new BigInteger(1, hash).toString(16);
|
||||
}
|
||||
|
||||
public static byte[] utf8(String data) {
|
||||
try {
|
||||
return data.getBytes(StringUtils.UTF8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
public static String blake2b512HexString(String data) {
|
||||
return encodeHex(blake2b512(data));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,7 +62,8 @@ public class HashElement implements ExtensionElement {
|
|||
|
||||
/**
|
||||
* Return the hash algorithm used in this HashElement.
|
||||
* @return algorithm
|
||||
*
|
||||
* @return algorithm the algorithm.
|
||||
*/
|
||||
public HashManager.ALGORITHM getAlgorithm() {
|
||||
return algorithm;
|
||||
|
@ -70,7 +71,8 @@ public class HashElement implements ExtensionElement {
|
|||
|
||||
/**
|
||||
* Return the checksum as a byte array.
|
||||
* @return
|
||||
*
|
||||
* @return the hash.
|
||||
*/
|
||||
public byte[] getHash() {
|
||||
return hash;
|
||||
|
@ -78,7 +80,8 @@ public class HashElement implements ExtensionElement {
|
|||
|
||||
/**
|
||||
* Return the checksum as a base16 (hex) string.
|
||||
* @return
|
||||
*
|
||||
* @return the hash.
|
||||
*/
|
||||
public String getHashB64() {
|
||||
return hashB64;
|
||||
|
|
|
@ -25,7 +25,7 @@ public class UploadService {
|
|||
enum Version {
|
||||
v0_2,
|
||||
v0_3,
|
||||
};
|
||||
}
|
||||
|
||||
private final DomainBareJid address;
|
||||
private final Version version;
|
||||
|
|
|
@ -607,23 +607,6 @@ public final class MamManager extends Manager {
|
|||
return serviceDiscoveryManager.supportsFeature(myBareJid, MamElements.NAMESPACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Message Archive Management is supported by the server.
|
||||
*
|
||||
* @return true if Message Archive Management is supported by the server.
|
||||
* @throws NotConnectedException
|
||||
* @throws XMPPErrorException
|
||||
* @throws NoResponseException
|
||||
* @throws InterruptedException
|
||||
* @depreacted use {@link #isSupported()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO Remove in Smack 4.3
|
||||
public boolean isSupportedByServer()
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return ServiceDiscoveryManager.getInstanceFor(connection()).serverSupportsFeature(MamElements.NAMESPACE);
|
||||
}
|
||||
|
||||
private static DataForm getNewMamForm() {
|
||||
FormField field = new FormField(FormField.FORM_TYPE);
|
||||
field.setType(FormField.Type.hidden);
|
||||
|
|
|
@ -146,6 +146,7 @@ public class MultiUserChatLight {
|
|||
* for the newly created chat.
|
||||
* @return new Chat for sending private messages to a given room occupant.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
// Do not re-use Chat API, which was designed for XMPP-IM 1:1 chats and not MUClight private chats.
|
||||
public org.jivesoftware.smack.chat.Chat createPrivateChat(EntityJid occupant, ChatMessageListener listener) {
|
||||
|
|
|
@ -68,7 +68,7 @@ public class MUCLightBlockingIQProvider extends IQProvider<MUCLightBlockingIQ> {
|
|||
return mucLightBlockingIQ;
|
||||
}
|
||||
|
||||
private HashMap<Jid, Boolean> parseBlocking(XmlPullParser parser, HashMap<Jid, Boolean> map)
|
||||
private static HashMap<Jid, Boolean> parseBlocking(XmlPullParser parser, HashMap<Jid, Boolean> map)
|
||||
throws XmppStringprepException, XmlPullParserException, IOException {
|
||||
if (map == null) {
|
||||
map = new HashMap<>();
|
||||
|
|
|
@ -93,7 +93,7 @@ public class MUCLightInfoIQProvider extends IQProvider<MUCLightInfoIQ> {
|
|||
return new MUCLightInfoIQ(version, new MUCLightRoomConfiguration(roomName, subject, customConfigs), occupants);
|
||||
}
|
||||
|
||||
private HashMap<Jid, MUCLightAffiliation> iterateOccupants(XmlPullParser parser) throws Exception {
|
||||
private static HashMap<Jid, MUCLightAffiliation> iterateOccupants(XmlPullParser parser) throws Exception {
|
||||
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
|
||||
int depth = parser.getDepth();
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class HashElementTest extends SmackTestSuite {
|
|||
@Test
|
||||
public void stanzaTest() throws Exception {
|
||||
String message = "Hello World!";
|
||||
HashElement element = HashManager.calculateHashElement(SHA_256, HashManager.utf8(message));
|
||||
HashElement element = HashManager.calculateHashElement(SHA_256, StringUtils.toUtf8Bytes(message));
|
||||
String expected = "<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=</hash>";
|
||||
assertEquals(expected, element.toXML().toString());
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.hashes;
|
|||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -47,7 +48,7 @@ public class HashTest extends SmackTestSuite {
|
|||
|
||||
private byte[] array() {
|
||||
if (testArray == null) {
|
||||
testArray = HashManager.utf8(testString);
|
||||
testArray = StringUtils.toUtf8Bytes(testString);
|
||||
}
|
||||
return testArray;
|
||||
}
|
||||
|
@ -56,103 +57,103 @@ public class HashTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void hashTest() {
|
||||
assertEquals(md5sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.MD5, array())));
|
||||
assertEquals(sha1sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA_1, array())));
|
||||
assertEquals(sha224sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA_224, array())));
|
||||
assertEquals(sha256sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA_256, array())));
|
||||
assertEquals(sha384sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA_384, array())));
|
||||
assertEquals(sha512sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA_512, array())));
|
||||
assertEquals(sha3_224sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA3_224, array())));
|
||||
assertEquals(sha3_256sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA3_256, array())));
|
||||
assertEquals(sha3_384sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA3_384, array())));
|
||||
assertEquals(sha3_512sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA3_512, array())));
|
||||
assertEquals(b2_160sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B160, array())));
|
||||
assertEquals(b2_256sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B256, array())));
|
||||
assertEquals(b2_384sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B384, array())));
|
||||
assertEquals(b2_512sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B512, array())));
|
||||
assertEquals(md5sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.MD5, array())));
|
||||
assertEquals(sha1sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA_1, array())));
|
||||
assertEquals(sha224sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA_224, array())));
|
||||
assertEquals(sha256sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA_256, array())));
|
||||
assertEquals(sha384sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA_384, array())));
|
||||
assertEquals(sha512sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA_512, array())));
|
||||
assertEquals(sha3_224sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA3_224, array())));
|
||||
assertEquals(sha3_256sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA3_256, array())));
|
||||
assertEquals(sha3_384sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA3_384, array())));
|
||||
assertEquals(sha3_512sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA3_512, array())));
|
||||
assertEquals(b2_160sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B160, array())));
|
||||
assertEquals(b2_256sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B256, array())));
|
||||
assertEquals(b2_384sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B384, array())));
|
||||
assertEquals(b2_512sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B512, array())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void md5Test() {
|
||||
String actual = HashManager.hex(HashManager.md5(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.md5(array()));
|
||||
assertEquals(md5sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sha1Test() {
|
||||
String actual = HashManager.hex(HashManager.sha_1(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.sha_1(array()));
|
||||
assertEquals(sha1sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sha224Test() {
|
||||
String actual = HashManager.hex(HashManager.sha_224(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.sha_224(array()));
|
||||
assertEquals(sha224sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sha256Test() {
|
||||
String actual = HashManager.hex(HashManager.sha_256(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.sha_256(array()));
|
||||
assertEquals(sha256sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sha384Test() {
|
||||
String actual = HashManager.hex(HashManager.sha_384(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.sha_384(array()));
|
||||
assertEquals(sha384sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sha512Test() {
|
||||
String actual = HashManager.hex(HashManager.sha_512(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.sha_512(array()));
|
||||
assertEquals(sha512sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sha3_224Test() {
|
||||
String actual = HashManager.hex(HashManager.sha3_224(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.sha3_224(array()));
|
||||
assertEquals(sha3_224sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sha3_256Test() {
|
||||
String actual = HashManager.hex(HashManager.sha3_256(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.sha3_256(array()));
|
||||
assertEquals(sha3_256sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sha3_384Test() {
|
||||
String actual = HashManager.hex(HashManager.sha3_384(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.sha3_384(array()));
|
||||
assertEquals(sha3_384sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sha3_512Test() {
|
||||
String actual = HashManager.hex(HashManager.sha3_512(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.sha3_512(array()));
|
||||
assertEquals(sha3_512sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blake2b160Test() {
|
||||
String actual = HashManager.hex(HashManager.blake2b160(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.blake2b160(array()));
|
||||
assertEquals(b2_160sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blake2b256Test() {
|
||||
String actual = HashManager.hex(HashManager.blake2b256(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.blake2b256(array()));
|
||||
assertEquals(b2_256sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blake2b384Test() {
|
||||
String actual = HashManager.hex(HashManager.blake2b384(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.blake2b384(array()));
|
||||
assertEquals(b2_384sum, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blake2b512Test() {
|
||||
String actual = HashManager.hex(HashManager.blake2b512(array()));
|
||||
String actual = StringUtils.encodeHex(HashManager.blake2b512(array()));
|
||||
assertEquals(b2_512sum, actual);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue