1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Use StandardCharsets.(UTF_8|US_ASCII)

This also gets rid of a ton of UnsupportedEncodingException s.
This commit is contained in:
Florian Schmaus 2019-05-08 11:34:40 +02:00
parent 2a4d110b22
commit d2f5efcb20
33 changed files with 125 additions and 227 deletions

View file

@ -1,7 +1,7 @@
language: android language: android
android: android:
components: components:
- android-16 - android-19
jdk: jdk:
- oraclejdk8 - oraclejdk8
- openjdk8 - openjdk8

View file

@ -705,15 +705,7 @@ def getGitCommit() {
} }
def getAndroidRuntimeJar() { def getAndroidRuntimeJar() {
// We set a different Android API level compared to def androidApiLevel = ext.smackMinAndroidSdk
// 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 androidHome = getAndroidHome() def androidHome = getAndroidHome()
def androidJar = new File("$androidHome/platforms/android-${androidApiLevel}/android.jar") def androidJar = new File("$androidHome/platforms/android-${androidApiLevel}/android.jar")
if (androidJar.isFile()) { if (androidJar.isFile()) {

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright © 2014-2018 Florian Schmaus * Copyright © 2014-2019 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; 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 org.jivesoftware.smack.util.stringencoder.StringEncoder;
import android.util.Base64; import android.util.Base64;
@ -39,21 +38,13 @@ public final class AndroidBase64UrlSafeEncoder implements StringEncoder<String>
@Override @Override
public String encode(String string) { public String encode(String string) {
try { return Base64.encodeToString(string.getBytes(StandardCharsets.UTF_8), BASE64_ENCODER_FLAGS);
return Base64.encodeToString(string.getBytes(StringUtils.UTF8), BASE64_ENCODER_FLAGS);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("UTF-8 not supported", e);
}
} }
@Override @Override
public String decode(String string) { public String decode(String string) {
byte[] bytes = Base64.decode(string, BASE64_ENCODER_FLAGS); byte[] bytes = Base64.decode(string, BASE64_ENCODER_FLAGS);
try { return new String(bytes, StandardCharsets.UTF_8);
return new String(bytes, StringUtils.UTF8);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("UTF-8 not supported", e);
}
} }
} }

View file

@ -23,6 +23,7 @@ import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.KeyStoreException; import java.security.KeyStoreException;
@ -2044,7 +2045,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
try { try {
Constructor<?> c = Class.forName("sun.security.pkcs11.SunPKCS11").getConstructor(InputStream.class); Constructor<?> c = Class.forName("sun.security.pkcs11.SunPKCS11").getConstructor(InputStream.class);
String pkcs11Config = "name = SmartCard\nlibrary = " + config.getPKCS11Library(); 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); Provider p = (Provider) c.newInstance(config);
Security.addProvider(p); Security.addProvider(p);
ks = KeyStore.getInstance("PKCS11",p); ks = KeyStore.getInstance("PKCS11",p);

View file

@ -20,6 +20,7 @@ package org.jivesoftware.smack;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.logging.Level; 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.CloseableUtil;
import org.jivesoftware.smack.util.FileUtils; import org.jivesoftware.smack.util.FileUtils;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.xml.XmlPullParser; import org.jivesoftware.smack.xml.XmlPullParser;
@ -69,7 +69,7 @@ public final class SmackInitialization {
String smackVersion; String smackVersion;
BufferedReader reader = null; BufferedReader reader = null;
try { 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(); smackVersion = reader.readLine();
} catch (Exception e) { } catch (Exception e) {
LOGGER.log(Level.SEVERE, "Could not determine Smack version", e); LOGGER.log(Level.SEVERE, "Could not determine Smack version", e);

View file

@ -22,8 +22,7 @@ import java.io.OutputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import org.jivesoftware.smack.util.StringUtils;
/** /**
* Socket factory for socks4 proxy. * Socket factory for socks4 proxy.
@ -86,7 +85,7 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
} }
if (user != null) { if (user != null) {
byte[] userBytes = user.getBytes(StringUtils.UTF8); byte[] userBytes = user.getBytes(StandardCharsets.UTF_8);
System.arraycopy(userBytes, 0, buf, index, user.length()); System.arraycopy(userBytes, 0, buf, index, user.length());
index += user.length(); index += user.length();
} }

View file

@ -21,10 +21,10 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.util.CloseableUtil; import org.jivesoftware.smack.util.CloseableUtil;
import org.jivesoftware.smack.util.StringUtils;
/** /**
* Socket factory for Socks5 proxy. * Socket factory for Socks5 proxy.
@ -133,11 +133,11 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
index = 0; index = 0;
buf[index++] = 1; buf[index++] = 1;
buf[index++] = (byte) user.length(); buf[index++] = (byte) user.length();
byte[] userBytes = user.getBytes(StringUtils.UTF8); byte[] userBytes = user.getBytes(StandardCharsets.UTF_8);
System.arraycopy(userBytes, 0, buf, index, System.arraycopy(userBytes, 0, buf, index,
user.length()); user.length());
index += user.length(); index += user.length();
byte[] passwordBytes = passwd.getBytes(StringUtils.UTF8); byte[] passwordBytes = passwd.getBytes(StandardCharsets.UTF_8);
buf[index++] = (byte) passwordBytes.length; buf[index++] = (byte) passwordBytes.length;
System.arraycopy(passwordBytes, 0, buf, index, System.arraycopy(passwordBytes, 0, buf, index,
passwd.length()); passwd.length());
@ -204,7 +204,7 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
buf[index++] = 1; // CONNECT buf[index++] = 1; // CONNECT
buf[index++] = 0; buf[index++] = 0;
byte[] hostb = host.getBytes(StringUtils.UTF8); byte[] hostb = host.getBytes(StandardCharsets.UTF_8);
int len = hostb.length; int len = hostb.length;
buf[index++] = 3; // DOMAINNAME buf[index++] = 3; // DOMAINNAME
buf[index++] = (byte) len; buf[index++] = (byte) len;

View file

@ -16,7 +16,7 @@
*/ */
package org.jivesoftware.smack.sasl.core; package org.jivesoftware.smack.sasl.core;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Collections; import java.util.Collections;
@ -114,14 +114,8 @@ public abstract class ScramMechanism extends SASLMechanism {
@Override @Override
protected byte[] evaluateChallenge(byte[] challenge) throws SmackSaslException { protected byte[] evaluateChallenge(byte[] challenge) throws SmackSaslException {
String challengeString;
try {
// TODO: Where is it specified that this is an UTF-8 encoded string? // TODO: Where is it specified that this is an UTF-8 encoded string?
challengeString = new String(challenge, StringUtils.UTF8); String challengeString = new String(challenge, StandardCharsets.UTF_8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
switch (state) { switch (state) {
case AUTH_TEXT_SENT: case AUTH_TEXT_SENT:
@ -386,14 +380,9 @@ public abstract class ScramMechanism extends SASLMechanism {
* @throws SmackSaslException if a SASL related error occurs. * @throws SmackSaslException if a SASL related error occurs.
*/ */
private byte[] hi(String normalizedPassword, byte[] salt, int iterations) throws SmackSaslException { 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. // According to RFC 5802 § 2.2, the resulting string of the normalization is also in UTF-8.
key = normalizedPassword.getBytes(StringUtils.UTF8); byte[] key = normalizedPassword.getBytes(StandardCharsets.UTF_8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError();
}
// U1 := HMAC(str, salt + INT(1)) // U1 := HMAC(str, salt + INT(1))
byte[] u = hmac(key, ByteUtils.concat(salt, ONE)); byte[] u = hmac(key, ByteUtils.concat(salt, ONE));
byte[] res = u.clone(); byte[] res = u.clone();

View file

@ -30,6 +30,7 @@ import java.io.Reader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -90,7 +91,7 @@ public final class FileUtils {
public static boolean addLines(String uriString, Set<String> set) throws MalformedURLException, IOException { public static boolean addLines(String uriString, Set<String> set) throws MalformedURLException, IOException {
URI uri = URI.create(uriString); URI uri = URI.create(uriString);
InputStream is = getStreamForUri(uri, null); 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); BufferedReader br = new BufferedReader(sr);
try { try {
String line; String line;

View file

@ -21,7 +21,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -71,12 +71,7 @@ public class PacketParserUtils {
} }
public static XmlPullParser getParserFor(InputStream inputStream) throws XmlPullParserException { public static XmlPullParser getParserFor(InputStream inputStream) throws XmlPullParserException {
InputStreamReader inputStreamReader; InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
try {
inputStreamReader = new InputStreamReader(inputStream, StringUtils.UTF8);
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
return SmackXmlParser.newXmlParser(inputStreamReader); return SmackXmlParser.newXmlParser(inputStreamReader);
} }

View file

@ -17,7 +17,7 @@
package org.jivesoftware.smack.util; package org.jivesoftware.smack.util;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random; import java.util.Random;
@ -29,7 +29,23 @@ public class StringUtils {
public static final String MD5 = "MD5"; public static final String MD5 = "MD5";
public static final String SHA1 = "SHA-1"; 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"; 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 USASCII = "US-ASCII";
public static final String QUOTE_ENCODE = "&quot;"; public static final String QUOTE_ENCODE = "&quot;";
@ -244,12 +260,7 @@ public class StringUtils {
} }
public static byte[] toUtf8Bytes(String string) { public static byte[] toUtf8Bytes(String string) {
try { return string.getBytes(StandardCharsets.UTF_8);
return string.getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new IllegalStateException("UTF-8 encoding not supported by platform", e);
}
} }
/** /**

View file

@ -19,9 +19,7 @@ package org.jivesoftware.smack.util.stringencoder;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import org.jivesoftware.smack.util.StringUtils;
/** /**
* Base32 string encoding is useful for when filenames case-insensitive filesystems are encoded. * 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) { public static String decode(String str) {
ByteArrayOutputStream bs = new ByteArrayOutputStream(); ByteArrayOutputStream bs = new ByteArrayOutputStream();
byte[] raw; byte[] raw = str.getBytes(StandardCharsets.UTF_8);
try {
raw = str.getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
for (int i = 0; i < raw.length; i++) { for (int i = 0; i < raw.length; i++) {
char c = (char) raw[i]; char c = (char) raw[i];
if (!Character.isWhitespace(c)) { if (!Character.isWhitespace(c)) {
@ -114,24 +107,12 @@ public class Base32 {
} }
} }
String res; String res = new String(bs.toByteArray(), StandardCharsets.UTF_8);
try {
res = new String(bs.toByteArray(), StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
return res; return res;
} }
public static String encode(String str) { public static String encode(String str) {
byte[] b; byte[] b = str.getBytes(StandardCharsets.UTF_8);
try {
b = str.getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
for (int i = 0; i < (b.length + 4) / 5; i++) { for (int i = 0; i < (b.length + 4) / 5; i++) {
@ -174,13 +155,7 @@ public class Base32 {
os.write(c); os.write(c);
} }
} }
String res; String res = new String(os.toByteArray(), StandardCharsets.UTF_8);
try {
res = new String(os.toByteArray(), StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
return res; return res;
} }

View file

@ -16,10 +16,9 @@
*/ */
package org.jivesoftware.smack.util.stringencoder; 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.Objects;
import org.jivesoftware.smack.util.StringUtils;
public class Base64 { public class Base64 {
@ -31,11 +30,7 @@ public class Base64 {
} }
public static final String encode(String string) { public static final String encode(String string) {
try { return encodeToString(string.getBytes(StandardCharsets.UTF_8));
return encodeToString(string.getBytes(StringUtils.UTF8));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("UTF-8 not supported", e);
}
} }
public static final String encodeToString(byte[] input) { public static final String encodeToString(byte[] input) {
@ -56,11 +51,7 @@ public class Base64 {
public static final String decodeToString(String string) { public static final String decodeToString(String string) {
byte[] bytes = decode(string); byte[] bytes = decode(string);
try { return new String(bytes, StandardCharsets.UTF_8);
return new String(bytes, StringUtils.UTF8);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("UTF-8 not supported", e);
}
} }
// TODO: We really should not mask the IllegalArgumentException. But some unit test depend on this behavior, like // 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) { public static final byte[] decode(byte[] input) {
String string; String string = new String(input, StandardCharsets.US_ASCII);
try {
string = new String(input, StringUtils.USASCII);
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
return decode(string); return decode(string);
} }

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smack.sasl;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -39,14 +39,14 @@ public class DigestMd5SaslTest extends AbstractSaslTest {
super(saslMechanism); super(saslMechanism);
} }
protected void runTest(boolean useAuthzid) throws SmackException, InterruptedException, XmppStringprepException, UnsupportedEncodingException { protected void runTest(boolean useAuthzid) throws SmackException, InterruptedException, XmppStringprepException {
EntityBareJid authzid = null; EntityBareJid authzid = null;
if (useAuthzid) { if (useAuthzid) {
authzid = JidCreate.entityBareFrom("shazbat@xmpp.org"); authzid = JidCreate.entityBareFrom("shazbat@xmpp.org");
} }
saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret", authzid, null); saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret", authzid, null);
byte[] response = saslMechanism.evaluateChallenge(challengeBytes); byte[] response = saslMechanism.evaluateChallenge(challengeBytes);
String responseString = new String(response, StringUtils.UTF8); String responseString = new String(response, StandardCharsets.UTF_8);
String[] responseParts = responseString.split(","); String[] responseParts = responseString.split(",");
Map<String, String> responsePairs = new HashMap<String, String>(); Map<String, String> responsePairs = new HashMap<String, String>();
for (String part : responseParts) { for (String part : responseParts) {

View file

@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import org.junit.Test; import org.junit.Test;
@ -72,15 +72,15 @@ public class StringUtilsTest {
} }
@Test @Test
public void testEncodeHex() throws UnsupportedEncodingException { public void testEncodeHex() {
String input = ""; String input = "";
String output = ""; String output = "";
assertEquals(new String(StringUtils.encodeHex(input.getBytes(StringUtils.UTF8))), assertEquals(new String(StringUtils.encodeHex(input.getBytes(StandardCharsets.UTF_8))),
output); output);
input = "foo bar 123"; input = "foo bar 123";
output = "666f6f2062617220313233"; output = "666f6f2062617220313233";
assertEquals(new String(StringUtils.encodeHex(input.getBytes(StringUtils.UTF8))), assertEquals(new String(StringUtils.encodeHex(input.getBytes(StandardCharsets.UTF_8))),
output); output);
} }

View file

@ -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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; 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.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils; import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
@ -53,7 +55,7 @@ public class HashElementTest extends SmackTestSuite {
assertTrue(element.equals(parsed)); assertTrue(element.equals(parsed));
HashElement other = new HashElement(HashManager.ALGORITHM.SHA_512, HashElement other = new HashElement(HashManager.ALGORITHM.SHA_512,
"861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8".getBytes(StringUtils.UTF8)); "861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8".getBytes(StandardCharsets.UTF_8));
assertFalse(element.equals(other)); assertFalse(element.equals(other));
} }

View file

@ -19,10 +19,10 @@ package org.jivesoftware.smackx.bytestreams.socks5;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; 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.SmackException.SmackMessageException;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.util.CloseableUtil; import org.jivesoftware.smack.util.CloseableUtil;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
@ -202,13 +201,7 @@ public class Socks5Client {
* @return SOCKS5 connection request message * @return SOCKS5 connection request message
*/ */
private byte[] createSocks5ConnectRequest() { private byte[] createSocks5ConnectRequest() {
byte[] addr; byte[] addr = digest.getBytes(StandardCharsets.UTF_8);
try {
addr = digest.getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
byte[] data = new byte[7 + addr.length]; byte[] data = new byte[7 + addr.length];
data[0] = (byte) 0x05; // version (SOCKS5) data[0] = (byte) 0x05; // version (SOCKS5)

View file

@ -24,6 +24,7 @@ import java.net.NetworkInterface;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException; import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
@ -39,7 +40,6 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.util.CloseableUtil; 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 * 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); byte[] connectionRequest = Socks5Utils.receiveSocks5Message(in);
// extract digest // 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 // return error if digest is not allowed
if (!Socks5Proxy.this.allowedConnections.contains(responseDigest)) { if (!Socks5Proxy.this.allowedConnections.contains(responseDigest)) {

View file

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,7 @@
*/ */
package org.jivesoftware.smackx.caps; package org.jivesoftware.smackx.caps;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Comparator; 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 // encoded using Base64 as specified in Section 4 of RFC 4648
// (note: the Base64 output MUST NOT include whitespace and MUST set // (note: the Base64 output MUST NOT include whitespace and MUST set
// padding bits to zero). // padding bits to zero).
byte[] bytes; byte[] bytes = sb.toString().getBytes(StandardCharsets.UTF_8);
try {
bytes = sb.toString().getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
byte[] digest; byte[] digest;
synchronized (md) { synchronized (md) {
digest = md.digest(bytes); digest = md.digest(bytes);

View file

@ -18,11 +18,12 @@ package org.jivesoftware.smackx.bob;
import static org.junit.jupiter.api.Assertions.assertEquals; 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.IQ.Type;
import org.jivesoftware.smack.packet.StreamOpen; import org.jivesoftware.smack.packet.StreamOpen;
import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.bob.element.BoBIQ; import org.jivesoftware.smackx.bob.element.BoBIQ;
@ -55,7 +56,7 @@ public class BoBIQTest extends SmackTestSuite {
BoBIQ bobIQ = PacketParserUtils.parseStanza(sampleBoBIQResponse); BoBIQ bobIQ = PacketParserUtils.parseStanza(sampleBoBIQResponse);
BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1"); 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); BoBIQ createdBoBIQ = new BoBIQ(bobHash, bobData);
createdBoBIQ.setStanzaId("sarasa"); createdBoBIQ.setStanzaId("sarasa");

View file

@ -20,11 +20,9 @@ import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.util.Properties; import java.util.Properties;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.InitExtensions; import org.jivesoftware.smackx.InitExtensions;
import com.jamesmurty.utils.XMLBuilder; import com.jamesmurty.utils.XMLBuilder;
@ -71,13 +69,13 @@ public class DataPacketExtensionTest extends InitExtensions {
} }
@Test @Test
public void shouldReturnNullIfDataIsInvalid() throws UnsupportedEncodingException { public void shouldReturnNullIfDataIsInvalid() {
// pad character is not at end of data // pad character is not at end of data
DataPacketExtension data = new DataPacketExtension("sessionID", 0, "BBBB=CCC"); DataPacketExtension data = new DataPacketExtension("sessionID", 0, "BBBB=CCC");
assertNull(data.getDecodedData()); assertNull(data.getDecodedData());
// invalid Base64 character // 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()); assertNull(data.getDecodedData());
} }

View file

@ -25,10 +25,10 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.util.NetworkUtil; import org.jivesoftware.smack.util.NetworkUtil;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost; 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 // reply with full SOCKS5 message with an error code (01 = general SOCKS server
// failure) // failure)
out.write(new byte[] { (byte) 0x05, (byte) 0x01, (byte) 0x00, (byte) 0x03 }); 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.length);
out.write(address); out.write(address);
out.write(new byte[] { (byte) 0x00, (byte) 0x00 }); out.write(new byte[] { (byte) 0x00, (byte) 0x00 });
@ -297,7 +297,7 @@ public class Socks5ClientTest {
out.write(new byte[] { (byte) 0x05, (byte) 0x00 }); out.write(new byte[] { (byte) 0x05, (byte) 0x00 });
out.flush(); out.flush();
byte[] address = digest.getBytes(StringUtils.UTF8); byte[] address = digest.getBytes(StandardCharsets.UTF_8);
assertEquals((byte) 0x05, (byte) in.read()); // version assertEquals((byte) 0x05, (byte) in.read()); // version
assertEquals((byte) 0x01, (byte) in.read()); // connect request assertEquals((byte) 0x01, (byte) in.read()); // connect request

View file

@ -29,13 +29,12 @@ import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException; import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import org.jivesoftware.smack.util.StringUtils;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
@ -281,7 +280,7 @@ public class Socks5ProxyTest {
proxy.start(); proxy.start();
assertTrue(proxy.isRunning()); 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 // add digest to allow connection
proxy.addTransfer(digest); proxy.addTransfer(digest);

View file

@ -24,13 +24,13 @@ import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException; import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException; 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 * 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); byte[] connectionRequest = Socks5Utils.receiveSocks5Message(in);
// extract digest // 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) connectionRequest[1] = (byte) 0x00; // set return status to 0 (success)
out.write(connectionRequest); out.write(connectionRequest);

View file

@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
@ -48,12 +48,7 @@ public class FileTransferIntegrationTest extends AbstractSmackIntegrationTest {
private static final byte[] dataToSend; private static final byte[] dataToSend;
static { static {
try { dataToSend = StringUtils.insecureRandomString(1024 * 4 * 5).getBytes(StandardCharsets.UTF_8);
dataToSend = StringUtils.insecureRandomString(1024 * 4 * 5).getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
} }
@SmackIntegrationTest @SmackIntegrationTest

View file

@ -16,10 +16,9 @@
*/ */
package org.jivesoftware.smack.util.stringencoder.java7; package org.jivesoftware.smack.util.stringencoder.java7;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.util.Base64; import java.util.Base64;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.stringencoder.StringEncoder; import org.jivesoftware.smack.util.stringencoder.StringEncoder;
@ -52,25 +51,14 @@ public final class Java7Base64UrlSafeEncoder implements StringEncoder<String> {
@Override @Override
public String encode(String s) { public String encode(String s) {
byte[] bytes; byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
try {
bytes = s.getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
return encoder.encodeToString(bytes); return encoder.encodeToString(bytes);
} }
@Override @Override
public String decode(String s) { public String decode(String s) {
byte[] bytes = decoder.decode(s); byte[] bytes = decoder.decode(s);
try { return new String(bytes, StandardCharsets.UTF_8);
return new String(bytes, StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
} }
} }

View file

@ -23,12 +23,11 @@ import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.util.StringUtils;
/** /**
* A very Simple HTTP Server. * A very Simple HTTP Server.
*/ */
@ -88,7 +87,7 @@ public class HttpServer {
this.socket = socket; this.socket = socket;
this.input = socket.getInputStream(); this.input = socket.getInputStream();
this.output = socket.getOutputStream(); 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 @Override
@ -122,16 +121,16 @@ public class HttpServer {
+ entityBody.length() + CRLF; + entityBody.length() + CRLF;
contentTypeLine = "text/html"; 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(contentTypeLine.getBytes(StandardCharsets.UTF_8));
output.write(contentLengthLine.getBytes(StringUtils.UTF8)); 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));
} }
} }

View file

@ -16,7 +16,7 @@
*/ */
package org.jivesoftware.smackx.omemo; package org.jivesoftware.smackx.omemo;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -25,8 +25,6 @@ import java.util.logging.Logger;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.omemo.element.OmemoElement; import org.jivesoftware.smackx.omemo.element.OmemoElement;
import org.jivesoftware.smackx.omemo.element.OmemoKeyElement; import org.jivesoftware.smackx.omemo.element.OmemoKeyElement;
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException; import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
@ -169,10 +167,9 @@ public abstract class OmemoRatchet<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
byte[] encryptedBody = payloadAndAuthTag(element, cipherAndAuthTag.getAuthTag()); byte[] encryptedBody = payloadAndAuthTag(element, cipherAndAuthTag.getAuthTag());
try { try {
String plaintext = new String(cipherAndAuthTag.getCipher().doFinal(encryptedBody), StringUtils.UTF8); String plaintext = new String(cipherAndAuthTag.getCipher().doFinal(encryptedBody), StandardCharsets.UTF_8);
return plaintext; return plaintext;
} catch (IllegalBlockSizeException | BadPaddingException e) {
} catch (UnsupportedEncodingException | IllegalBlockSizeException | BadPaddingException e) {
throw new CryptoFailedException("decryptMessageElement could not decipher message body: " throw new CryptoFailedException("decryptMessageElement could not decipher message body: "
+ e.getMessage()); + e.getMessage());
} }

View file

@ -19,7 +19,6 @@ package org.jivesoftware.smackx.omemo;
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYLENGTH; import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYLENGTH;
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYTYPE; import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYTYPE;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -309,7 +308,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
try { try {
builder = new OmemoMessageBuilder<>(userDevice, gullibleTrustCallback, getOmemoRatchet(manager), builder = new OmemoMessageBuilder<>(userDevice, gullibleTrustCallback, getOmemoRatchet(manager),
messageKey, iv, null); messageKey, iv, null);
} catch (InvalidKeyException | InvalidAlgorithmParameterException | NoSuchPaddingException | BadPaddingException | UnsupportedEncodingException | IllegalBlockSizeException e) { } catch (InvalidKeyException | InvalidAlgorithmParameterException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e) {
throw new CryptoFailedException(e); throw new CryptoFailedException(e);
} }
@ -371,7 +370,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
try { try {
builder = new OmemoMessageBuilder<>( builder = new OmemoMessageBuilder<>(
userDevice, manager.getTrustCallback(), getOmemoRatchet(managerGuard.get()), messageKey, iv, message); userDevice, manager.getTrustCallback(), getOmemoRatchet(managerGuard.get()), messageKey, iv, message);
} catch (UnsupportedEncodingException | BadPaddingException | IllegalBlockSizeException | } catch (BadPaddingException | IllegalBlockSizeException |
NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException e) { NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException e) {
throw new CryptoFailedException(e); throw new CryptoFailedException(e);
} }

View file

@ -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 static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYTYPE;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -37,8 +38,6 @@ import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.omemo.OmemoRatchet; import org.jivesoftware.smackx.omemo.OmemoRatchet;
import org.jivesoftware.smackx.omemo.OmemoService; import org.jivesoftware.smackx.omemo.OmemoService;
import org.jivesoftware.smackx.omemo.element.OmemoElement; import org.jivesoftware.smackx.omemo.element.OmemoElement;
@ -96,7 +95,6 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
* @throws InvalidKeyException * @throws InvalidKeyException
* @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
* @throws IllegalBlockSizeException * @throws IllegalBlockSizeException
* @throws UnsupportedEncodingException
* @throws InvalidAlgorithmParameterException * @throws InvalidAlgorithmParameterException
*/ */
public OmemoMessageBuilder(OmemoDevice userDevice, public OmemoMessageBuilder(OmemoDevice userDevice,
@ -107,7 +105,7 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
String message) String message)
throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException,
IllegalBlockSizeException, IllegalBlockSizeException,
UnsupportedEncodingException, InvalidAlgorithmParameterException { InvalidAlgorithmParameterException {
this.userDevice = userDevice; this.userDevice = userDevice;
this.trustCallback = callback; this.trustCallback = callback;
this.ratchet = ratchet; this.ratchet = ratchet;
@ -152,11 +150,12 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
* @throws NoSuchProviderException * @throws NoSuchProviderException
* @throws InvalidAlgorithmParameterException * @throws InvalidAlgorithmParameterException
* @throws InvalidKeyException * @throws InvalidKeyException
* @throws UnsupportedEncodingException
* @throws BadPaddingException * @throws BadPaddingException
* @throws IllegalBlockSizeException * @throws IllegalBlockSizeException
*/ */
private void setMessage(String message) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, UnsupportedEncodingException, BadPaddingException, IllegalBlockSizeException { private void setMessage(String message)
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
if (message == null) { if (message == null) {
return; return;
} }
@ -170,7 +169,7 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
byte[] body; byte[] body;
byte[] ciphertext; byte[] ciphertext;
body = message.getBytes(StringUtils.UTF8); body = message.getBytes(StandardCharsets.UTF_8);
ciphertext = cipher.doFinal(body); ciphertext = cipher.doFinal(body);
byte[] clearKeyWithAuthTag = new byte[messageKey.length + 16]; byte[] clearKeyWithAuthTag = new byte[messageKey.length + 16];

View file

@ -19,12 +19,12 @@ package org.jivesoftware.smackx.omemo;
import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils; import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.stringencoder.Base64; import org.jivesoftware.smack.util.stringencoder.Base64;
import org.jivesoftware.smack.xml.XmlPullParser; import org.jivesoftware.smack.xml.XmlPullParser;
@ -41,12 +41,12 @@ public class OmemoBundleVAxolotlElementTest extends SmackTestSuite {
@Test @Test
public void serializationTest() throws Exception { public void serializationTest() throws Exception {
int signedPreKeyId = 420; int signedPreKeyId = 420;
String signedPreKeyB64 = Base64.encodeToString("SignedPreKey".getBytes(StringUtils.UTF8)); String signedPreKeyB64 = Base64.encodeToString("SignedPreKey".getBytes(StandardCharsets.UTF_8));
String signedPreKeySigB64 = Base64.encodeToString("SignedPreKeySignature".getBytes(StringUtils.UTF8)); String signedPreKeySigB64 = Base64.encodeToString("SignedPreKeySignature".getBytes(StandardCharsets.UTF_8));
String identityKeyB64 = Base64.encodeToString("IdentityKey".getBytes(StringUtils.UTF8)); String identityKeyB64 = Base64.encodeToString("IdentityKey".getBytes(StandardCharsets.UTF_8));
int preKeyId1 = 220, preKeyId2 = 284; int preKeyId1 = 220, preKeyId2 = 284;
String preKey1B64 = Base64.encodeToString("FirstPreKey".getBytes(StringUtils.UTF8)), String preKey1B64 = Base64.encodeToString("FirstPreKey".getBytes(StandardCharsets.UTF_8)),
preKey2B64 = Base64.encodeToString("SecondPreKey".getBytes(StringUtils.UTF8)); preKey2B64 = Base64.encodeToString("SecondPreKey".getBytes(StandardCharsets.UTF_8));
HashMap<Integer, String> preKeysB64 = new HashMap<>(); HashMap<Integer, String> preKeysB64 = new HashMap<>();
preKeysB64.put(preKeyId1, preKey1B64); preKeysB64.put(preKeyId1, preKey1B64);
preKeysB64.put(preKeyId2, preKey2B64); preKeysB64.put(preKeyId2, preKey2B64);
@ -80,11 +80,11 @@ public class OmemoBundleVAxolotlElementTest extends SmackTestSuite {
String actual = bundle.toXML().toString(); String actual = bundle.toXML().toString();
assertEquals("Bundles XML must match.", expected, actual); assertEquals("Bundles XML must match.", expected, actual);
byte[] signedPreKey = "SignedPreKey".getBytes(StringUtils.UTF8); byte[] signedPreKey = "SignedPreKey".getBytes(StandardCharsets.UTF_8);
byte[] signedPreKeySig = "SignedPreKeySignature".getBytes(StringUtils.UTF8); byte[] signedPreKeySig = "SignedPreKeySignature".getBytes(StandardCharsets.UTF_8);
byte[] identityKey = "IdentityKey".getBytes(StringUtils.UTF8); byte[] identityKey = "IdentityKey".getBytes(StandardCharsets.UTF_8);
byte[] firstPreKey = "FirstPreKey".getBytes(StringUtils.UTF8); byte[] firstPreKey = "FirstPreKey".getBytes(StandardCharsets.UTF_8);
byte[] secondPreKey = "SecondPreKey".getBytes(StringUtils.UTF8); byte[] secondPreKey = "SecondPreKey".getBytes(StandardCharsets.UTF_8);
OmemoBundleElement_VAxolotl parsed = new OmemoBundleVAxolotlProvider().parse(TestUtils.getParser(actual)); OmemoBundleElement_VAxolotl parsed = new OmemoBundleVAxolotlProvider().parse(TestUtils.getParser(actual));

View file

@ -18,11 +18,11 @@ package org.jivesoftware.smackx.omemo;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils; import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.stringencoder.Base64; import org.jivesoftware.smack.util.stringencoder.Base64;
import org.jivesoftware.smackx.omemo.element.OmemoElement_VAxolotl; import org.jivesoftware.smackx.omemo.element.OmemoElement_VAxolotl;
@ -40,11 +40,11 @@ public class OmemoVAxolotlElementTest extends SmackTestSuite {
@Test @Test
public void serializationTest() throws Exception { 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 keyId1 = 8;
int keyId2 = 33333; int keyId2 = 33333;
byte[] keyData1 = "KEYDATA".getBytes(StringUtils.UTF8); byte[] keyData1 = "KEYDATA".getBytes(StandardCharsets.UTF_8);
byte[] keyData2 = "DATAKEY".getBytes(StringUtils.UTF8); byte[] keyData2 = "DATAKEY".getBytes(StandardCharsets.UTF_8);
int sid = 12131415; int sid = 12131415;
byte[] iv = OmemoMessageBuilder.generateIv(); byte[] iv = OmemoMessageBuilder.generateIv();

View file

@ -16,7 +16,7 @@
*/ */
package org.jivesoftware.smack.sasl.provided; package org.jivesoftware.smack.sasl.provided;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.CallbackHandler;
@ -103,13 +103,7 @@ public class SASLDigestMD5Mechanism extends SASLMechanism {
if (challenge.length == 0) { if (challenge.length == 0) {
throw new SmackSaslException("Initial challenge has zero length"); throw new SmackSaslException("Initial challenge has zero length");
} }
String challengeString; String challengeString = new String(challenge, StandardCharsets.UTF_8);
try {
challengeString = new String(challenge, StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
String[] challengeParts = challengeString.split(","); String[] challengeParts = challengeString.split(",");
byte[] response = null; byte[] response = null;
switch (state) { switch (state) {