directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject [04/17] directory-kerby git commit: Use StandardCharsets.UTF_8 to avoid handling of UnsupportedEncodingException
Date Fri, 27 Nov 2015 08:18:14 GMT
Use StandardCharsets.UTF_8 to avoid handling of UnsupportedEncodingException


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/b7a062e6
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/b7a062e6
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/b7a062e6

Branch: refs/heads/pkinit-support
Commit: b7a062e606ff40dda2f2003a16fa528096e7bc05
Parents: 8194b21
Author: Stefan Seelmann <mail@stefan-seelmann.de>
Authored: Thu Nov 26 07:52:09 2015 +0100
Committer: Stefan Seelmann <mail@stefan-seelmann.de>
Committed: Thu Nov 26 07:52:26 2015 +0100

----------------------------------------------------------------------
 .../org/apache/kerby/config/IniConfigLoader.java  |  4 ++--
 .../kerberos/kerb/integration/test/Transport.java |  4 ++--
 .../kerb/integration/test/gss/GssAppClient.java   |  4 ++--
 .../kerb/integration/test/gss/GssAppServer.java   |  4 ++--
 .../kerb/integration/test/jaas/TokenCache.java    |  6 +++---
 .../kerb/integration/test/sasl/SaslAppClient.java |  8 ++++----
 .../kerb/integration/test/sasl/SaslAppServer.java |  4 ++--
 .../kerb/crypto/cksum/HmacMd5Rc4CheckSum.java     |  4 ++--
 .../kerberos/kerb/crypto/enc/KeKiCmacEnc.java     |  4 ++--
 .../kerberos/kerb/crypto/enc/KeKiHmacSha1Enc.java |  4 ++--
 .../kerby/kerberos/kerb/crypto/fast/FastUtil.java |  4 ++--
 .../kerb/crypto/key/AbstractKeyMaker.java         | 18 ++++++------------
 .../kerberos/kerb/crypto/key/AesKeyMaker.java     |  8 +-------
 .../kerb/crypto/key/CamelliaKeyMaker.java         |  8 +-------
 .../kerby/kerberos/kerb/crypto/util/Rc4.java      |  4 ++--
 .../kerby/kerberos/kerb/KrbInputStream.java       |  4 ++--
 .../kerby/kerberos/kerb/KrbOutputStream.java      |  4 ++--
 .../kerberos/provider/token/JwtTokenDecoder.java  |  4 ++--
 .../kerberos/provider/token/JwtTokenEncoder.java  |  4 ++--
 .../kerby/kerberos/tool/token/TokenCache.java     |  6 +++---
 .../src/main/java/org/apache/kerby/util/Utf8.java | 14 +++-----------
 21 files changed, 49 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
----------------------------------------------------------------------
diff --git a/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java b/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
index 69e58ab..5c673b2 100644
--- a/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
+++ b/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
@@ -23,7 +23,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public class IniConfigLoader extends ConfigLoader {
     private static final String COMMENT_SYMBOL = "#";
@@ -40,7 +40,7 @@ public class IniConfigLoader extends ConfigLoader {
         currentConfig = config;
 
         InputStream is = (InputStream) resource.getResource();
-        BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
+        BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
 
         String line;
         while ((line = reader.readLine()) != null) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/Transport.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/Transport.java
b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/Transport.java
index 5aa7151..50bad1a 100644
--- a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/Transport.java
+++ b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/Transport.java
@@ -24,7 +24,7 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public class Transport {
 
@@ -130,7 +130,7 @@ public class Transport {
         }
 
         public Message(String header, byte[] body) {
-            this.header = header.getBytes(Charset.forName("UTF-8"));
+            this.header = header.getBytes(StandardCharsets.UTF_8);
             this.body = body;
         }
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/gss/GssAppClient.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/gss/GssAppClient.java
b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/gss/GssAppClient.java
index fd5b4a2..278f294 100644
--- a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/gss/GssAppClient.java
+++ b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/gss/GssAppClient.java
@@ -29,7 +29,7 @@ import org.ietf.jgss.GSSName;
 import org.ietf.jgss.MessageProp;
 import org.ietf.jgss.Oid;
 
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public class GssAppClient extends AppClient {
     private String clientPrincipal;
@@ -94,7 +94,7 @@ public class GssAppClient extends AppClient {
             System.out.println("Mutual authentication took place!");
         }
 
-        byte[] messageBytes = "Hello There!\0".getBytes(Charset.forName("UTF-8"));
+        byte[] messageBytes = "Hello There!\0".getBytes(StandardCharsets.UTF_8);
         MessageProp prop =  new MessageProp(0, true);
         token = context.wrap(messageBytes, 0, messageBytes.length, prop);
         System.out.println("Will send wrap token of size " + token.length);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/gss/GssAppServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/gss/GssAppServer.java
b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/gss/GssAppServer.java
index 5130a1a..84ffff2 100644
--- a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/gss/GssAppServer.java
+++ b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/gss/GssAppServer.java
@@ -29,7 +29,7 @@ import org.ietf.jgss.GSSName;
 import org.ietf.jgss.MessageProp;
 import org.ietf.jgss.Oid;
 
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public class GssAppServer extends AppServer {
     private String serverPrincipal;
@@ -94,7 +94,7 @@ public class GssAppServer extends AppServer {
         MessageProp prop = new MessageProp(0, false);
         byte[] token = conn.recvToken();
         byte[] bytes = context.unwrap(token, 0, token.length, prop);
-        String str = new String(bytes, Charset.forName("UTF-8"));
+        String str = new String(bytes, StandardCharsets.UTF_8);
         System.out.println("Received data \""
                 + str + "\" of length " + str.length());
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenCache.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenCache.java
b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenCache.java
index 6051cdb..e398407 100644
--- a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenCache.java
+++ b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenCache.java
@@ -29,7 +29,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Writer;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 /**
  * This class provides APIs for converting token cache file with token string.
@@ -62,7 +62,7 @@ public class TokenCache {
         String token = null;
         try {
             BufferedReader reader = new BufferedReader(
-                    new InputStreamReader(new FileInputStream(cacheFile), Charset.forName("UTF-8")));
+                    new InputStreamReader(new FileInputStream(cacheFile), StandardCharsets.UTF_8));
             String line = reader.readLine();
             reader.close();
             if (line != null) {
@@ -84,7 +84,7 @@ public class TokenCache {
         File cacheFile = getDefaultTokenCache();
 
         try {
-            Writer writer = new FileWriterWithEncoding(cacheFile, Charset.forName("UTF-8"));
+            Writer writer = new FileWriterWithEncoding(cacheFile, StandardCharsets.UTF_8);
             writer.write(token);
             writer.flush();
             writer.close();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/sasl/SaslAppClient.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/sasl/SaslAppClient.java
b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/sasl/SaslAppClient.java
index a20076a..2509df9 100644
--- a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/sasl/SaslAppClient.java
+++ b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/sasl/SaslAppClient.java
@@ -25,7 +25,7 @@ import org.apache.kerby.kerberos.kerb.integration.test.Transport;
 import javax.security.sasl.Sasl;
 import javax.security.sasl.SaslClient;
 import java.io.IOException;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -81,7 +81,7 @@ public class SaslAppClient extends AppClient {
 
         System.out.println("Context Established! ");
 
-        token = "Hello There!\0".getBytes(Charset.forName("UTF-8"));
+        token = "Hello There!\0".getBytes(StandardCharsets.UTF_8);
         System.out.println("Will send wrap token of size " + token.length);
 
         conn.sendToken(token);
@@ -92,14 +92,14 @@ public class SaslAppClient extends AppClient {
 
     private boolean isOK(Transport.Message msg) {
         if (msg.header != null) {
-            return new String(msg.header, Charset.forName("UTF-8")).equals("OK");
+            return new String(msg.header, StandardCharsets.UTF_8).equals("OK");
         }
         return false;
     }
 
     private boolean isContinue(Transport.Message msg) {
         if (msg.header != null) {
-            return new String(msg.header, Charset.forName("UTF-8")).equals("CONT");
+            return new String(msg.header, StandardCharsets.UTF_8).equals("CONT");
         }
         return false;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/sasl/SaslAppServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/sasl/SaslAppServer.java
b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/sasl/SaslAppServer.java
index 4b4833c..f769d5e 100644
--- a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/sasl/SaslAppServer.java
+++ b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/sasl/SaslAppServer.java
@@ -30,7 +30,7 @@ import javax.security.sasl.Sasl;
 import javax.security.sasl.SaslException;
 import javax.security.sasl.SaslServer;
 import java.io.IOException;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -100,7 +100,7 @@ public class SaslAppServer extends AppServer {
     protected void doWith(SaslServer ss, Map<String, Object> props,
                           Transport.Connection conn) throws IOException, Exception {
         byte[] token = conn.recvToken();
-        String str = new String(token, Charset.forName("UTF-8"));
+        String str = new String(token, StandardCharsets.UTF_8);
         System.out.println("Received data \""
                 + str + "\" of length " + str.length());
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/cksum/HmacMd5Rc4CheckSum.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/cksum/HmacMd5Rc4CheckSum.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/cksum/HmacMd5Rc4CheckSum.java
index 787ec26..f584915 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/cksum/HmacMd5Rc4CheckSum.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/cksum/HmacMd5Rc4CheckSum.java
@@ -25,7 +25,7 @@ import org.apache.kerby.kerberos.kerb.crypto.cksum.provider.Md5Provider;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.spec.base.CheckSumType;
 
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public class HmacMd5Rc4CheckSum extends AbstractKeyedCheckSumTypeHandler {
 
@@ -57,7 +57,7 @@ public class HmacMd5Rc4CheckSum extends AbstractKeyedCheckSumTypeHandler
{
     protected byte[] doChecksumWithKey(byte[] data, int start, int len,
                                        byte[] key, int usage) throws KrbException {
 
-        byte[] signKey = "signaturekey".getBytes(Charset.forName("UTF-8"));
+        byte[] signKey = "signaturekey".getBytes(StandardCharsets.UTF_8);
         byte[] newSignKey = new byte[signKey.length + 1];
         System.arraycopy(signKey, 0, newSignKey, 0, signKey.length);
         byte[] ksign = Hmac.hmac(hashProvider(), key, newSignKey);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiCmacEnc.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiCmacEnc.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiCmacEnc.java
index 2ee020a..022d5df 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiCmacEnc.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiCmacEnc.java
@@ -25,7 +25,7 @@ import org.apache.kerby.kerberos.kerb.crypto.util.Cmac;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
 
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public abstract class KeKiCmacEnc extends KeKiEnc {
 
@@ -48,7 +48,7 @@ public abstract class KeKiCmacEnc extends KeKiEnc {
 
     @Override
     public byte[] prf(byte[] key, byte[] seed) throws KrbException {
-        byte[] prfConst = "prf".getBytes(Charset.forName("UTF-8"));
+        byte[] prfConst = "prf".getBytes(StandardCharsets.UTF_8);
         byte[] kp;
         if (EncryptionHandler.getEncHandler(this.eType()).prfSize() != encProvider().blockSize())
{
             return null;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiHmacSha1Enc.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiHmacSha1Enc.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiHmacSha1Enc.java
index a2823a2..6cf1563 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiHmacSha1Enc.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiHmacSha1Enc.java
@@ -24,7 +24,7 @@ import org.apache.kerby.kerberos.kerb.crypto.util.Hmac;
 import org.apache.kerby.kerberos.kerb.crypto.cksum.HashProvider;
 import org.apache.kerby.kerberos.kerb.KrbException;
 
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public abstract class KeKiHmacSha1Enc extends KeKiEnc {
 
@@ -38,7 +38,7 @@ public abstract class KeKiHmacSha1Enc extends KeKiEnc {
 
     @Override
     public byte[] prf(byte[] key, byte[] seed) throws KrbException {
-        byte[] prfConst = "prf".getBytes(Charset.forName("UTF-8"));
+        byte[] prfConst = "prf".getBytes(StandardCharsets.UTF_8);
         int cksumSize = (hashProvider().hashSize() / encProvider().blockSize()) * encProvider().blockSize();
         byte[] cksum = new byte[cksumSize];
         byte[] kp;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/fast/FastUtil.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/fast/FastUtil.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/fast/FastUtil.java
index 4644791..461d789 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/fast/FastUtil.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/fast/FastUtil.java
@@ -23,7 +23,7 @@ import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.crypto.EncryptionHandler;
 import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
 
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 /**
  * Implementing FAST (RFC6113) armor key related algorithms.
@@ -48,7 +48,7 @@ public class FastUtil {
         int prfSize = EncryptionHandler.getEncHandler(key.getKeyType()).prfSize();
         int iterations = keyBytesLen / prfSize;
         prfInbuf[0] = 1;
-        System.arraycopy(pepper.getBytes(Charset.forName("UTF-8")), 0, prfInbuf, 1, pepper.length());
+        System.arraycopy(pepper.getBytes(StandardCharsets.UTF_8), 0, prfInbuf, 1, pepper.length());
         if (keyBytesLen % prfSize != 0) {
             iterations++;
         }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/AbstractKeyMaker.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/AbstractKeyMaker.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/AbstractKeyMaker.java
index fe0275e..d7bd35d 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/AbstractKeyMaker.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/AbstractKeyMaker.java
@@ -23,12 +23,11 @@ import org.apache.kerby.kerberos.kerb.crypto.util.BytesUtil;
 import org.apache.kerby.kerberos.kerb.crypto.enc.EncryptProvider;
 import org.apache.kerby.kerberos.kerb.KrbException;
 
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public abstract class AbstractKeyMaker implements KeyMaker {
 
-    static final byte[] KERBEROS_CONSTANT = "kerberos".getBytes(Charset.forName("UTF-8"));
+    static final byte[] KERBEROS_CONSTANT = "kerberos".getBytes(StandardCharsets.UTF_8);
 
     private EncryptProvider encProvider;
 
@@ -47,11 +46,7 @@ public abstract class AbstractKeyMaker implements KeyMaker {
         System.arraycopy(password.toCharArray(), 0, chars, 0, password.length());
         System.arraycopy(salt.toCharArray(), 0, chars, password.length(), salt.length());
 
-        try {
-            return new String(chars).getBytes("UTF-8");
-        } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException("Character decoding failed", e);
-        }
+        return new String(chars).getBytes(StandardCharsets.UTF_8);
     }
 
     protected static int getIterCount(byte[] param, int defCount) {
@@ -67,11 +62,10 @@ public abstract class AbstractKeyMaker implements KeyMaker {
         return iterCount;
     }
 
-    protected static byte[] getSaltBytes(String salt, String pepper)
-            throws UnsupportedEncodingException {
-        byte[] saltBytes = salt.getBytes("UTF-8");
+    protected static byte[] getSaltBytes(String salt, String pepper) {
+        byte[] saltBytes = salt.getBytes(StandardCharsets.UTF_8);
         if (pepper != null && !pepper.isEmpty()) {
-            byte[] pepperBytes = pepper.getBytes("UTF-8");
+            byte[] pepperBytes = pepper.getBytes(StandardCharsets.UTF_8);
             int len = saltBytes.length;
             len += 1 + pepperBytes.length;
             byte[] results = new byte[len];

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/AesKeyMaker.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/AesKeyMaker.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/AesKeyMaker.java
index c3a72a3..31c5895 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/AesKeyMaker.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/AesKeyMaker.java
@@ -23,7 +23,6 @@ import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.crypto.util.Pbkdf;
 import org.apache.kerby.kerberos.kerb.crypto.enc.provider.AesProvider;
 
-import java.io.UnsupportedEncodingException;
 import java.security.GeneralSecurityException;
 
 public class AesKeyMaker extends DkKeyMaker {
@@ -41,12 +40,7 @@ public class AesKeyMaker extends DkKeyMaker {
     public byte[] str2key(String string, String salt, byte[] param) throws KrbException {
         int iterCount = getIterCount(param, 4096);
 
-        byte[] saltBytes = null;
-        try {
-            saltBytes = getSaltBytes(salt, null);
-        } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException(e);
-        }
+        byte[] saltBytes = getSaltBytes(salt, null);
 
         int keySize = encProvider().keySize();
         byte[] random;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/CamelliaKeyMaker.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/CamelliaKeyMaker.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/CamelliaKeyMaker.java
index dbdb7f7..292842f 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/CamelliaKeyMaker.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/CamelliaKeyMaker.java
@@ -25,7 +25,6 @@ import org.apache.kerby.kerberos.kerb.crypto.util.Pbkdf;
 import org.apache.kerby.kerberos.kerb.crypto.enc.provider.CamelliaProvider;
 import org.apache.kerby.kerberos.kerb.KrbException;
 
-import java.io.UnsupportedEncodingException;
 import java.security.GeneralSecurityException;
 
 public class CamelliaKeyMaker extends DkKeyMaker {
@@ -43,12 +42,7 @@ public class CamelliaKeyMaker extends DkKeyMaker {
     public byte[] str2key(String string, String salt, byte[] param) throws KrbException {
         int iterCount = getIterCount(param, 32768);
 
-        byte[] saltBytes = null;
-        try {
-            saltBytes = getSaltBytes(salt, getPepper());
-        } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException(e);
-        }
+        byte[] saltBytes = getSaltBytes(salt, getPepper());
 
         int keySize = encProvider().keySize();
         byte[] random;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/util/Rc4.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/util/Rc4.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/util/Rc4.java
index 5a800c6..8213cdf 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/util/Rc4.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/util/Rc4.java
@@ -19,14 +19,14 @@
  */
 package org.apache.kerby.kerberos.kerb.crypto.util;
 
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 /**
  * Ref. MIT krb5 enc_rc4.c
  */
 public class Rc4 {
 
-    private static final byte[] L40 = "fortybits".getBytes(Charset.forName("UTF-8"));
+    private static final byte[] L40 = "fortybits".getBytes(StandardCharsets.UTF_8);
 
     public static byte[] getSalt(int usage, boolean exportable) {
         int newUsage = convertUsage(usage);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbInputStream.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbInputStream.java
b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbInputStream.java
index 40f5324..b523505 100644
--- a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbInputStream.java
+++ b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbInputStream.java
@@ -27,7 +27,7 @@ import org.apache.kerby.kerberos.kerb.spec.base.PrincipalName;
 import java.io.DataInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public abstract class KrbInputStream extends DataInputStream {
     public KrbInputStream(InputStream in) {
@@ -55,7 +55,7 @@ public abstract class KrbInputStream extends DataInputStream {
     public String readCountedString() throws IOException {
         byte[] countedOctets = readCountedOctets();
         // ASCII
-        return new String(countedOctets, Charset.forName("UTF-8"));
+        return new String(countedOctets, StandardCharsets.UTF_8);
     }
 
     public byte[] readCountedOctets() throws IOException {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbOutputStream.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbOutputStream.java
b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbOutputStream.java
index bf67ba4..b1ea2c4 100644
--- a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbOutputStream.java
+++ b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbOutputStream.java
@@ -26,7 +26,7 @@ import org.apache.kerby.kerberos.kerb.spec.base.PrincipalName;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public abstract class KrbOutputStream extends DataOutputStream {
     public KrbOutputStream(OutputStream out) {
@@ -50,7 +50,7 @@ public abstract class KrbOutputStream extends DataOutputStream {
     }
 
     public void writeCountedString(String string) throws IOException {
-        byte[] data = string != null ? string.getBytes(Charset.forName("UTF-8")) : null;
// ASCII
+        byte[] data = string != null ? string.getBytes(StandardCharsets.UTF_8) : null; //
ASCII
 
         writeCountedOctets(data);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenDecoder.java
----------------------------------------------------------------------
diff --git a/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenDecoder.java
b/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenDecoder.java
index 7c34bf1..8aad479 100644
--- a/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenDecoder.java
+++ b/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenDecoder.java
@@ -38,7 +38,7 @@ import org.apache.kerby.kerberos.kerb.provider.TokenDecoder;
 import org.apache.kerby.kerberos.kerb.spec.base.AuthToken;
 
 import java.io.IOException;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.security.PrivateKey;
 import java.security.PublicKey;
 import java.security.interfaces.ECPublicKey;
@@ -62,7 +62,7 @@ public class JwtTokenDecoder implements TokenDecoder {
      */
     @Override
     public AuthToken decodeFromBytes(byte[] content) throws IOException {
-        String tokenStr = new String(content, Charset.forName("UTF-8"));
+        String tokenStr = new String(content, StandardCharsets.UTF_8);
 
         return decodeFromString(tokenStr);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenEncoder.java
----------------------------------------------------------------------
diff --git a/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenEncoder.java
b/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenEncoder.java
index 0d129f4..03ebdcf 100644
--- a/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenEncoder.java
+++ b/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenEncoder.java
@@ -41,7 +41,7 @@ import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.provider.TokenEncoder;
 import org.apache.kerby.kerberos.kerb.spec.base.AuthToken;
 
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.security.PrivateKey;
 import java.security.PublicKey;
 import java.security.interfaces.ECPrivateKey;
@@ -66,7 +66,7 @@ public class JwtTokenEncoder implements TokenEncoder {
     @Override
     public byte[] encodeAsBytes(AuthToken token) throws KrbException {
         String tokenStr = encodeAsString(token);
-        return tokenStr.getBytes(Charset.forName("UTF-8"));
+        return tokenStr.getBytes(StandardCharsets.UTF_8);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
----------------------------------------------------------------------
diff --git a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
index 1235b8f..e8c5a2c 100644
--- a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
+++ b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
@@ -29,7 +29,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Writer;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 public class TokenCache {
     private static final String DEFAULT_TOKEN_CACHE_PATH = ".tokenauth";
@@ -53,7 +53,7 @@ public class TokenCache {
         String token = null;
         try {
             BufferedReader reader = new BufferedReader(
-                    new InputStreamReader(new FileInputStream(cacheFile), Charset.forName("UTF-8")));
+                    new InputStreamReader(new FileInputStream(cacheFile), StandardCharsets.UTF_8));
             String line = reader.readLine();
             reader.close();
             if (line != null) {
@@ -70,7 +70,7 @@ public class TokenCache {
         File cacheFile = getDefaultTokenCache();
 
         try {
-            Writer writer = new FileWriterWithEncoding(cacheFile, Charset.forName("UTF-8"));
+            Writer writer = new FileWriterWithEncoding(cacheFile, StandardCharsets.UTF_8);
             writer.write(token);
             writer.flush();
             writer.close();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7a062e6/kerby-util/src/main/java/org/apache/kerby/util/Utf8.java
----------------------------------------------------------------------
diff --git a/kerby-util/src/main/java/org/apache/kerby/util/Utf8.java b/kerby-util/src/main/java/org/apache/kerby/util/Utf8.java
index 4952665..4e57234 100644
--- a/kerby-util/src/main/java/org/apache/kerby/util/Utf8.java
+++ b/kerby-util/src/main/java/org/apache/kerby/util/Utf8.java
@@ -19,24 +19,16 @@
  */
 package org.apache.kerby.util;
 
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 
 public final class Utf8 {
     private Utf8() { }
 
     public static String toString(byte[] bytes) {
-        try {
-            return new String(bytes, "UTF-8");
-        } catch (UnsupportedEncodingException uee) {
-            throw new RuntimeException("UTF8 unavailable", uee);
-        }
+        return new String(bytes, StandardCharsets.UTF_8);
     }
 
     public static byte[] toBytes(String s) {
-        try {
-            return s.getBytes("UTF-8");
-        } catch (UnsupportedEncodingException uee) {
-            throw new RuntimeException("UTF8 unavailable", uee);
-        }
+        return s.getBytes(StandardCharsets.UTF_8);
     }
 }


Mime
View raw message