From d2f5efcb206a68fbf4c94aa148c023aee254e89d Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 8 May 2019 11:34:40 +0200 Subject: [PATCH] Use StandardCharsets.(UTF_8|US_ASCII) This also gets rid of a ton of UnsupportedEncodingException s. --- .travis.yml | 2 +- build.gradle | 10 +---- .../android/AndroidBase64UrlSafeEncoder.java | 17 ++------- .../smack/AbstractXMPPConnection.java | 3 +- .../smack/SmackInitialization.java | 4 +- .../proxy/Socks4ProxySocketConnection.java | 5 +-- .../proxy/Socks5ProxySocketConnection.java | 8 ++-- .../smack/sasl/core/ScramMechanism.java | 23 +++--------- .../jivesoftware/smack/util/FileUtils.java | 3 +- .../smack/util/PacketParserUtils.java | 9 +---- .../jivesoftware/smack/util/StringUtils.java | 25 +++++++++---- .../smack/util/stringencoder/Base32.java | 37 +++---------------- .../smack/util/stringencoder/Base64.java | 22 ++--------- .../smack/sasl/DigestMd5SaslTest.java | 6 +-- .../smack/util/StringUtilsTest.java | 8 ++-- .../smackx/hashes/HashElementTest.java | 4 +- .../bytestreams/socks5/Socks5Client.java | 11 +----- .../bytestreams/socks5/Socks5Proxy.java | 4 +- .../smackx/caps/EntityCapsManager.java | 12 ++---- .../jivesoftware/smackx/bob/BoBIQTest.java | 5 ++- .../ibb/packet/DataPacketExtensionTest.java | 8 ++-- .../bytestreams/socks5/Socks5ClientTest.java | 6 +-- .../bytestreams/socks5/Socks5ProxyTest.java | 5 +-- .../bytestreams/socks5/Socks5TestProxy.java | 4 +- .../FileTransferIntegrationTest.java | 9 +---- .../java7/Java7Base64UrlSafeEncoder.java | 18 ++------- .../smackx/jingleold/nat/HttpServer.java | 17 ++++----- .../smackx/omemo/OmemoRatchet.java | 9 ++--- .../smackx/omemo/OmemoService.java | 5 +-- .../omemo/util/OmemoMessageBuilder.java | 13 +++---- .../omemo/OmemoBundleVAxolotlElementTest.java | 22 +++++------ .../omemo/OmemoVAxolotlElementTest.java | 8 ++-- .../sasl/provided/SASLDigestMD5Mechanism.java | 10 +---- 33 files changed, 125 insertions(+), 227 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1630d0d92..1abdffa1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: android android: components: - - android-16 + - android-19 jdk: - oraclejdk8 - openjdk8 diff --git a/build.gradle b/build.gradle index a5b9c61d9..8d80bd574 100644 --- a/build.gradle +++ b/build.gradle @@ -705,15 +705,7 @@ def getGitCommit() { } def getAndroidRuntimeJar() { - // We set a different Android API level compared to - // smackMinAndroidSdk here. The runtime jar retrieved via this - // method is, compared to earlier Smack versions, not used to - // check for Android API compatibility. Instead it is used to for - // the eclipse classpath, for javadoc and when compiling the pure - // Android subprojects of Smack. Currently we require level 16 - // here, because of the @TargetApi annotation found in - // AndroidUsingLinkProperties of minidns-android21. - def androidApiLevel = 16 + def androidApiLevel = ext.smackMinAndroidSdk def androidHome = getAndroidHome() def androidJar = new File("$androidHome/platforms/android-${androidApiLevel}/android.jar") if (androidJar.isFile()) { diff --git a/smack-android/src/main/java/org/jivesoftware/smack/util/stringencoder/android/AndroidBase64UrlSafeEncoder.java b/smack-android/src/main/java/org/jivesoftware/smack/util/stringencoder/android/AndroidBase64UrlSafeEncoder.java index e6e43af59..b83d3014d 100644 --- a/smack-android/src/main/java/org/jivesoftware/smack/util/stringencoder/android/AndroidBase64UrlSafeEncoder.java +++ b/smack-android/src/main/java/org/jivesoftware/smack/util/stringencoder/android/AndroidBase64UrlSafeEncoder.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2014-2018 Florian Schmaus + * Copyright © 2014-2019 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,8 @@ */ package org.jivesoftware.smack.util.stringencoder.android; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; -import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.stringencoder.StringEncoder; import android.util.Base64; @@ -39,21 +38,13 @@ public final class AndroidBase64UrlSafeEncoder implements StringEncoder @Override public String encode(String string) { - try { - return Base64.encodeToString(string.getBytes(StringUtils.UTF8), BASE64_ENCODER_FLAGS); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("UTF-8 not supported", e); - } + return Base64.encodeToString(string.getBytes(StandardCharsets.UTF_8), BASE64_ENCODER_FLAGS); } @Override public String decode(String string) { byte[] bytes = Base64.decode(string, BASE64_ENCODER_FLAGS); - try { - return new String(bytes, StringUtils.UTF8); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("UTF-8 not supported", e); - } + return new String(bytes, StandardCharsets.UTF_8); } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 632855ac2..423b42917 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -23,6 +23,7 @@ import java.io.InputStream; import java.io.Reader; import java.io.Writer; import java.lang.reflect.Constructor; +import java.nio.charset.StandardCharsets; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; @@ -2044,7 +2045,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { try { Constructor c = Class.forName("sun.security.pkcs11.SunPKCS11").getConstructor(InputStream.class); String pkcs11Config = "name = SmartCard\nlibrary = " + config.getPKCS11Library(); - ByteArrayInputStream config = new ByteArrayInputStream(pkcs11Config.getBytes(StringUtils.UTF8)); + ByteArrayInputStream config = new ByteArrayInputStream(pkcs11Config.getBytes(StandardCharsets.UTF_8)); Provider p = (Provider) c.newInstance(config); Security.addProvider(p); ks = KeyStore.getInstance("PKCS11",p); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java index 56ce677ce..5bcf27b2f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java @@ -20,6 +20,7 @@ package org.jivesoftware.smack; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.List; import java.util.logging.Level; @@ -45,7 +46,6 @@ import org.jivesoftware.smack.sasl.core.ScramSha1PlusMechanism; import org.jivesoftware.smack.util.CloseableUtil; import org.jivesoftware.smack.util.FileUtils; import org.jivesoftware.smack.util.PacketParserUtils; -import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.xml.XmlPullParser; @@ -69,7 +69,7 @@ public final class SmackInitialization { String smackVersion; BufferedReader reader = null; try { - reader = new BufferedReader(new InputStreamReader(FileUtils.getStreamForClasspathFile("org.jivesoftware.smack/version", null), StringUtils.UTF8)); + reader = new BufferedReader(new InputStreamReader(FileUtils.getStreamForClasspathFile("org.jivesoftware.smack/version", null), StandardCharsets.UTF_8)); smackVersion = reader.readLine(); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Could not determine Smack version", e); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java index a8e384e22..2c2658c99 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java @@ -22,8 +22,7 @@ import java.io.OutputStream; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; - -import org.jivesoftware.smack.util.StringUtils; +import java.nio.charset.StandardCharsets; /** * Socket factory for socks4 proxy. @@ -86,7 +85,7 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection { } if (user != null) { - byte[] userBytes = user.getBytes(StringUtils.UTF8); + byte[] userBytes = user.getBytes(StandardCharsets.UTF_8); System.arraycopy(userBytes, 0, buf, index, user.length()); index += user.length(); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java index de9cebe6f..3c8a080e6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java @@ -21,10 +21,10 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; +import java.nio.charset.StandardCharsets; import java.util.logging.Logger; import org.jivesoftware.smack.util.CloseableUtil; -import org.jivesoftware.smack.util.StringUtils; /** * Socket factory for Socks5 proxy. @@ -133,11 +133,11 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection { index = 0; buf[index++] = 1; buf[index++] = (byte) user.length(); - byte[] userBytes = user.getBytes(StringUtils.UTF8); + byte[] userBytes = user.getBytes(StandardCharsets.UTF_8); System.arraycopy(userBytes, 0, buf, index, user.length()); index += user.length(); - byte[] passwordBytes = passwd.getBytes(StringUtils.UTF8); + byte[] passwordBytes = passwd.getBytes(StandardCharsets.UTF_8); buf[index++] = (byte) passwordBytes.length; System.arraycopy(passwordBytes, 0, buf, index, passwd.length()); @@ -204,7 +204,7 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection { buf[index++] = 1; // CONNECT buf[index++] = 0; - byte[] hostb = host.getBytes(StringUtils.UTF8); + byte[] hostb = host.getBytes(StandardCharsets.UTF_8); int len = hostb.length; buf[index++] = 3; // DOMAINNAME buf[index++] = (byte) len; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java b/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java index c55e7bb3b..e8cb0e8e1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java @@ -16,7 +16,7 @@ */ package org.jivesoftware.smack.sasl.core; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; import java.security.SecureRandom; import java.util.Collections; @@ -114,14 +114,8 @@ public abstract class ScramMechanism extends SASLMechanism { @Override protected byte[] evaluateChallenge(byte[] challenge) throws SmackSaslException { - String challengeString; - try { - // TODO: Where is it specified that this is an UTF-8 encoded string? - challengeString = new String(challenge, StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + // TODO: Where is it specified that this is an UTF-8 encoded string? + String challengeString = new String(challenge, StandardCharsets.UTF_8); switch (state) { case AUTH_TEXT_SENT: @@ -386,14 +380,9 @@ public abstract class ScramMechanism extends SASLMechanism { * @throws SmackSaslException if a SASL related error occurs. */ private byte[] hi(String normalizedPassword, byte[] salt, int iterations) throws SmackSaslException { - byte[] key; - try { - // According to RFC 5802 § 2.2, the resulting string of the normalization is also in UTF-8. - key = normalizedPassword.getBytes(StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(); - } + // According to RFC 5802 § 2.2, the resulting string of the normalization is also in UTF-8. + byte[] key = normalizedPassword.getBytes(StandardCharsets.UTF_8); + // U1 := HMAC(str, salt + INT(1)) byte[] u = hmac(key, ByteUtils.concat(salt, ONE)); byte[] res = u.clone(); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java index 8fc4bcd7e..8d246c1c4 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java @@ -30,6 +30,7 @@ import java.io.Reader; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -90,7 +91,7 @@ public final class FileUtils { public static boolean addLines(String uriString, Set set) throws MalformedURLException, IOException { URI uri = URI.create(uriString); InputStream is = getStreamForUri(uri, null); - InputStreamReader sr = new InputStreamReader(is, StringUtils.UTF8); + InputStreamReader sr = new InputStreamReader(is, StandardCharsets.UTF_8); BufferedReader br = new BufferedReader(sr); try { String line; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java index 25e06bfc9..e80c6efcc 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java @@ -21,7 +21,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -71,12 +71,7 @@ public class PacketParserUtils { } public static XmlPullParser getParserFor(InputStream inputStream) throws XmlPullParserException { - InputStreamReader inputStreamReader; - try { - inputStreamReader = new InputStreamReader(inputStream, StringUtils.UTF8); - } catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); return SmackXmlParser.newXmlParser(inputStreamReader); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java index a3d7ad096..3e172f539 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java @@ -17,7 +17,7 @@ package org.jivesoftware.smack.util; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Iterator; import java.util.Random; @@ -29,7 +29,23 @@ public class StringUtils { public static final String MD5 = "MD5"; public static final String SHA1 = "SHA-1"; + + /** + * Deprecated, do not use. + * + * @deprecated use StandardCharsets.UTF_8 instead. + */ + // TODO: Remove in Smack 4.5. + @Deprecated public static final String UTF8 = "UTF-8"; + + /** + * Deprecated, do not use. + * + * @deprecated use StandardCharsets.US_ASCII instead. + */ + // TODO: Remove in Smack 4.5. + @Deprecated public static final String USASCII = "US-ASCII"; public static final String QUOTE_ENCODE = """; @@ -244,12 +260,7 @@ public class StringUtils { } public static byte[] toUtf8Bytes(String string) { - try { - return string.getBytes(StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new IllegalStateException("UTF-8 encoding not supported by platform", e); - } + return string.getBytes(StandardCharsets.UTF_8); } /** diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java index 868dd4a63..12856c29a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java @@ -19,9 +19,7 @@ package org.jivesoftware.smack.util.stringencoder; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.io.UnsupportedEncodingException; - -import org.jivesoftware.smack.util.StringUtils; +import java.nio.charset.StandardCharsets; /** * Base32 string encoding is useful for when filenames case-insensitive filesystems are encoded. @@ -55,13 +53,8 @@ public class Base32 { public static String decode(String str) { ByteArrayOutputStream bs = new ByteArrayOutputStream(); - byte[] raw; - try { - raw = str.getBytes(StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + byte[] raw = str.getBytes(StandardCharsets.UTF_8); + for (int i = 0; i < raw.length; i++) { char c = (char) raw[i]; if (!Character.isWhitespace(c)) { @@ -114,24 +107,12 @@ public class Base32 { } } - String res; - try { - res = new String(bs.toByteArray(), StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + String res = new String(bs.toByteArray(), StandardCharsets.UTF_8); return res; } public static String encode(String str) { - byte[] b; - try { - b = str.getBytes(StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + byte[] b = str.getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream os = new ByteArrayOutputStream(); for (int i = 0; i < (b.length + 4) / 5; i++) { @@ -174,13 +155,7 @@ public class Base32 { os.write(c); } } - String res; - try { - res = new String(os.toByteArray(), StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + String res = new String(os.toByteArray(), StandardCharsets.UTF_8); return res; } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64.java b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64.java index fb6ae327b..eb71b5f7f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base64.java @@ -16,10 +16,9 @@ */ package org.jivesoftware.smack.util.stringencoder; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import org.jivesoftware.smack.util.Objects; -import org.jivesoftware.smack.util.StringUtils; public class Base64 { @@ -31,11 +30,7 @@ public class Base64 { } public static final String encode(String string) { - try { - return encodeToString(string.getBytes(StringUtils.UTF8)); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("UTF-8 not supported", e); - } + return encodeToString(string.getBytes(StandardCharsets.UTF_8)); } public static final String encodeToString(byte[] input) { @@ -56,11 +51,7 @@ public class Base64 { public static final String decodeToString(String string) { byte[] bytes = decode(string); - try { - return new String(bytes, StringUtils.UTF8); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("UTF-8 not supported", e); - } + return new String(bytes, StandardCharsets.UTF_8); } // TODO: We really should not mask the IllegalArgumentException. But some unit test depend on this behavior, like @@ -74,12 +65,7 @@ public class Base64 { } public static final byte[] decode(byte[] input) { - String string; - try { - string = new String(input, StringUtils.USASCII); - } catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + String string = new String(input, StandardCharsets.US_ASCII); return decode(string); } diff --git a/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java b/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java index adf5b2bb5..f6f9ba7c6 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java @@ -19,7 +19,7 @@ package org.jivesoftware.smack.sasl; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -39,14 +39,14 @@ public class DigestMd5SaslTest extends AbstractSaslTest { super(saslMechanism); } - protected void runTest(boolean useAuthzid) throws SmackException, InterruptedException, XmppStringprepException, UnsupportedEncodingException { + protected void runTest(boolean useAuthzid) throws SmackException, InterruptedException, XmppStringprepException { EntityBareJid authzid = null; if (useAuthzid) { authzid = JidCreate.entityBareFrom("shazbat@xmpp.org"); } saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret", authzid, null); byte[] response = saslMechanism.evaluateChallenge(challengeBytes); - String responseString = new String(response, StringUtils.UTF8); + String responseString = new String(response, StandardCharsets.UTF_8); String[] responseParts = responseString.split(","); Map responsePairs = new HashMap(); for (String part : responseParts) { diff --git a/smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java b/smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java index a76087842..226cb07b0 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import org.junit.Test; @@ -72,15 +72,15 @@ public class StringUtilsTest { } @Test - public void testEncodeHex() throws UnsupportedEncodingException { + public void testEncodeHex() { String input = ""; String output = ""; - assertEquals(new String(StringUtils.encodeHex(input.getBytes(StringUtils.UTF8))), + assertEquals(new String(StringUtils.encodeHex(input.getBytes(StandardCharsets.UTF_8))), output); input = "foo bar 123"; output = "666f6f2062617220313233"; - assertEquals(new String(StringUtils.encodeHex(input.getBytes(StringUtils.UTF8))), + assertEquals(new String(StringUtils.encodeHex(input.getBytes(StandardCharsets.UTF_8))), output); } diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/hashes/HashElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/hashes/HashElementTest.java index 0a24e7aa9..1605b80d2 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/hashes/HashElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/hashes/HashElementTest.java @@ -22,6 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.nio.charset.StandardCharsets; + import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smack.test.util.TestUtils; import org.jivesoftware.smack.util.StringUtils; @@ -53,7 +55,7 @@ public class HashElementTest extends SmackTestSuite { assertTrue(element.equals(parsed)); HashElement other = new HashElement(HashManager.ALGORITHM.SHA_512, - "861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8".getBytes(StringUtils.UTF8)); + "861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8".getBytes(StandardCharsets.UTF_8)); assertFalse(element.equals(other)); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Client.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Client.java index 1aa534dc4..83965e7ca 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Client.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Client.java @@ -19,10 +19,10 @@ package org.jivesoftware.smackx.bytestreams.socks5; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -37,7 +37,6 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.SmackMessageException; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.util.CloseableUtil; -import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost; @@ -202,13 +201,7 @@ public class Socks5Client { * @return SOCKS5 connection request message */ private byte[] createSocks5ConnectRequest() { - byte[] addr; - try { - addr = digest.getBytes(StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + byte[] addr = digest.getBytes(StandardCharsets.UTF_8); byte[] data = new byte[7 + addr.length]; data[0] = (byte) 0x05; // version (SOCKS5) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java index 2acf2e8f0..bf842f7a2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java @@ -24,6 +24,7 @@ import java.net.NetworkInterface; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; @@ -39,7 +40,6 @@ import java.util.logging.Logger; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.util.CloseableUtil; -import org.jivesoftware.smack.util.StringUtils; /** * The Socks5Proxy class represents a local SOCKS5 proxy server. It can be enabled/disabled by @@ -468,7 +468,7 @@ public final class Socks5Proxy { byte[] connectionRequest = Socks5Utils.receiveSocks5Message(in); // extract digest - String responseDigest = new String(connectionRequest, 5, connectionRequest[4], StringUtils.UTF8); + String responseDigest = new String(connectionRequest, 5, connectionRequest[4], StandardCharsets.UTF_8); // return error if digest is not allowed if (!Socks5Proxy.this.allowedConnections.contains(responseDigest)) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java index 5d35cf1b5..d75cb7036 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2009 Jonas Ådahl, 2011-2014 Florian Schmaus + * Copyright © 2009 Jonas Ådahl, 2011-2019 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ */ package org.jivesoftware.smackx.caps; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Comparator; @@ -749,13 +749,7 @@ public final class EntityCapsManager extends Manager { // encoded using Base64 as specified in Section 4 of RFC 4648 // (note: the Base64 output MUST NOT include whitespace and MUST set // padding bits to zero). - byte[] bytes; - try { - bytes = sb.toString().getBytes(StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + byte[] bytes = sb.toString().getBytes(StandardCharsets.UTF_8); byte[] digest; synchronized (md) { digest = md.digest(bytes); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bob/BoBIQTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bob/BoBIQTest.java index 83a2bb08c..a1c27386e 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bob/BoBIQTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bob/BoBIQTest.java @@ -18,11 +18,12 @@ package org.jivesoftware.smackx.bob; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.nio.charset.StandardCharsets; + import org.jivesoftware.smack.packet.IQ.Type; import org.jivesoftware.smack.packet.StreamOpen; import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smack.util.PacketParserUtils; -import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.bob.element.BoBIQ; @@ -55,7 +56,7 @@ public class BoBIQTest extends SmackTestSuite { BoBIQ bobIQ = PacketParserUtils.parseStanza(sampleBoBIQResponse); BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1"); - BoBData bobData = new BoBData("image/png", "sarasade2354j2".getBytes(StringUtils.UTF8), 86400); + BoBData bobData = new BoBData("image/png", "sarasade2354j2".getBytes(StandardCharsets.UTF_8), 86400); BoBIQ createdBoBIQ = new BoBIQ(bobHash, bobData); createdBoBIQ.setStanzaId("sarasa"); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataPacketExtensionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataPacketExtensionTest.java index e35959783..b5afeb197 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataPacketExtensionTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataPacketExtensionTest.java @@ -20,11 +20,9 @@ import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Properties; -import org.jivesoftware.smack.util.StringUtils; - import org.jivesoftware.smackx.InitExtensions; import com.jamesmurty.utils.XMLBuilder; @@ -71,13 +69,13 @@ public class DataPacketExtensionTest extends InitExtensions { } @Test - public void shouldReturnNullIfDataIsInvalid() throws UnsupportedEncodingException { + public void shouldReturnNullIfDataIsInvalid() { // pad character is not at end of data DataPacketExtension data = new DataPacketExtension("sessionID", 0, "BBBB=CCC"); assertNull(data.getDecodedData()); // invalid Base64 character - data = new DataPacketExtension("sessionID", 0, new String(new byte[] { 123 }, StringUtils.UTF8)); + data = new DataPacketExtension("sessionID", 0, new String(new byte[] { 123 }, StandardCharsets.UTF_8)); assertNull(data.getDecodedData()); } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java index 430b83f5b..82f4c2d2b 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java @@ -25,10 +25,10 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.ServerSocket; import java.net.Socket; +import java.nio.charset.StandardCharsets; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.util.NetworkUtil; -import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost; @@ -238,7 +238,7 @@ public class Socks5ClientTest { // reply with full SOCKS5 message with an error code (01 = general SOCKS server // failure) out.write(new byte[] { (byte) 0x05, (byte) 0x01, (byte) 0x00, (byte) 0x03 }); - byte[] address = digest.getBytes(StringUtils.UTF8); + byte[] address = digest.getBytes(StandardCharsets.UTF_8); out.write(address.length); out.write(address); out.write(new byte[] { (byte) 0x00, (byte) 0x00 }); @@ -297,7 +297,7 @@ public class Socks5ClientTest { out.write(new byte[] { (byte) 0x05, (byte) 0x00 }); out.flush(); - byte[] address = digest.getBytes(StringUtils.UTF8); + byte[] address = digest.getBytes(StandardCharsets.UTF_8); assertEquals((byte) 0x05, (byte) in.read()); // version assertEquals((byte) 0x01, (byte) in.read()); // connect request diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java index 5380b5591..32c531f88 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java @@ -29,13 +29,12 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; -import org.jivesoftware.smack.util.StringUtils; - import org.junit.After; import org.junit.Test; @@ -281,7 +280,7 @@ public class Socks5ProxyTest { proxy.start(); assertTrue(proxy.isRunning()); - String digest = new String(new byte[] { (byte) 0xAA }, StringUtils.UTF8); + String digest = new String(new byte[] { (byte) 0xAA }, StandardCharsets.UTF_8); // add digest to allow connection proxy.addTransfer(digest); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5TestProxy.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5TestProxy.java index 6684c6f89..c40d037cf 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5TestProxy.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5TestProxy.java @@ -24,13 +24,13 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.Logger; import org.jivesoftware.smack.SmackException; -import org.jivesoftware.smack.util.StringUtils; /** * Simple SOCKS5 proxy for testing purposes. It is almost the same as the Socks5Proxy class but the @@ -297,7 +297,7 @@ public final class Socks5TestProxy { byte[] connectionRequest = Socks5Utils.receiveSocks5Message(in); // extract digest - String responseDigest = new String(connectionRequest, 5, connectionRequest[4], StringUtils.UTF8); + String responseDigest = new String(connectionRequest, 5, connectionRequest[4], StandardCharsets.UTF_8); connectionRequest[1] = (byte) 0x00; // set return status to 0 (success) out.write(connectionRequest); diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferIntegrationTest.java index b4d581647..651137694 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferIntegrationTest.java @@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.jivesoftware.smack.SmackException; @@ -48,12 +48,7 @@ public class FileTransferIntegrationTest extends AbstractSmackIntegrationTest { private static final byte[] dataToSend; static { - try { - dataToSend = StringUtils.insecureRandomString(1024 * 4 * 5).getBytes(StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + dataToSend = StringUtils.insecureRandomString(1024 * 4 * 5).getBytes(StandardCharsets.UTF_8); } @SmackIntegrationTest diff --git a/smack-java7/src/main/java/org/jivesoftware/smack/util/stringencoder/java7/Java7Base64UrlSafeEncoder.java b/smack-java7/src/main/java/org/jivesoftware/smack/util/stringencoder/java7/Java7Base64UrlSafeEncoder.java index 1d2d9a530..18869e3b9 100644 --- a/smack-java7/src/main/java/org/jivesoftware/smack/util/stringencoder/java7/Java7Base64UrlSafeEncoder.java +++ b/smack-java7/src/main/java/org/jivesoftware/smack/util/stringencoder/java7/Java7Base64UrlSafeEncoder.java @@ -16,10 +16,9 @@ */ package org.jivesoftware.smack.util.stringencoder.java7; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Base64; -import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.stringencoder.StringEncoder; @@ -52,25 +51,14 @@ public final class Java7Base64UrlSafeEncoder implements StringEncoder { @Override public String encode(String s) { - byte[] bytes; - try { - bytes = s.getBytes(StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + byte[] bytes = s.getBytes(StandardCharsets.UTF_8); return encoder.encodeToString(bytes); } @Override public String decode(String s) { byte[] bytes = decoder.decode(s); - try { - return new String(bytes, StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + return new String(bytes, StandardCharsets.UTF_8); } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/HttpServer.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/HttpServer.java index 848485e8a..f011dc46c 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/HttpServer.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/HttpServer.java @@ -23,12 +23,11 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; +import java.nio.charset.StandardCharsets; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; -import org.jivesoftware.smack.util.StringUtils; - /** * A very Simple HTTP Server. */ @@ -88,7 +87,7 @@ public class HttpServer { this.socket = socket; this.input = socket.getInputStream(); this.output = socket.getOutputStream(); - this.br = new BufferedReader(new InputStreamReader(socket.getInputStream(), StringUtils.UTF8)); + this.br = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8)); } @Override @@ -122,16 +121,16 @@ public class HttpServer { + entityBody.length() + CRLF; contentTypeLine = "text/html"; - output.write(statusLine.getBytes(StringUtils.UTF8)); + output.write(statusLine.getBytes(StandardCharsets.UTF_8)); - output.write(serverLine.getBytes(StringUtils.UTF8)); + output.write(serverLine.getBytes(StandardCharsets.UTF_8)); - output.write(contentTypeLine.getBytes(StringUtils.UTF8)); - output.write(contentLengthLine.getBytes(StringUtils.UTF8)); + output.write(contentTypeLine.getBytes(StandardCharsets.UTF_8)); + output.write(contentLengthLine.getBytes(StandardCharsets.UTF_8)); - output.write(CRLF.getBytes(StringUtils.UTF8)); + output.write(CRLF.getBytes(StandardCharsets.UTF_8)); - output.write(entityBody.getBytes(StringUtils.UTF8)); + output.write(entityBody.getBytes(StandardCharsets.UTF_8)); } } diff --git a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoRatchet.java b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoRatchet.java index 2dee41a43..36befe824 100644 --- a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoRatchet.java +++ b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoRatchet.java @@ -16,7 +16,7 @@ */ package org.jivesoftware.smackx.omemo; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -25,8 +25,6 @@ import java.util.logging.Logger; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; -import org.jivesoftware.smack.util.StringUtils; - import org.jivesoftware.smackx.omemo.element.OmemoElement; import org.jivesoftware.smackx.omemo.element.OmemoKeyElement; import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException; @@ -169,10 +167,9 @@ public abstract class OmemoRatchet(userDevice, gullibleTrustCallback, getOmemoRatchet(manager), messageKey, iv, null); - } catch (InvalidKeyException | InvalidAlgorithmParameterException | NoSuchPaddingException | BadPaddingException | UnsupportedEncodingException | IllegalBlockSizeException e) { + } catch (InvalidKeyException | InvalidAlgorithmParameterException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e) { throw new CryptoFailedException(e); } @@ -371,7 +370,7 @@ public abstract class OmemoService( userDevice, manager.getTrustCallback(), getOmemoRatchet(managerGuard.get()), messageKey, iv, message); - } catch (UnsupportedEncodingException | BadPaddingException | IllegalBlockSizeException | + } catch (BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException e) { throw new CryptoFailedException(e); } diff --git a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/util/OmemoMessageBuilder.java b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/util/OmemoMessageBuilder.java index da361623b..197aab42d 100644 --- a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/util/OmemoMessageBuilder.java +++ b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/util/OmemoMessageBuilder.java @@ -21,6 +21,7 @@ import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYLENGTH import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYTYPE; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -37,8 +38,6 @@ import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; -import org.jivesoftware.smack.util.StringUtils; - import org.jivesoftware.smackx.omemo.OmemoRatchet; import org.jivesoftware.smackx.omemo.OmemoService; import org.jivesoftware.smackx.omemo.element.OmemoElement; @@ -96,7 +95,6 @@ public class OmemoMessageBuilder preKeysB64 = new HashMap<>(); preKeysB64.put(preKeyId1, preKey1B64); preKeysB64.put(preKeyId2, preKey2B64); @@ -80,11 +80,11 @@ public class OmemoBundleVAxolotlElementTest extends SmackTestSuite { String actual = bundle.toXML().toString(); assertEquals("Bundles XML must match.", expected, actual); - byte[] signedPreKey = "SignedPreKey".getBytes(StringUtils.UTF8); - byte[] signedPreKeySig = "SignedPreKeySignature".getBytes(StringUtils.UTF8); - byte[] identityKey = "IdentityKey".getBytes(StringUtils.UTF8); - byte[] firstPreKey = "FirstPreKey".getBytes(StringUtils.UTF8); - byte[] secondPreKey = "SecondPreKey".getBytes(StringUtils.UTF8); + byte[] signedPreKey = "SignedPreKey".getBytes(StandardCharsets.UTF_8); + byte[] signedPreKeySig = "SignedPreKeySignature".getBytes(StandardCharsets.UTF_8); + byte[] identityKey = "IdentityKey".getBytes(StandardCharsets.UTF_8); + byte[] firstPreKey = "FirstPreKey".getBytes(StandardCharsets.UTF_8); + byte[] secondPreKey = "SecondPreKey".getBytes(StandardCharsets.UTF_8); OmemoBundleElement_VAxolotl parsed = new OmemoBundleVAxolotlProvider().parse(TestUtils.getParser(actual)); diff --git a/smack-omemo/src/test/java/org/jivesoftware/smackx/omemo/OmemoVAxolotlElementTest.java b/smack-omemo/src/test/java/org/jivesoftware/smackx/omemo/OmemoVAxolotlElementTest.java index c2d10b862..1d4e1a49e 100644 --- a/smack-omemo/src/test/java/org/jivesoftware/smackx/omemo/OmemoVAxolotlElementTest.java +++ b/smack-omemo/src/test/java/org/jivesoftware/smackx/omemo/OmemoVAxolotlElementTest.java @@ -18,11 +18,11 @@ package org.jivesoftware.smackx.omemo; import static org.junit.Assert.assertEquals; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smack.test.util.TestUtils; -import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.stringencoder.Base64; import org.jivesoftware.smackx.omemo.element.OmemoElement_VAxolotl; @@ -40,11 +40,11 @@ public class OmemoVAxolotlElementTest extends SmackTestSuite { @Test public void serializationTest() throws Exception { - byte[] payload = "This is payload.".getBytes(StringUtils.UTF8); + byte[] payload = "This is payload.".getBytes(StandardCharsets.UTF_8); int keyId1 = 8; int keyId2 = 33333; - byte[] keyData1 = "KEYDATA".getBytes(StringUtils.UTF8); - byte[] keyData2 = "DATAKEY".getBytes(StringUtils.UTF8); + byte[] keyData1 = "KEYDATA".getBytes(StandardCharsets.UTF_8); + byte[] keyData2 = "DATAKEY".getBytes(StandardCharsets.UTF_8); int sid = 12131415; byte[] iv = OmemoMessageBuilder.generateIv(); diff --git a/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Mechanism.java b/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Mechanism.java index 97ff9c27c..4c5ba0ee2 100644 --- a/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Mechanism.java +++ b/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Mechanism.java @@ -16,7 +16,7 @@ */ package org.jivesoftware.smack.sasl.provided; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import javax.security.auth.callback.CallbackHandler; @@ -103,13 +103,7 @@ public class SASLDigestMD5Mechanism extends SASLMechanism { if (challenge.length == 0) { throw new SmackSaslException("Initial challenge has zero length"); } - String challengeString; - try { - challengeString = new String(challenge, StringUtils.UTF8); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + String challengeString = new String(challenge, StandardCharsets.UTF_8); String[] challengeParts = challengeString.split(","); byte[] response = null; switch (state) {