This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
commit d459158b89cfe8dc9818a9256a461802c9a77692 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Jul 16 09:51:08 2023 -0400 Use stock JRE Charset instead of magic string Clean up exceptions on non-public methods --- .../config/keys/loader/openssh/kdf/BCrypt.java | 11 ++++----- .../apache/sshd/common/util/io/FileSnapshot.java | 26 +++++++++++----------- .../sshd/common/util/threads/ThreadUtils.java | 12 +++++----- .../apache/sshd/common/channel/LocalWindow.java | 2 +- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/sshd-common/src/main/java/org/apache/sshd/common/config/keys/loader/openssh/kdf/BCrypt.java b/sshd-common/src/main/java/org/apache/sshd/common/config/keys/loader/openssh/kdf/BCrypt.java index 84b546ed2..0a78aa8c8 100644 --- a/sshd-common/src/main/java/org/apache/sshd/common/config/keys/loader/openssh/kdf/BCrypt.java +++ b/sshd-common/src/main/java/org/apache/sshd/common/config/keys/loader/openssh/kdf/BCrypt.java @@ -21,6 +21,7 @@ package org.apache.sshd.common.config.keys.loader.openssh.kdf; // It's available on maven as artifact org.connectbot.jbcrypt:jbcrypt:1.0.0. pbkdf method added 2016 by Kenny Root. // Modifications for Apache MINA sshd: this comment, plus changed the package from org.mindrot.jbcrypt to avoid conflicts. import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.DigestException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -862,13 +863,9 @@ public class BCrypt { public static boolean checkpw(String plaintext, String hashed) { byte hashed_bytes[]; byte try_bytes[]; - try { - String try_pw = hashpw(plaintext, hashed); - hashed_bytes = hashed.getBytes("UTF-8"); - try_bytes = try_pw.getBytes("UTF-8"); - } catch (UnsupportedEncodingException uee) { - return false; - } + String try_pw = hashpw(plaintext, hashed); + hashed_bytes = hashed.getBytes(StandardCharsets.UTF_8); + try_bytes = try_pw.getBytes(StandardCharsets.UTF_8); if (hashed_bytes.length != try_bytes.length) return false; byte ret = 0; diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/io/FileSnapshot.java b/sshd-common/src/main/java/org/apache/sshd/common/util/io/FileSnapshot.java index 29ec35d32..4911d80ef 100644 --- a/sshd-common/src/main/java/org/apache/sshd/common/util/io/FileSnapshot.java +++ b/sshd-common/src/main/java/org/apache/sshd/common/util/io/FileSnapshot.java @@ -82,10 +82,10 @@ public class FileSnapshot { /** * Creates a new {@link FileSnapshot} instance. * - * @param snapTime the {@link Instant} the snapshot was taken - * @param lastModified the "last modified" {@link FileTime} - * @param size the file size - * @param fileKey the file key + * @param snapTime the {@link Instant} the snapshot was taken + * @param lastModified the "last modified" {@link FileTime} + * @param size the file size + * @param fileKey the file key */ protected FileSnapshot(Instant snapTime, FileTime lastModified, long size, Object fileKey) { this.snapTime = Objects.requireNonNull(snapTime); @@ -133,10 +133,10 @@ public class FileSnapshot { /** * Creates a new {@link FileSnapshot} for the given path. * - * @param file to take the snapshot of - * @param options {@link LinkOption}s to use - * @return the {@link FileSnapshot}, never {@code null} - * @throws IOException if an I/O error occurs + * @param file to take the snapshot of + * @param options {@link LinkOption}s to use + * @return the {@link FileSnapshot}, never {@code null} + * @throws IOException if an I/O error occurs */ public static FileSnapshot save(Path file, LinkOption... options) throws IOException { BasicFileAttributes attributes = null; @@ -155,11 +155,11 @@ public class FileSnapshot { /** * Reload the {@link FileSnapshot} for the given file. * - * @param file to take the snapshot of - * @param options {@link LinkOption}s to use - * @return a {@link FileSnapshot}, never {@code null}; if {@code == this}, the file may be assumed - * unmodified - * @throws IOException if an I/O error occurs + * @param file to take the snapshot of + * @param options {@link LinkOption}s to use + * @return a {@link FileSnapshot}, never {@code null}; if {@code == this}, the file may be assumed + * unmodified + * @throws IOException if an I/O error occurs */ public FileSnapshot reload(Path file, LinkOption... options) throws IOException { FileSnapshot newSnapshot = save(file, options); diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java b/sshd-common/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java index a94ff9cce..90780abad 100644 --- a/sshd-common/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java +++ b/sshd-common/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java @@ -76,13 +76,13 @@ public final class ThreadUtils { * Runs an {@link IOFunction} with a flag set indicating that the executing thread is an Apache MINA sshd * framework-internal thread. * - * @param <T> parameter type - * @param <V> return type - * @param param parameter for the function - * @param code function to run - * @return the result of {@code code} + * @param <T> parameter type + * @param <V> return type + * @param param parameter for the function + * @param code function to run + * @return the result of {@code code} * @throws IOException propagated from {@code code.apply()} - * @see #isInternalThread() + * @see #isInternalThread() */ public static <T, V> V runAsInternal(T param, IOFunction<? super T, V> code) throws IOException { if (isInternalThread()) { diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/LocalWindow.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/LocalWindow.java index 8e52bb633..ff46a2a03 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/channel/LocalWindow.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/LocalWindow.java @@ -56,7 +56,7 @@ public class LocalWindow extends Window { /** * Initializes the {@link LocalWindow} with the packet and window sizes from the {@code resolver}. * - * @param resolver {@PropertyResolver} to access properties + * @param resolver {@PropertyResolver} to access properties */ public void init(PropertyResolver resolver) { init(CoreModuleProperties.WINDOW_SIZE.getRequired(resolver),