From a22ec4b112d2613e149d95d0bedeca462ffef1e3 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 10 May 2018 19:33:28 +0200 Subject: [PATCH] Use java.text.Normalizer for SASLPrep --- .../smack/sasl/SASLMechanism.java | 28 ++++--------------- .../smack/util/StringTransformer.java | 23 --------------- 2 files changed, 5 insertions(+), 46 deletions(-) delete mode 100644 smack-core/src/main/java/org/jivesoftware/smack/util/StringTransformer.java diff --git a/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java b/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java index d3aede72c..8f3e8c594 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java @@ -1,6 +1,6 @@ /** * - * Copyright 2003-2007 Jive Software, 2014-2016 Florian Schmaus + * Copyright 2003-2007 Jive Software, 2014-2018 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,6 +16,9 @@ */ package org.jivesoftware.smack.sasl; +import java.text.Normalizer; +import java.text.Normalizer.Form; + import javax.net.ssl.SSLSession; import javax.security.auth.callback.CallbackHandler; @@ -25,7 +28,6 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.sasl.packet.SaslStreamElements.AuthMechanism; import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Response; -import org.jivesoftware.smack.util.StringTransformer; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.stringencoder.Base64; @@ -54,22 +56,6 @@ public abstract class SASLMechanism implements Comparable { public static final String GSSAPI = "GSSAPI"; public static final String PLAIN = "PLAIN"; - // TODO Remove once Smack's min Android API is 9, where java.text.Normalizer is available - private static StringTransformer saslPrepTransformer; - - /** - * Set the SASLPrep StringTransformer. - *

- * A simple SASLPrep StringTransformer would be for example: java.text.Normalizer.normalize(string, Form.NFKC); - *

- * - * @param stringTransformer set StringTransformer to use for SASLPrep. - * @see RFC 4013 - SASLprep: Stringprep Profile for User Names and Passwords - */ - public static void setSaslPrepTransformer(StringTransformer stringTransformer) { - saslPrepTransformer = stringTransformer; - } - protected XMPPConnection connection; protected ConnectionConfiguration connectionConfiguration; @@ -319,11 +305,7 @@ public abstract class SASLMechanism implements Comparable { * @see RFC 4013 - SASLprep: Stringprep Profile for User Names and Passwords */ protected static String saslPrep(String string) { - StringTransformer stringTransformer = saslPrepTransformer; - if (stringTransformer != null) { - return stringTransformer.transform(string); - } - return string; + return Normalizer.normalize(string, Form.NFKC); } @Override diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/StringTransformer.java b/smack-core/src/main/java/org/jivesoftware/smack/util/StringTransformer.java deleted file mode 100644 index 313dcf29e..000000000 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/StringTransformer.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - * Copyright 2014 Florian Schmaus - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jivesoftware.smack.util; - -public interface StringTransformer { - - String transform(String string); - -}