You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2017/12/28 10:43:10 UTC
[3/3] mina-sshd git commit: Replaced all usages of Pair with
SimpleImmutableEntry (exists since Java 1.6)
Replaced all usages of Pair with SimpleImmutableEntry (exists since Java 1.6)
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/74b6918b
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/74b6918b
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/74b6918b
Branch: refs/heads/master
Commit: 74b6918bce641e00006510ea38f1dee57fed2b0e
Parents: 1542874
Author: Goldstein Lyor <ly...@c-b4.com>
Authored: Thu Dec 28 12:27:24 2017 +0200
Committer: Goldstein Lyor <ly...@c-b4.com>
Committed: Thu Dec 28 12:42:58 2017 +0200
----------------------------------------------------------------------
.../java/org/apache/sshd/agent/SshAgent.java | 5 +-
.../sshd/agent/common/AbstractAgentClient.java | 12 +-
.../sshd/agent/common/AbstractAgentProxy.java | 9 +-
.../apache/sshd/agent/common/AgentDelegate.java | 4 +-
.../org/apache/sshd/agent/local/AgentImpl.java | 25 +++--
.../auth/hostbased/HostKeyIdentityProvider.java | 11 +-
.../auth/hostbased/UserAuthHostBased.java | 10 +-
.../auth/pubkey/SshAgentPublicKeyIterator.java | 8 +-
.../auth/pubkey/UserAuthPublicKeyIterator.java | 11 +-
.../DefaultConfigFileHostEntryResolver.java | 6 +-
.../config/keys/ClientIdentityFileWatcher.java | 6 +-
.../DefaultKnownHostsServerKeyVerifier.java | 6 +-
.../extensions/CheckFileHandleExtension.java | 8 +-
.../sftp/extensions/CheckFileNameExtension.java | 9 +-
.../helpers/AbstractCheckFileExtension.java | 6 +-
.../helpers/CheckFileHandleExtensionImpl.java | 6 +-
.../helpers/CheckFileNameExtensionImpl.java | 6 +-
.../apache/sshd/common/SyspropsMapWrapper.java | 8 +-
.../sshd/common/config/keys/KeyUtils.java | 40 +++----
.../loader/AbstractKeyPairResourceParser.java | 4 +-
.../keys/loader/KeyPairResourceParser.java | 12 +-
.../openssh/OpenSSHKeyPairResourceParser.java | 8 +-
.../pem/ECDSAPEMResourceKeyPairParser.java | 15 +--
.../apache/sshd/common/io/nio2/Nio2Service.java | 23 ++--
.../common/session/helpers/AbstractSession.java | 34 +++---
.../common/signature/AbstractSignature.java | 8 +-
.../sshd/common/signature/SignatureDSA.java | 8 +-
.../sshd/common/signature/SignatureECDSA.java | 8 +-
.../sshd/common/signature/SignatureRSA.java | 8 +-
.../org/apache/sshd/common/util/Invoker.java | 12 +-
.../apache/sshd/common/util/MapEntryUtils.java | 53 +++++++++
.../java/org/apache/sshd/common/util/Pair.java | 109 -------------------
.../common/util/io/ModifiableFileWatcher.java | 12 +-
.../util/security/eddsa/SignatureEd25519.java | 9 +-
.../DefaultAuthorizedKeysAuthenticator.java | 6 +-
.../sftp/AbstractSftpSubsystemHelper.java | 22 ++--
.../java/org/apache/sshd/agent/AgentTest.java | 4 +-
.../helpers/AbstractCheckFileExtensionTest.java | 16 +--
.../KeyUtilsFingerprintCaseSensitivityTest.java | 4 +-
.../keys/KeyUtilsFingerprintGenerationTest.java | 105 +++++++++---------
.../sshd/common/config/keys/KeyUtilsTest.java | 4 +-
.../sshd/common/io/nio2/Nio2ServiceTest.java | 12 +-
.../apache/sshd/common/mac/MacVectorsTest.java | 83 +++++++-------
.../ReservedSessionMessagesHandlerTest.java | 19 ++--
.../sshd/common/signature/SignatureRSATest.java | 6 +-
.../util/io/ModifiableFileWatcherTest.java | 4 +-
.../apache/sshd/deprecated/UserAuthAgent.java | 10 +-
.../test/JUnit4SingleInstanceClassRunner.java | 9 +-
.../sshd/server/auth/BaseAuthenticatorTest.java | 25 +++--
.../password/LdapPasswordAuthenticatorTest.java | 7 +-
.../pubkey/LdapPublickeyAuthenticatorTest.java | 7 +-
51 files changed, 411 insertions(+), 451 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgent.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgent.java b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgent.java
index 83e2aa0..dc5b832 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgent.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgent.java
@@ -22,8 +22,7 @@ import java.io.IOException;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.List;
-
-import org.apache.sshd.common.util.Pair;
+import java.util.Map;
/**
* SSH key agent server
@@ -32,7 +31,7 @@ public interface SshAgent extends java.nio.channels.Channel {
String SSH_AUTHSOCKET_ENV_NAME = "SSH_AUTH_SOCK";
- List<Pair<PublicKey, String>> getIdentities() throws IOException;
+ List<? extends Map.Entry<PublicKey, String>> getIdentities() throws IOException;
byte[] sign(PublicKey key, byte[] data) throws IOException;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
index dd007db..c4c3f26 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentClient.java
@@ -21,12 +21,12 @@ package org.apache.sshd.agent.common;
import java.io.IOException;
import java.security.KeyPair;
import java.security.PublicKey;
-import java.util.List;
+import java.util.Collection;
+import java.util.Map;
import org.apache.sshd.agent.SshAgent;
import org.apache.sshd.agent.SshAgentConstants;
import org.apache.sshd.common.config.keys.KeyUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.BufferUtils;
@@ -96,12 +96,12 @@ public abstract class AbstractAgentClient extends AbstractLoggingBean {
}
switch (cmd) {
case SshAgentConstants.SSH2_AGENTC_REQUEST_IDENTITIES: {
- List<Pair<PublicKey, String>> keys = agent.getIdentities();
+ Collection<? extends Map.Entry<PublicKey, String>> keys = agent.getIdentities();
rep.putByte(SshAgentConstants.SSH2_AGENT_IDENTITIES_ANSWER);
rep.putInt(keys.size());
- for (Pair<PublicKey, String> key : keys) {
- rep.putPublicKey(key.getFirst());
- rep.putString(key.getSecond());
+ for (Map.Entry<PublicKey, String> key : keys) {
+ rep.putPublicKey(key.getKey());
+ rep.putString(key.getValue());
}
break;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
index 21bd92c..c2d8365 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/common/AbstractAgentProxy.java
@@ -21,9 +21,11 @@ package org.apache.sshd.agent.common;
import java.io.IOException;
import java.security.KeyPair;
import java.security.PublicKey;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import org.apache.sshd.agent.SshAgent;
@@ -32,7 +34,6 @@ import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.BufferUtils;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
@@ -81,7 +82,7 @@ public abstract class AbstractAgentProxy extends AbstractLoggingBean implements
}
@Override
- public List<Pair<PublicKey, String>> getIdentities() throws IOException {
+ public List<? extends Map.Entry<PublicKey, String>> getIdentities() throws IOException {
int cmd = SshAgentConstants.SSH2_AGENTC_REQUEST_IDENTITIES;
int okcmd = SshAgentConstants.SSH2_AGENT_IDENTITIES_ANSWER;
if (FactoryManager.AGENT_FORWARDING_TYPE_IETF.equals(channelType)) {
@@ -101,7 +102,7 @@ public abstract class AbstractAgentProxy extends AbstractLoggingBean implements
throw new SshException("Bad identities count: " + nbIdentities);
}
- List<Pair<PublicKey, String>> keys = new ArrayList<>(nbIdentities);
+ List<SimpleImmutableEntry<PublicKey, String>> keys = new ArrayList<>(nbIdentities);
for (int i = 0; i < nbIdentities; i++) {
PublicKey key = buffer.getPublicKey();
String comment = buffer.getString();
@@ -109,7 +110,7 @@ public abstract class AbstractAgentProxy extends AbstractLoggingBean implements
log.debug("getIdentities() key type={}, comment={}, fingerprint={}",
KeyUtils.getKeyType(key), comment, KeyUtils.getFingerPrint(key));
}
- keys.add(new Pair<>(key, comment));
+ keys.add(new SimpleImmutableEntry<>(key, comment));
}
return keys;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/agent/common/AgentDelegate.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/common/AgentDelegate.java b/sshd-core/src/main/java/org/apache/sshd/agent/common/AgentDelegate.java
index 24bb0eb..1bd9704 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/common/AgentDelegate.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/common/AgentDelegate.java
@@ -22,9 +22,9 @@ import java.io.IOException;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.List;
+import java.util.Map;
import org.apache.sshd.agent.SshAgent;
-import org.apache.sshd.common.util.Pair;
public class AgentDelegate implements SshAgent {
@@ -45,7 +45,7 @@ public class AgentDelegate implements SshAgent {
}
@Override
- public List<Pair<PublicKey, String>> getIdentities() throws IOException {
+ public List<? extends Map.Entry<PublicKey, String>> getIdentities() throws IOException {
return agent.getIdentities();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentImpl.java b/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentImpl.java
index b1c8602..eeffb98 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentImpl.java
@@ -25,9 +25,11 @@ import java.security.interfaces.DSAPublicKey;
import java.security.interfaces.ECPublicKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -37,7 +39,6 @@ import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.signature.BuiltinSignatures;
import org.apache.sshd.common.signature.Signature;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.security.SecurityUtils;
@@ -46,7 +47,7 @@ import org.apache.sshd.common.util.security.SecurityUtils;
*/
public class AgentImpl implements SshAgent {
- private final List<Pair<KeyPair, String>> keys = new ArrayList<>();
+ private final List<Map.Entry<KeyPair, String>> keys = new ArrayList<>();
private final AtomicBoolean open = new AtomicBoolean(true);
public AgentImpl() {
@@ -59,12 +60,12 @@ public class AgentImpl implements SshAgent {
}
@Override
- public List<Pair<PublicKey, String>> getIdentities() throws IOException {
+ public List<? extends Map.Entry<PublicKey, String>> getIdentities() throws IOException {
if (!isOpen()) {
throw new SshException("Agent closed");
}
- return GenericUtils.map(keys, kp -> new Pair<>(kp.getFirst().getPublic(), kp.getSecond()));
+ return GenericUtils.map(keys, kp -> new SimpleImmutableEntry<>(kp.getKey().getPublic(), kp.getValue()));
}
@Override
@@ -74,9 +75,9 @@ public class AgentImpl implements SshAgent {
}
try {
- Pair<KeyPair, String> pp = Objects.requireNonNull(getKeyPair(keys, key), "Key not found");
- KeyPair kp = ValidateUtils.checkNotNull(pp.getFirst(), "No key pair for agent=%s", pp.getSecond());
- PublicKey pubKey = ValidateUtils.checkNotNull(kp.getPublic(), "No public key for agent=%s", pp.getSecond());
+ Map.Entry<KeyPair, String> pp = Objects.requireNonNull(getKeyPair(keys, key), "Key not found");
+ KeyPair kp = ValidateUtils.checkNotNull(pp.getKey(), "No key pair for agent=%s", pp.getValue());
+ PublicKey pubKey = ValidateUtils.checkNotNull(kp.getPublic(), "No public key for agent=%s", pp.getValue());
final Signature verif;
if (pubKey instanceof DSAPublicKey) {
@@ -106,7 +107,7 @@ public class AgentImpl implements SshAgent {
if (!isOpen()) {
throw new SshException("Agent closed");
}
- keys.add(new Pair<>(Objects.requireNonNull(key, "No key"), comment));
+ keys.add(new SimpleImmutableEntry<>(Objects.requireNonNull(key, "No key"), comment));
}
@Override
@@ -115,7 +116,7 @@ public class AgentImpl implements SshAgent {
throw new SshException("Agent closed");
}
- Pair<KeyPair, String> kp = getKeyPair(keys, key);
+ Map.Entry<KeyPair, String> kp = getKeyPair(keys, key);
if (kp == null) {
throw new SshException("Key not found");
}
@@ -137,13 +138,13 @@ public class AgentImpl implements SshAgent {
}
}
- protected static Pair<KeyPair, String> getKeyPair(Collection<Pair<KeyPair, String>> keys, PublicKey key) {
+ protected static Map.Entry<KeyPair, String> getKeyPair(Collection<? extends Map.Entry<KeyPair, String>> keys, PublicKey key) {
if (GenericUtils.isEmpty(keys) || (key == null)) {
return null;
}
- for (Pair<KeyPair, String> k : keys) {
- KeyPair kp = k.getFirst();
+ for (Map.Entry<KeyPair, String> k : keys) {
+ KeyPair kp = k.getKey();
if (KeyUtils.compareKeys(key, kp.getPublic())) {
return k;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/HostKeyIdentityProvider.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/HostKeyIdentityProvider.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/HostKeyIdentityProvider.java
index b141eb5..85bb82c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/HostKeyIdentityProvider.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/HostKeyIdentityProvider.java
@@ -21,12 +21,13 @@ package org.apache.sshd.client.auth.hostbased;
import java.security.KeyPair;
import java.security.cert.X509Certificate;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
@@ -34,11 +35,11 @@ import org.apache.sshd.common.util.Pair;
@FunctionalInterface
public interface HostKeyIdentityProvider {
/**
- * @return The host keys as a {@link Pair} of key + certificates (which can be {@code null}/empty)
+ * @return The host keys as a {@link Map.Entry} of key + certificates (which can be {@code null}/empty)
*/
- Iterable<Pair<KeyPair, List<X509Certificate>>> loadHostKeys();
+ Iterable<? extends Map.Entry<KeyPair, List<X509Certificate>>> loadHostKeys();
- static Iterator<Pair<KeyPair, List<X509Certificate>>> iteratorOf(HostKeyIdentityProvider provider) {
+ static Iterator<? extends Map.Entry<KeyPair, List<X509Certificate>>> iteratorOf(HostKeyIdentityProvider provider) {
return GenericUtils.iteratorOf((provider == null) ? null : provider.loadHostKeys());
}
@@ -47,6 +48,6 @@ public interface HostKeyIdentityProvider {
}
static HostKeyIdentityProvider wrap(Iterable<? extends KeyPair> pairs) {
- return () -> GenericUtils.wrapIterable(pairs, kp -> new Pair<>(kp, Collections.<X509Certificate>emptyList()));
+ return () -> GenericUtils.wrapIterable(pairs, kp -> new SimpleImmutableEntry<>(kp, Collections.<X509Certificate>emptyList()));
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/UserAuthHostBased.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/UserAuthHostBased.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/UserAuthHostBased.java
index 398cc4c..c363eeb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/UserAuthHostBased.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/hostbased/UserAuthHostBased.java
@@ -25,6 +25,7 @@ import java.security.cert.X509Certificate;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.apache.sshd.client.auth.AbstractUserAuth;
import org.apache.sshd.client.session.ClientSession;
@@ -35,7 +36,6 @@ import org.apache.sshd.common.signature.Signature;
import org.apache.sshd.common.signature.SignatureFactoriesManager;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.OsUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.BufferUtils;
@@ -48,7 +48,7 @@ import org.apache.sshd.common.util.net.SshdSocketAddress;
public class UserAuthHostBased extends AbstractUserAuth implements SignatureFactoriesManager {
public static final String NAME = UserAuthHostBasedFactory.NAME;
- private Iterator<Pair<KeyPair, List<X509Certificate>>> keys;
+ private Iterator<? extends Map.Entry<KeyPair, ? extends Collection<X509Certificate>>> keys;
private final HostKeyIdentityProvider clientHostKeys;
private List<NamedFactory<Signature>> factories;
private String clientUsername;
@@ -102,8 +102,8 @@ public class UserAuthHostBased extends AbstractUserAuth implements SignatureFact
return false;
}
- Pair<KeyPair, List<X509Certificate>> keyInfo = keys.next();
- KeyPair kp = keyInfo.getFirst();
+ Map.Entry<KeyPair, ? extends Collection<X509Certificate>> keyInfo = keys.next();
+ KeyPair kp = keyInfo.getKey();
PublicKey pub = kp.getPublic();
String keyType = KeyUtils.getKeyType(pub);
if (log.isTraceEnabled()) {
@@ -137,7 +137,7 @@ public class UserAuthHostBased extends AbstractUserAuth implements SignatureFact
buffer.putRawPublicKey(pub);
- List<X509Certificate> certs = keyInfo.getSecond();
+ Collection<X509Certificate> certs = keyInfo.getValue();
if (GenericUtils.size(certs) > 0) {
for (X509Certificate c : certs) {
// TODO make sure this yields DER encoding
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SshAgentPublicKeyIterator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SshAgentPublicKeyIterator.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SshAgentPublicKeyIterator.java
index 315e245..7551ed8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SshAgentPublicKeyIterator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SshAgentPublicKeyIterator.java
@@ -22,19 +22,19 @@ package org.apache.sshd.client.auth.pubkey;
import java.io.IOException;
import java.security.PublicKey;
import java.util.Iterator;
+import java.util.Map;
import java.util.Objects;
import org.apache.sshd.agent.SshAgent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class SshAgentPublicKeyIterator extends AbstractKeyPairIterator<KeyAgentIdentity> {
private final SshAgent agent;
- private final Iterator<Pair<PublicKey, String>> keys;
+ private final Iterator<? extends Map.Entry<PublicKey, String>> keys;
public SshAgentPublicKeyIterator(ClientSession session, SshAgent agent) throws IOException {
super(session);
@@ -49,7 +49,7 @@ public class SshAgentPublicKeyIterator extends AbstractKeyPairIterator<KeyAgentI
@Override
public KeyAgentIdentity next() {
- Pair<PublicKey, String> kp = keys.next();
- return new KeyAgentIdentity(agent, kp.getFirst(), kp.getSecond());
+ Map.Entry<PublicKey, String> kp = keys.next();
+ return new KeyAgentIdentity(agent, kp.getKey(), kp.getValue());
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
index 1d36cce..202b0a8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
@@ -56,8 +56,9 @@ public class UserAuthPublicKeyIterator extends AbstractKeyPairIterator<PublicKey
if (factory != null) {
try {
agent = Objects.requireNonNull(factory.createClient(manager), "No agent created");
- identities.add(agent.getIdentities().stream()
- .map(kp -> new KeyAgentIdentity(agent, kp.getFirst(), kp.getSecond())));
+ identities.add(agent.getIdentities()
+ .stream()
+ .map(kp -> new KeyAgentIdentity(agent, kp.getKey(), kp.getValue())));
} catch (Exception e) {
try {
closeAgent();
@@ -70,9 +71,9 @@ public class UserAuthPublicKeyIterator extends AbstractKeyPairIterator<PublicKey
}
identities.add(Stream.of(KeyIdentityProvider.providerOf(session))
- .map(KeyIdentityProvider::loadKeys)
- .flatMap(GenericUtils::stream)
- .map(kp -> new KeyPairIdentity(signatureFactories, session, kp)));
+ .map(KeyIdentityProvider::loadKeys)
+ .flatMap(GenericUtils::stream)
+ .map(kp -> new KeyPairIdentity(signatureFactories, session, kp)));
current = identities.stream().flatMap(r -> r).iterator();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/config/hosts/DefaultConfigFileHostEntryResolver.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/config/hosts/DefaultConfigFileHostEntryResolver.java b/sshd-core/src/main/java/org/apache/sshd/client/config/hosts/DefaultConfigFileHostEntryResolver.java
index b03225c..da5f687 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/config/hosts/DefaultConfigFileHostEntryResolver.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/config/hosts/DefaultConfigFileHostEntryResolver.java
@@ -25,9 +25,9 @@ import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.io.IoUtils;
/**
@@ -81,10 +81,10 @@ public class DefaultConfigFileHostEntryResolver extends ConfigFileHostEntryResol
log.debug("reloadHostConfigEntries({}@{}:{}) check permissions of {}", username, host, port, path);
}
- Pair<String, Object> violation = validateStrictConfigFilePermissions(path);
+ Map.Entry<String, ?> violation = validateStrictConfigFilePermissions(path);
if (violation != null) {
log.warn("reloadHostConfigEntries({}@{}:{}) invalid file={} permissions: {}",
- username, host, port, path, violation.getFirst());
+ username, host, port, path, violation.getKey());
updateReloadAttributes();
return Collections.emptyList();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcher.java b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcher.java
index a051606..a00cb24 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcher.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcher.java
@@ -24,6 +24,7 @@ import java.nio.file.Path;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.PublicKey;
+import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
@@ -31,7 +32,6 @@ import java.util.function.Supplier;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.common.util.io.ModifiableFileWatcher;
@@ -105,10 +105,10 @@ public class ClientIdentityFileWatcher extends ModifiableFileWatcher implements
protected KeyPair reloadClientIdentity(Path path) throws IOException, GeneralSecurityException {
if (isStrict()) {
- Pair<String, Object> violation = KeyUtils.validateStrictKeyFilePermissions(path, IoUtils.EMPTY_LINK_OPTIONS);
+ Map.Entry<String, Object> violation = KeyUtils.validateStrictKeyFilePermissions(path, IoUtils.EMPTY_LINK_OPTIONS);
if (violation != null) {
if (log.isDebugEnabled()) {
- log.debug("reloadClientIdentity({}) ignore due to {}", path, violation.getFirst());
+ log.debug("reloadClientIdentity({}) ignore due to {}", path, violation.getKey());
}
return null;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/DefaultKnownHostsServerKeyVerifier.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/DefaultKnownHostsServerKeyVerifier.java b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/DefaultKnownHostsServerKeyVerifier.java
index f2f83ad..b1c3a10 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/DefaultKnownHostsServerKeyVerifier.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/DefaultKnownHostsServerKeyVerifier.java
@@ -26,10 +26,10 @@ import java.nio.file.Path;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import org.apache.sshd.client.config.hosts.KnownHostEntry;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.io.IoUtils;
/**
@@ -76,9 +76,9 @@ public class DefaultKnownHostsServerKeyVerifier extends KnownHostsServerKeyVerif
log.debug("reloadKnownHosts({}) check permissions", file);
}
- Pair<String, Object> violation = validateStrictConfigFilePermissions(file);
+ Map.Entry<String, ?> violation = validateStrictConfigFilePermissions(file);
if (violation != null) {
- log.warn("reloadKnownHosts({}) invalid file permissions: {}", file, violation.getFirst());
+ log.warn("reloadKnownHosts({}) invalid file permissions: {}", file, violation.getKey());
updateReloadAttributes();
return Collections.emptyList();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileHandleExtension.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileHandleExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileHandleExtension.java
index c5208c5..e788bf8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileHandleExtension.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileHandleExtension.java
@@ -21,9 +21,9 @@ package org.apache.sshd.client.subsystem.sftp.extensions;
import java.io.IOException;
import java.util.Collection;
+import java.util.Map;
import org.apache.sshd.client.subsystem.sftp.SftpClient.Handle;
-import org.apache.sshd.common.util.Pair;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
@@ -37,10 +37,10 @@ public interface CheckFileHandleExtension extends SftpClientExtension {
* @param length Length of data to hash - if zero then till EOF
* @param blockSize Input block size to calculate individual hashes - if
* zero the <U>one</U> hash of <U>all</U> the data
- * @return A {@link Pair} where left=hash algorithm name, right=the calculated
- * hashes.
+ * @return An <U>immutable</U> {@link Map.Entry} where key=hash algorithm name,
+ * value=the calculated hashes.
* @throws IOException If failed to execute the command
*/
- Pair<String, Collection<byte[]>> checkFileHandle(Handle handle, Collection<String> algorithms, long startOffset, long length, int blockSize) throws IOException;
+ Map.Entry<String, Collection<byte[]>> checkFileHandle(Handle handle, Collection<String> algorithms, long startOffset, long length, int blockSize) throws IOException;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileNameExtension.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileNameExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileNameExtension.java
index e4ff1e9..8f562ba 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileNameExtension.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileNameExtension.java
@@ -21,8 +21,7 @@ package org.apache.sshd.client.subsystem.sftp.extensions;
import java.io.IOException;
import java.util.Collection;
-
-import org.apache.sshd.common.util.Pair;
+import java.util.Map;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
@@ -36,9 +35,9 @@ public interface CheckFileNameExtension extends SftpClientExtension {
* @param length Length of data to hash - if zero then till EOF
* @param blockSize Input block size to calculate individual hashes - if
* zero the <U>one</U> hash of <U>all</U> the data
- * @return A {@link Pair} where left=hash algorithm name, right=the calculated
- * hashes.
+ * @return An <U>immutable</U> {@link Map.Entry} key left=hash algorithm name,
+ * value=the calculated hashes.
* @throws IOException If failed to execute the command
*/
- Pair<String, Collection<byte[]>> checkFileName(String name, Collection<String> algorithms, long startOffset, long length, int blockSize) throws IOException;
+ Map.Entry<String, Collection<byte[]>> checkFileName(String name, Collection<String> algorithms, long startOffset, long length, int blockSize) throws IOException;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtension.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtension.java
index 640f5c0..1411098 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtension.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtension.java
@@ -21,6 +21,7 @@ package org.apache.sshd.client.subsystem.sftp.extensions.helpers;
import java.io.IOException;
import java.io.StreamCorruptedException;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
import java.util.LinkedList;
@@ -28,7 +29,6 @@ import org.apache.sshd.client.subsystem.sftp.RawSftpClient;
import org.apache.sshd.client.subsystem.sftp.SftpClient;
import org.apache.sshd.common.subsystem.sftp.SftpConstants;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.BufferUtils;
@@ -40,7 +40,7 @@ public abstract class AbstractCheckFileExtension extends AbstractSftpClientExten
super(name, client, raw, extras);
}
- protected Pair<String, Collection<byte[]>> doGetHash(Object target, Collection<String> algorithms, long offset, long length, int blockSize) throws IOException {
+ protected SimpleImmutableEntry<String, Collection<byte[]>> doGetHash(Object target, Collection<String> algorithms, long offset, long length, int blockSize) throws IOException {
Buffer buffer = getCommandBuffer(target, Byte.MAX_VALUE);
putTarget(buffer, target);
buffer.putString(GenericUtils.join(algorithms, ','));
@@ -71,6 +71,6 @@ public abstract class AbstractCheckFileExtension extends AbstractSftpClientExten
hashes.add(hashValue);
}
- return new Pair<>(algo, hashes);
+ return new SimpleImmutableEntry<>(algo, hashes);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CheckFileHandleExtensionImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CheckFileHandleExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CheckFileHandleExtensionImpl.java
index 65e6b54..1a464c3 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CheckFileHandleExtensionImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CheckFileHandleExtensionImpl.java
@@ -20,6 +20,7 @@
package org.apache.sshd.client.subsystem.sftp.extensions.helpers;
import java.io.IOException;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
import org.apache.sshd.client.subsystem.sftp.RawSftpClient;
@@ -27,7 +28,6 @@ import org.apache.sshd.client.subsystem.sftp.SftpClient;
import org.apache.sshd.client.subsystem.sftp.SftpClient.Handle;
import org.apache.sshd.client.subsystem.sftp.extensions.CheckFileHandleExtension;
import org.apache.sshd.common.subsystem.sftp.SftpConstants;
-import org.apache.sshd.common.util.Pair;
/**
* Implements "check-file-handle" extension
@@ -41,7 +41,9 @@ public class CheckFileHandleExtensionImpl extends AbstractCheckFileExtension imp
}
@Override
- public Pair<String, Collection<byte[]>> checkFileHandle(Handle handle, Collection<String> algorithms, long startOffset, long length, int blockSize) throws IOException {
+ public SimpleImmutableEntry<String, Collection<byte[]>> checkFileHandle(
+ Handle handle, Collection<String> algorithms, long startOffset, long length, int blockSize)
+ throws IOException {
return doGetHash(handle.getIdentifier(), algorithms, startOffset, length, blockSize);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CheckFileNameExtensionImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CheckFileNameExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CheckFileNameExtensionImpl.java
index 77c4af3..1b615c8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CheckFileNameExtensionImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CheckFileNameExtensionImpl.java
@@ -20,13 +20,13 @@
package org.apache.sshd.client.subsystem.sftp.extensions.helpers;
import java.io.IOException;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
import org.apache.sshd.client.subsystem.sftp.RawSftpClient;
import org.apache.sshd.client.subsystem.sftp.SftpClient;
import org.apache.sshd.client.subsystem.sftp.extensions.CheckFileNameExtension;
import org.apache.sshd.common.subsystem.sftp.SftpConstants;
-import org.apache.sshd.common.util.Pair;
/**
* Implements "check-file-name" extension
@@ -40,7 +40,9 @@ public class CheckFileNameExtensionImpl extends AbstractCheckFileExtension imple
}
@Override
- public Pair<String, Collection<byte[]>> checkFileName(String name, Collection<String> algorithms, long startOffset, long length, int blockSize) throws IOException {
+ public SimpleImmutableEntry<String, Collection<byte[]>> checkFileName(
+ String name, Collection<String> algorithms, long startOffset, long length, int blockSize)
+ throws IOException {
return doGetHash(name, algorithms, startOffset, length, blockSize);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/SyspropsMapWrapper.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/SyspropsMapWrapper.java b/sshd-core/src/main/java/org/apache/sshd/common/SyspropsMapWrapper.java
index 6dcb615..4408be2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/SyspropsMapWrapper.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/SyspropsMapWrapper.java
@@ -19,6 +19,7 @@
package org.apache.sshd.common;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
@@ -28,7 +29,7 @@ import java.util.TreeSet;
import java.util.stream.Collectors;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
+import org.apache.sshd.common.util.MapEntryUtils;
/**
* A wrapper that exposes a read-only {@link Map} access to the system
@@ -105,8 +106,7 @@ public final class SyspropsMapWrapper implements Map<String, Object> {
public Set<Entry<String, Object>> entrySet() {
Properties props = System.getProperties();
// return a copy in order to avoid concurrent modifications
- Set<Entry<String, Object>> entries =
- new TreeSet<>(Pair.byKeyEntryComparator());
+ Set<Entry<String, Object>> entries = new TreeSet<>(MapEntryUtils.byKeyEntryComparator());
for (String key : props.stringPropertyNames()) {
if (!isMappedSyspropKey(key)) {
continue;
@@ -114,7 +114,7 @@ public final class SyspropsMapWrapper implements Map<String, Object> {
Object v = props.getProperty(key);
if (v != null) {
- entries.add(new Pair<>(getUnmappedSyspropKey(key), v));
+ entries.add(new SimpleImmutableEntry<>(getUnmappedSyspropKey(key), v));
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
index 6ff6fde..84b019f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/KeyUtils.java
@@ -47,6 +47,7 @@ import java.security.spec.DSAPublicKeySpec;
import java.security.spec.ECParameterSpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.RSAPublicKeySpec;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -71,7 +72,6 @@ import org.apache.sshd.common.digest.DigestUtils;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.OsUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
@@ -186,13 +186,13 @@ public final class KeyUtils {
* @param path The {@link Path} to be checked - ignored if {@code null}
* or does not exist
* @param options The {@link LinkOption}s to use to query the file's permissions
- * @return The violated permission as {@link Pair} first is a message second is
- * offending object {@link PosixFilePermission} or {@link String} for owner - {@code null} if
- * no violations detected
+ * @return The violated permission as {@link SimpleImmutableEntry} where key is a message and
+ * value is the offending object {@link PosixFilePermission} or {@link String} for owner - {@code null}
+ * if no violations detected
* @throws IOException If failed to retrieve the permissions
* @see #STRICTLY_PROHIBITED_FILE_PERMISSION
*/
- public static Pair<String, Object> validateStrictKeyFilePermissions(Path path, LinkOption... options) throws IOException {
+ public static SimpleImmutableEntry<String, Object> validateStrictKeyFilePermissions(Path path, LinkOption... options) throws IOException {
if ((path == null) || (!Files.exists(path, options))) {
return null;
}
@@ -204,20 +204,20 @@ public final class KeyUtils {
if (perms.contains(PosixFilePermission.OTHERS_EXECUTE)) {
PosixFilePermission p = PosixFilePermission.OTHERS_EXECUTE;
- return new Pair<>(String.format("Permissions violation (%s)", p), p);
+ return new SimpleImmutableEntry<>(String.format("Permissions violation (%s)", p), p);
}
if (OsUtils.isUNIX()) {
PosixFilePermission p = IoUtils.validateExcludedPermissions(perms, STRICTLY_PROHIBITED_FILE_PERMISSION);
if (p != null) {
- return new Pair<>(String.format("Permissions violation (%s)", p), p);
+ return new SimpleImmutableEntry<>(String.format("Permissions violation (%s)", p), p);
}
if (Files.isRegularFile(path, options)) {
Path parent = path.getParent();
p = IoUtils.validateExcludedPermissions(IoUtils.getPermissions(parent, options), STRICTLY_PROHIBITED_FILE_PERMISSION);
if (p != null) {
- return new Pair<>(String.format("Parent permissions violation (%s)", p), p);
+ return new SimpleImmutableEntry<>(String.format("Parent permissions violation (%s)", p), p);
}
}
}
@@ -239,14 +239,14 @@ public final class KeyUtils {
}
if (!expected.contains(owner)) {
- return new Pair<>(String.format("Owner violation (%s)", owner), owner);
+ return new SimpleImmutableEntry<>(String.format("Owner violation (%s)", owner), owner);
}
if (OsUtils.isUNIX()) {
if (Files.isRegularFile(path, options)) {
String parentOwner = IoUtils.getFileOwner(path.getParent(), options);
if ((!GenericUtils.isEmpty(parentOwner)) && (!expected.contains(parentOwner))) {
- return new Pair<>(String.format("Parent owner violation (%s)", parentOwner), parentOwner);
+ return new SimpleImmutableEntry<>(String.format("Parent owner violation (%s)", parentOwner), parentOwner);
}
}
}
@@ -581,12 +581,12 @@ public final class KeyUtils {
* @param expected The expected fingerprint if {@code null} or empty then returns a failure
* with the default fingerprint.
* @param key the {@link PublicKey} - if {@code null} then returns null.
- * @return Pair<Boolean, String> - first is success indicator, second is actual fingerprint,
+ * @return SimpleImmutableEntry<Boolean, String> - key is success indicator, value is actual fingerprint,
* {@code null} if no key.
* @see #getDefaultFingerPrintFactory()
* @see #checkFingerPrint(String, Factory, PublicKey)
*/
- public static Pair<Boolean, String> checkFingerPrint(String expected, PublicKey key) {
+ public static SimpleImmutableEntry<Boolean, String> checkFingerPrint(String expected, PublicKey key) {
return checkFingerPrint(expected, getDefaultFingerPrintFactory(), key);
}
@@ -595,10 +595,10 @@ public final class KeyUtils {
* with the default fingerprint.
* @param f The {@link Factory} to be used to generate the default {@link Digest} for the key
* @param key the {@link PublicKey} - if {@code null} then returns null.
- * @return Pair<Boolean, String> - first is success indicator, second is actual fingerprint,
+ * @return SimpleImmutableEntry<Boolean, String> - key is success indicator, value is actual fingerprint,
* {@code null} if no key.
*/
- public static Pair<Boolean, String> checkFingerPrint(String expected, Factory<? extends Digest> f, PublicKey key) {
+ public static SimpleImmutableEntry<Boolean, String> checkFingerPrint(String expected, Factory<? extends Digest> f, PublicKey key) {
return checkFingerPrint(expected, Objects.requireNonNull(f, "No digest factory").create(), key);
}
@@ -607,22 +607,22 @@ public final class KeyUtils {
* with the default fingerprint.
* @param d The {@link Digest} to be used to generate the default fingerprint for the key
* @param key the {@link PublicKey} - if {@code null} then returns null.
- * @return Pair<Boolean, String> - first is success indicator, second is actual fingerprint,
+ * @return SimpleImmutableEntry<Boolean, String> - key is success indicator, value is actual fingerprint,
* {@code null} if no key.
*/
- public static Pair<Boolean, String> checkFingerPrint(String expected, Digest d, PublicKey key) {
+ public static SimpleImmutableEntry<Boolean, String> checkFingerPrint(String expected, Digest d, PublicKey key) {
if (key == null) {
return null;
}
if (GenericUtils.isEmpty(expected)) {
- return new Pair<>(false, getFingerPrint(d, key));
+ return new SimpleImmutableEntry<>(false, getFingerPrint(d, key));
}
// de-construct fingerprint
int pos = expected.indexOf(':');
if ((pos < 0) || (pos >= (expected.length() - 1))) {
- return new Pair<>(false, getFingerPrint(d, key));
+ return new SimpleImmutableEntry<>(false, getFingerPrint(d, key));
}
String name = expected.substring(0, pos);
@@ -632,7 +632,7 @@ public final class KeyUtils {
if (name.length() > 2) {
expectedFactory = BuiltinDigests.fromFactoryName(name);
if (expectedFactory == null) {
- return new Pair<>(false, getFingerPrint(d, key));
+ return new SimpleImmutableEntry<>(false, getFingerPrint(d, key));
}
expected = name.toUpperCase() + ":" + value;
@@ -645,7 +645,7 @@ public final class KeyUtils {
boolean matches = BuiltinDigests.md5.getName().equals(expectedFactory.getName())
? expected.equalsIgnoreCase(fingerprint) // HEX is case insensitive
: expected.equals(fingerprint);
- return new Pair<>(matches, fingerprint);
+ return new SimpleImmutableEntry<>(matches, fingerprint);
}
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/AbstractKeyPairResourceParser.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/AbstractKeyPairResourceParser.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/AbstractKeyPairResourceParser.java
index c2c877f..a83bf68 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/AbstractKeyPairResourceParser.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/AbstractKeyPairResourceParser.java
@@ -30,11 +30,11 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.logging.Level;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.BufferUtils;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
@@ -88,7 +88,7 @@ public abstract class AbstractKeyPairResourceParser extends AbstractLoggingBean
Collection<KeyPair> keyPairs = Collections.emptyList();
List<String> beginMarkers = getBeginners();
List<List<String>> endMarkers = getEndingMarkers();
- for (Pair<Integer, Integer> markerPos = KeyPairResourceParser.findMarkerLine(lines, beginMarkers); markerPos != null;) {
+ for (Map.Entry<Integer, Integer> markerPos = KeyPairResourceParser.findMarkerLine(lines, beginMarkers); markerPos != null;) {
int startIndex = markerPos.getKey();
String startLine = lines.get(startIndex);
startIndex++;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/KeyPairResourceParser.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/KeyPairResourceParser.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/KeyPairResourceParser.java
index 88dd2bd..80fc2c5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/KeyPairResourceParser.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/KeyPairResourceParser.java
@@ -22,6 +22,7 @@ package org.apache.sshd.common.config.keys.loader;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collection;
@@ -31,7 +32,6 @@ import java.util.List;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
/**
@@ -106,11 +106,11 @@ public interface KeyPairResourceParser extends KeyPairResourceLoader {
*
* @param lines The list of lines to scan - ignored if {@code null}/empty
* @param markers The markers to match - ignored if {@code null}/empty
- * @return A {@link Pair} whose key is the <U>first</U> line index
+ * @return A {@link SimpleImmutableEntry} whose key is the <U>first</U> line index
* that matched and value the matched marker index - {@code null} if no match found
* @see #findMarkerLine(List, int, List)
*/
- static Pair<Integer, Integer> findMarkerLine(List<String> lines, List<String> markers) {
+ static SimpleImmutableEntry<Integer, Integer> findMarkerLine(List<String> lines, List<String> markers) {
return findMarkerLine(lines, 0, markers);
}
@@ -120,10 +120,10 @@ public interface KeyPairResourceParser extends KeyPairResourceLoader {
* @param lines The list of lines to scan - ignored if {@code null}/empty
* @param startLine The scan start line index
* @param markers The markers to match - ignored if {@code null}/empty
- * @return A {@link Pair} whose key is the <U>first</U> line index
+ * @return A {@link SimpleImmutableEntry} whose key is the <U>first</U> line index
* that matched and value the matched marker index - {@code null} if no match found
*/
- static Pair<Integer, Integer> findMarkerLine(List<String> lines, int startLine, List<String> markers) {
+ static SimpleImmutableEntry<Integer, Integer> findMarkerLine(List<String> lines, int startLine, List<String> markers) {
if (GenericUtils.isEmpty(lines) || GenericUtils.isEmpty(markers)) {
return null;
}
@@ -133,7 +133,7 @@ public interface KeyPairResourceParser extends KeyPairResourceLoader {
for (int markerIndex = 0; markerIndex < markers.size(); markerIndex++) {
String m = markers.get(markerIndex);
if (l.contains(m)) {
- return new Pair<>(lineIndex, markerIndex);
+ return new SimpleImmutableEntry<>(lineIndex, markerIndex);
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/openssh/OpenSSHKeyPairResourceParser.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/openssh/OpenSSHKeyPairResourceParser.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/openssh/OpenSSHKeyPairResourceParser.java
index bc068ea..b837ab1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/openssh/OpenSSHKeyPairResourceParser.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/openssh/OpenSSHKeyPairResourceParser.java
@@ -31,6 +31,7 @@ import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -48,7 +49,6 @@ import org.apache.sshd.common.config.keys.PrivateKeyEntryDecoder;
import org.apache.sshd.common.config.keys.PublicKeyEntryDecoder;
import org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.BufferUtils;
import org.apache.sshd.common.util.io.IoUtils;
@@ -185,7 +185,7 @@ public class OpenSSHKeyPairResourceParser extends AbstractKeyPairResourceParser
resourceKey, keyIndex, pubType);
}
- Pair<PrivateKey, String> prvData = readPrivateKey(resourceKey, context, pubType, passwordProvider, stream);
+ Map.Entry<PrivateKey, String> prvData = readPrivateKey(resourceKey, context, pubType, passwordProvider, stream);
PrivateKey prvKey = (prvData == null) ? null : prvData.getKey();
ValidateUtils.checkNotNull(prvKey, "Empty private key #%d in %s", keyIndex, resourceKey);
@@ -204,7 +204,7 @@ public class OpenSSHKeyPairResourceParser extends AbstractKeyPairResourceParser
return keyPairs;
}
- protected Pair<PrivateKey, String> readPrivateKey(
+ protected SimpleImmutableEntry<PrivateKey, String> readPrivateKey(
String resourceKey, OpenSSHParserContext context, String keyType, FilePasswordProvider passwordProvider, InputStream stream)
throws IOException, GeneralSecurityException {
String prvType = KeyEntryResolver.decodeString(stream);
@@ -225,7 +225,7 @@ public class OpenSSHKeyPairResourceParser extends AbstractKeyPairResourceParser
}
String comment = KeyEntryResolver.decodeString(stream);
- return new Pair<>(prvKey, comment);
+ return new SimpleImmutableEntry<>(prvKey, comment);
}
protected <S extends InputStream> S validateStreamMagicMarker(String resourceKey, S stream) throws IOException {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/pem/ECDSAPEMResourceKeyPairParser.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/pem/ECDSAPEMResourceKeyPairParser.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/pem/ECDSAPEMResourceKeyPairParser.java
index 9b62ccd..dd8d2ea 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/pem/ECDSAPEMResourceKeyPairParser.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/pem/ECDSAPEMResourceKeyPairParser.java
@@ -32,14 +32,15 @@ import java.security.interfaces.ECPublicKey;
import java.security.spec.ECPoint;
import java.security.spec.ECPrivateKeySpec;
import java.security.spec.ECPublicKeySpec;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.apache.sshd.common.cipher.ECCurves;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.config.keys.KeyUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.io.NoCloseInputStream;
import org.apache.sshd.common.util.io.der.ASN1Object;
import org.apache.sshd.common.util.io.der.ASN1Type;
@@ -73,14 +74,14 @@ public class ECDSAPEMResourceKeyPairParser extends AbstractPEMResourceKeyPairPar
public Collection<KeyPair> extractKeyPairs(
String resourceKey, String beginMarker, String endMarker, FilePasswordProvider passwordProvider, InputStream stream)
throws IOException, GeneralSecurityException {
- Pair<ECPublicKeySpec, ECPrivateKeySpec> spec = decodeECPrivateKeySpec(stream, false);
+ Map.Entry<ECPublicKeySpec, ECPrivateKeySpec> spec = decodeECPrivateKeySpec(stream, false);
if (!SecurityUtils.isECCSupported()) {
throw new NoSuchProviderException("ECC not supported");
}
KeyFactory kf = SecurityUtils.getKeyFactory(KeyUtils.EC_ALGORITHM);
- ECPublicKey pubKey = (ECPublicKey) kf.generatePublic(spec.getFirst());
- ECPrivateKey prvKey = (ECPrivateKey) kf.generatePrivate(spec.getSecond());
+ ECPublicKey pubKey = (ECPublicKey) kf.generatePublic(spec.getKey());
+ ECPrivateKey prvKey = (ECPrivateKey) kf.generatePrivate(spec.getValue());
KeyPair kp = new KeyPair(pubKey, prvKey);
return Collections.singletonList(kp);
}
@@ -105,10 +106,10 @@ public class ECDSAPEMResourceKeyPairParser extends AbstractPEMResourceKeyPairPar
* </CODE></PRE>
* @param inputStream The {@link InputStream} containing the DER encoded data
* @param okToClose {@code true} if OK to close the DER stream once parsing complete
- * @return The decoded {@link Pair} of {@link ECPublicKeySpec} and {@link ECPrivateKeySpec}
+ * @return The decoded {@link SimpleImmutableEntry} of {@link ECPublicKeySpec} and {@link ECPrivateKeySpec}
* @throws IOException If failed to to decode the DER stream
*/
- public static Pair<ECPublicKeySpec, ECPrivateKeySpec> decodeECPrivateKeySpec(InputStream inputStream, boolean okToClose) throws IOException {
+ public static SimpleImmutableEntry<ECPublicKeySpec, ECPrivateKeySpec> decodeECPrivateKeySpec(InputStream inputStream, boolean okToClose) throws IOException {
ASN1Object sequence;
try (DERParser parser = new DERParser(NoCloseInputStream.resolveInputStream(inputStream, okToClose))) {
sequence = parser.readObject();
@@ -128,7 +129,7 @@ public class ECDSAPEMResourceKeyPairParser extends AbstractPEMResourceKeyPairPar
ECPoint w = decodeECPublicKeyValue(curve, parser);
ECPublicKeySpec pubSpec = new ECPublicKeySpec(w, prvSpec.getParams());
- return new Pair<>(pubSpec, prvSpec);
+ return new SimpleImmutableEntry<>(pubSpec, prvSpec);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
index 15d2520..cf3a8a2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
@@ -24,6 +24,7 @@ import java.net.SocketTimeoutException;
import java.net.StandardSocketOptions;
import java.nio.channels.AsynchronousChannelGroup;
import java.nio.channels.NetworkChannel;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -40,25 +41,25 @@ import org.apache.sshd.common.io.IoHandler;
import org.apache.sshd.common.io.IoService;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.closeable.AbstractInnerCloseable;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public abstract class Nio2Service extends AbstractInnerCloseable implements IoService, FactoryManagerHolder {
- public static final Map<String, Pair<SocketOption<?>, Object>> CONFIGURABLE_OPTIONS =
- Collections.unmodifiableMap(new LinkedHashMap<String, Pair<SocketOption<?>, Object>>() {
+ // Note: order may be important so that's why we use a LinkedHashMap
+ public static final Map<String, SimpleImmutableEntry<SocketOption<?>, Object>> CONFIGURABLE_OPTIONS =
+ Collections.unmodifiableMap(new LinkedHashMap<String, SimpleImmutableEntry<SocketOption<?>, Object>>() {
// Not serializing it
private static final long serialVersionUID = 1L;
{
- put(FactoryManager.SOCKET_KEEPALIVE, new Pair<SocketOption<?>, Object>(StandardSocketOptions.SO_KEEPALIVE, null));
- put(FactoryManager.SOCKET_LINGER, new Pair<SocketOption<?>, Object>(StandardSocketOptions.SO_LINGER, null));
- put(FactoryManager.SOCKET_RCVBUF, new Pair<SocketOption<?>, Object>(StandardSocketOptions.SO_RCVBUF, null));
- put(FactoryManager.SOCKET_REUSEADDR, new Pair<SocketOption<?>, Object>(StandardSocketOptions.SO_REUSEADDR, DEFAULT_REUSE_ADDRESS));
- put(FactoryManager.SOCKET_SNDBUF, new Pair<SocketOption<?>, Object>(StandardSocketOptions.SO_SNDBUF, null));
- put(FactoryManager.TCP_NODELAY, new Pair<SocketOption<?>, Object>(StandardSocketOptions.TCP_NODELAY, null));
+ put(FactoryManager.SOCKET_KEEPALIVE, new SimpleImmutableEntry<>(StandardSocketOptions.SO_KEEPALIVE, null));
+ put(FactoryManager.SOCKET_LINGER, new SimpleImmutableEntry<>(StandardSocketOptions.SO_LINGER, null));
+ put(FactoryManager.SOCKET_RCVBUF, new SimpleImmutableEntry<>(StandardSocketOptions.SO_RCVBUF, null));
+ put(FactoryManager.SOCKET_REUSEADDR, new SimpleImmutableEntry<>(StandardSocketOptions.SO_REUSEADDR, DEFAULT_REUSE_ADDRESS));
+ put(FactoryManager.SOCKET_SNDBUF, new SimpleImmutableEntry<>(StandardSocketOptions.SO_SNDBUF, null));
+ put(FactoryManager.TCP_NODELAY, new SimpleImmutableEntry<>(StandardSocketOptions.TCP_NODELAY, null));
}
});
@@ -134,9 +135,9 @@ public abstract class Nio2Service extends AbstractInnerCloseable implements IoSe
return socket;
}
- for (Map.Entry<String, Pair<SocketOption<?>, Object>> ce : CONFIGURABLE_OPTIONS.entrySet()) {
+ for (Map.Entry<String, ? extends Map.Entry<SocketOption<?>, ?>> ce : CONFIGURABLE_OPTIONS.entrySet()) {
String property = ce.getKey();
- Pair<SocketOption<?>, Object> defConfig = ce.getValue();
+ Map.Entry<SocketOption<?>, ?> defConfig = ce.getValue();
@SuppressWarnings("rawtypes")
SocketOption option = defConfig.getKey();
setOption(socket, property, option, defConfig.getValue());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
index 474eda6..28bdcd8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
@@ -23,6 +23,7 @@ import java.io.InterruptedIOException;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.nio.charset.StandardCharsets;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -85,7 +86,6 @@ import org.apache.sshd.common.util.EventListenerUtils;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.Invoker;
import org.apache.sshd.common.util.NumberUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.Readable;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -633,11 +633,11 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
* the next packet MUST be silently ignored
*/
for (KexProposalOption option : new KexProposalOption[]{KexProposalOption.ALGORITHMS, KexProposalOption.SERVERKEYS}) {
- Pair<String, String> result = comparePreferredKexProposalOption(option);
+ Map.Entry<String, String> result = comparePreferredKexProposalOption(option);
if (result != null) {
if (log.isDebugEnabled()) {
log.debug("handleFirstKexPacketFollows({})[{}] 1st follow KEX packet {} option mismatch: client={}, server={}",
- this, SshConstants.getCommandMessageName(cmd), option, result.getFirst(), result.getSecond());
+ this, SshConstants.getCommandMessageName(cmd), option, result.getKey(), result.getValue());
}
return false;
}
@@ -646,12 +646,12 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
return true;
}
- protected Pair<String, String> comparePreferredKexProposalOption(KexProposalOption option) {
+ protected SimpleImmutableEntry<String, String> comparePreferredKexProposalOption(KexProposalOption option) {
String[] clientPreferences = GenericUtils.split(clientProposal.get(option), ',');
String clientValue = clientPreferences[0];
String[] serverPreferences = GenericUtils.split(serverProposal.get(option), ',');
String serverValue = serverPreferences[0];
- return clientValue.equals(serverValue) ? null : new Pair<>(clientValue, serverValue);
+ return clientValue.equals(serverValue) ? null : new SimpleImmutableEntry<>(clientValue, serverValue);
}
protected void handleKexMessage(int cmd, Buffer buffer) throws Exception {
@@ -871,19 +871,19 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
}
- protected List<Pair<PendingWriteFuture, IoWriteFuture>> sendPendingPackets(Queue<PendingWriteFuture> packetsQueue) throws IOException {
+ protected List<SimpleImmutableEntry<PendingWriteFuture, IoWriteFuture>> sendPendingPackets(Queue<PendingWriteFuture> packetsQueue) throws IOException {
if (GenericUtils.isEmpty(packetsQueue)) {
return Collections.emptyList();
}
int numPending = packetsQueue.size();
- List<Pair<PendingWriteFuture, IoWriteFuture>> pendingWrites = new ArrayList<>(numPending);
+ List<SimpleImmutableEntry<PendingWriteFuture, IoWriteFuture>> pendingWrites = new ArrayList<>(numPending);
synchronized (encodeLock) {
for (PendingWriteFuture future = pendingPackets.poll();
future != null;
future = pendingPackets.poll()) {
IoWriteFuture writeFuture = doWritePacket(future.getBuffer());
- pendingWrites.add(new Pair<>(future, writeFuture));
+ pendingWrites.add(new SimpleImmutableEntry<>(future, writeFuture));
}
}
@@ -2648,12 +2648,12 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
long now = System.currentTimeMillis();
- Pair<TimeoutStatus, String> result = checkAuthenticationTimeout(now, getAuthTimeout());
+ Map.Entry<TimeoutStatus, String> result = checkAuthenticationTimeout(now, getAuthTimeout());
if (result == null) {
result = checkIdleTimeout(now, getIdleTimeout());
}
- TimeoutStatus status = (result == null) ? TimeoutStatus.NoTimeout : result.getFirst();
+ TimeoutStatus status = (result == null) ? TimeoutStatus.NoTimeout : result.getKey();
if ((status == null) || TimeoutStatus.NoTimeout.equals(status)) {
return;
}
@@ -2663,7 +2663,7 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
}
timeoutStatus.set(status);
- disconnect(SshConstants.SSH2_DISCONNECT_PROTOCOL_ERROR, result.getSecond());
+ disconnect(SshConstants.SSH2_DISCONNECT_PROTOCOL_ERROR, result.getValue());
}
/**
@@ -2672,15 +2672,15 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
* @param now The current time in millis
* @param authTimeoutMs The configured timeout in millis - if non-positive
* then no timeout
- * @return A {@link Pair} specifying the timeout status and disconnect reason
+ * @return A {@link SimpleImmutableEntry} specifying the timeout status and disconnect reason
* message if timeout expired, {@code null} or {@code NoTimeout} if no timeout
* occurred
* @see #getAuthTimeout()
*/
- protected Pair<TimeoutStatus, String> checkAuthenticationTimeout(long now, long authTimeoutMs) {
+ protected SimpleImmutableEntry<TimeoutStatus, String> checkAuthenticationTimeout(long now, long authTimeoutMs) {
long authDiff = now - authTimeoutStart;
if ((!authed) && (authTimeoutMs > 0L) && (authDiff > authTimeoutMs)) {
- return new Pair<>(TimeoutStatus.AuthTimeout, "Session has timed out waiting for authentication after " + authTimeoutMs + " ms.");
+ return new SimpleImmutableEntry<>(TimeoutStatus.AuthTimeout, "Session has timed out waiting for authentication after " + authTimeoutMs + " ms.");
} else {
return null;
}
@@ -2692,15 +2692,15 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
* @param now The current time in millis
* @param idleTimeoutMs The configured timeout in millis - if non-positive
* then no timeout
- * @return A {@link Pair} specifying the timeout status and disconnect reason
+ * @return A {@link SimpleImmutableEntry} specifying the timeout status and disconnect reason
* message if timeout expired, {@code null} or {@code NoTimeout} if no timeout
* occurred
* @see #getIdleTimeout()
*/
- protected Pair<TimeoutStatus, String> checkIdleTimeout(long now, long idleTimeoutMs) {
+ protected SimpleImmutableEntry<TimeoutStatus, String> checkIdleTimeout(long now, long idleTimeoutMs) {
long idleDiff = now - idleTimeoutStart;
if ((idleTimeoutMs > 0L) && (idleDiff > idleTimeoutMs)) {
- return new Pair<>(TimeoutStatus.IdleTimeout, "User session has timed out idling after " + idleTimeoutMs + " ms.");
+ return new SimpleImmutableEntry<>(TimeoutStatus.IdleTimeout, "User session has timed out idling after " + idleTimeoutMs + " ms.");
} else {
return null;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignature.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignature.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignature.java
index d2849da..ef06d15 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignature.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignature.java
@@ -23,10 +23,10 @@ import java.security.GeneralSecurityException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SignatureException;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Objects;
import org.apache.sshd.common.util.NumberUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.BufferUtils;
import org.apache.sshd.common.util.security.SecurityUtils;
@@ -101,10 +101,10 @@ public abstract class AbstractSignature implements Signature {
* Makes an attempt to detect if the signature is encoded or pure data
*
* @param sig The original signature
- * @return A {@link Pair} where first value is the key type and second
+ * @return A {@link SimpleImmutableEntry} where first value is the key type and second
* value is the data - {@code null} if not encoded
*/
- protected Pair<String, byte[]> extractEncodedSignature(byte[] sig) {
+ protected SimpleImmutableEntry<String, byte[]> extractEncodedSignature(byte[] sig) {
final int dataLen = NumberUtils.length(sig);
// if it is encoded then we must have at least 2 UINT32 values
if (dataLen < (2 * Integer.BYTES)) {
@@ -134,7 +134,7 @@ public abstract class AbstractSignature implements Signature {
String keyType = new String(sig, keyTypeStartPos, (int) keyTypeLen, StandardCharsets.UTF_8);
byte[] data = new byte[(int) dataBytesLen];
System.arraycopy(sig, keyTypeEndPos + Integer.BYTES, data, 0, (int) dataBytesLen);
- return new Pair<>(keyType, data);
+ return new SimpleImmutableEntry<>(keyType, data);
}
protected boolean doVerify(byte[] data) throws SignatureException {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureDSA.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureDSA.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureDSA.java
index ec5797b..1f552bd 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureDSA.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureDSA.java
@@ -21,10 +21,10 @@ package org.apache.sshd.common.signature;
import java.io.StreamCorruptedException;
import java.math.BigInteger;
import java.security.SignatureException;
+import java.util.Map;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.util.NumberUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.BufferUtils;
import org.apache.sshd.common.util.io.der.DERParser;
@@ -101,11 +101,11 @@ public class SignatureDSA extends AbstractSignature {
if (sigLen != DSA_SIGNATURE_LENGTH) {
// probably some encoded data
- Pair<String, byte[]> encoding = extractEncodedSignature(sig);
+ Map.Entry<String, byte[]> encoding = extractEncodedSignature(sig);
if (encoding != null) {
- String keyType = encoding.getFirst();
+ String keyType = encoding.getKey();
ValidateUtils.checkTrue(KeyPairProvider.SSH_DSS.equals(keyType), "Mismatched key type: %s", keyType);
- data = encoding.getSecond();
+ data = encoding.getValue();
sigLen = NumberUtils.length(data);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
index e33a610..56964d3 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureECDSA.java
@@ -20,9 +20,9 @@ package org.apache.sshd.common.signature;
import java.io.StreamCorruptedException;
import java.math.BigInteger;
+import java.util.Map;
import org.apache.sshd.common.cipher.ECCurves;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
@@ -101,12 +101,12 @@ public class SignatureECDSA extends AbstractSignature {
@Override
public boolean verify(byte[] sig) throws Exception {
byte[] data = sig;
- Pair<String, byte[]> encoding = extractEncodedSignature(data);
+ Map.Entry<String, byte[]> encoding = extractEncodedSignature(data);
if (encoding != null) {
- String keyType = encoding.getFirst();
+ String keyType = encoding.getKey();
ECCurves curve = ECCurves.fromKeyType(keyType);
ValidateUtils.checkNotNull(curve, "Unknown curve type: %s", keyType);
- data = encoding.getSecond();
+ data = encoding.getValue();
}
Buffer rsBuf = new ByteArrayBuffer(data);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureRSA.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureRSA.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureRSA.java
index 06dac00..ad1d37e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureRSA.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/SignatureRSA.java
@@ -21,9 +21,9 @@ package org.apache.sshd.common.signature;
import java.math.BigInteger;
import java.security.PublicKey;
import java.security.interfaces.RSAKey;
+import java.util.Map;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
/**
@@ -68,11 +68,11 @@ public class SignatureRSA extends AbstractSignature {
@Override
public boolean verify(byte[] sig) throws Exception {
byte[] data = sig;
- Pair<String, byte[]> encoding = extractEncodedSignature(data);
+ Map.Entry<String, byte[]> encoding = extractEncodedSignature(data);
if (encoding != null) {
- String keyType = encoding.getFirst();
+ String keyType = encoding.getKey();
ValidateUtils.checkTrue(KeyPairProvider.SSH_RSA.equals(keyType), "Mismatched key type: %s", keyType);
- data = encoding.getSecond();
+ data = encoding.getValue();
}
int expectedSize = getVerifierSignatureSize();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/util/Invoker.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/Invoker.java b/sshd-core/src/main/java/org/apache/sshd/common/util/Invoker.java
index ded7fa0..71cbebd 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/Invoker.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/Invoker.java
@@ -18,7 +18,9 @@
*/
package org.apache.sshd.common.util;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
+import java.util.Map;
/**
* The complement to the {@code Callable} interface - accepts one argument
@@ -74,7 +76,7 @@ public interface Invoker<ARG, RET> {
static <ARG> Invoker<ARG, Void> wrapFirst(Collection<? extends Invoker<? super ARG, ?>> invokers) {
return arg -> {
- Pair<Invoker<? super ARG, ?>, Throwable> result = invokeTillFirstFailure(arg, invokers);
+ Map.Entry<Invoker<? super ARG, ?>, Throwable> result = invokeTillFirstFailure(arg, invokers);
if (result != null) {
throw result.getValue();
}
@@ -89,10 +91,10 @@ public interface Invoker<ARG, RET> {
* @param arg The argument to pass to the {@link #invoke(Object)} method
* @param invokers The invokers to scan - ignored if {@code null}/empty
* (also ignores {@code null} members)
- * @return A {@link Pair} representing the <U>first</U> failed invocation
- * - {@code null} if all were successful (or none invoked).
+ * @return A {@link SimpleImmutableEntry} representing the <U>first</U> failed
+ * invocation - {@code null} if all were successful (or none invoked).
*/
- static <ARG> Pair<Invoker<? super ARG, ?>, Throwable> invokeTillFirstFailure(ARG arg, Collection<? extends Invoker<? super ARG, ?>> invokers) {
+ static <ARG> SimpleImmutableEntry<Invoker<? super ARG, ?>, Throwable> invokeTillFirstFailure(ARG arg, Collection<? extends Invoker<? super ARG, ?>> invokers) {
if (GenericUtils.isEmpty(invokers)) {
return null;
}
@@ -105,7 +107,7 @@ public interface Invoker<ARG, RET> {
try {
i.invoke(arg);
} catch (Throwable t) {
- return new Pair<>(i, t);
+ return new SimpleImmutableEntry<>(i, t);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/util/MapEntryUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/MapEntryUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/MapEntryUtils.java
new file mode 100644
index 0000000..7f176e7
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/MapEntryUtils.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.sshd.common.util;
+
+import java.util.Comparator;
+import java.util.Map;
+
+/**
+ * Represents an un-modifiable pair of values
+ *
+ * @param <F> First value type
+ * @param <S> Second value type
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public final class MapEntryUtils {
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private static final Comparator<Map.Entry<Comparable, ?>> BY_KEY_COMPARATOR = (o1, o2) -> {
+ Comparable k1 = o1.getKey();
+ Comparable k2 = o2.getKey();
+ return k1.compareTo(k2);
+ };
+
+ private MapEntryUtils() {
+ throw new UnsupportedOperationException("No instance");
+ }
+
+ /**
+ * @param <K> The {@link Comparable} key type
+ * @param <V> The associated entry value
+ * @return A {@link Comparator} for {@link java.util.Map.Entry}-ies that
+ * compares the key values
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static <K extends Comparable<K>, V> Comparator<Map.Entry<K, V>> byKeyEntryComparator() {
+ return (Comparator) BY_KEY_COMPARATOR;
+ }
+}
\ No newline at end of file