// Path: src/test/java/org/apache/sshd/util/test/JSchLogger.java
// public class JSchLogger implements Logger {
//     private final org.slf4j.Logger log = LoggerFactory.getLogger(JSch.class);
// 
//     public JSchLogger() {
//         super();
//     }
// 
//     @Override
//     public boolean isEnabled(int level) {
//         switch (level) {
//             case INFO:  // INFO is too "chatty" so we map it to debug
//             case DEBUG:
//                 return log.isDebugEnabled();
//             case WARN:
//                 return log.isWarnEnabled();
//             case ERROR:
//                 return log.isErrorEnabled();
//             case FATAL:
//                 return log.isErrorEnabled();
//             default:
//                 return false;
//         }
//     }
// 
//     @Override
//     public void log(int level, String message) {
//         switch (level) {
//             case INFO:  // INFO is too "chatty" so we map it to debug
//             case DEBUG:
//                 log.debug(message);
//                 break;
//             case WARN:
//                 log.warn(message);
//                 break;
//             case ERROR:
//             case FATAL:
//                 log.error(message);
//                 break;
//             default:
//                 log.error("[LEVEL=" + level + "]: " + message);
//         }
//     }
// 
//     public static void init() {
//         JSch.setLogger(new JSchLogger());
//     }
// }
// 
// Path: src/test/java/org/apache/sshd/util/test/OutputCountTrackingOutputStream.java
// public class OutputCountTrackingOutputStream extends FilterOutputStream {
//     protected long writeCount;
// 
//     public OutputCountTrackingOutputStream(OutputStream out) {
//         super(out);
//     }
// 
//     @Override
//     public void write(int b) throws IOException {
//         out.write(b);
//         updateWriteCount(1L);
//     }
// 
//     @Override
//     public void write(byte[] b, int off, int len) throws IOException {
//         out.write(b, off, len); // don't call super since it calls the single 'write'
//         updateWriteCount(len);
//     }
// 
//     public long getWriteCount() {
//         return writeCount;
//     }
// 
//     protected long updateWriteCount(long delta) {
//         writeCount += delta;
//         return writeCount;
//     }
// }


import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import com.jcraft.jsch.JSch;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.channel.ClientChannel;
import org.apache.sshd.client.channel.ClientChannelEvent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.cipher.BuiltinCiphers;
import org.apache.sshd.common.future.KeyExchangeFuture;
import org.apache.sshd.common.kex.BuiltinDHFactories;
import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.session.SessionListener;
import org.apache.sshd.common.subsystem.sftp.SftpConstants;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.common.util.io.NullOutputStream;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.util.test.BaseTestSupport;
import org.apache.sshd.util.test.JSchLogger;
import org.apache.sshd.util.test.OutputCountTrackingOutputStream;
import org.apache.sshd.util.test.SimpleUserInfo;
import org.apache.sshd.util.test.TeeOutputStream;
import org.junit.After;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
                     }

                     @Override
                     public void write(byte[] b, int off, int len) {
                         super.write(b, off, len);
                         updateWriteCount(len);
                         pipedCount.release(len);
                     }

                     private void updateWriteCount(long delta) {
                         writeCount += delta;
                         outputDebugMessage("OUT write count=%d", writeCount);
                     }
                 }) {
                session.addPasswordIdentity(getCurrentTestName());
                session.auth().verify(5L, TimeUnit.SECONDS);

                byte[] sentData;
                try (ChannelShell channel = session.createShellChannel();
                     PipedOutputStream pipedIn = new PipedOutputStream();
                     OutputStream sentTracker = new OutputCountTrackingOutputStream(sent) {
                         @Override
                         protected long updateWriteCount(long delta) {
                             long result = super.updateWriteCount(delta);
                             outputDebugMessage("SENT write count=%d", result);
                             return result;
                         }
                     };
                     OutputStream teeOut = new TeeOutputStream(sentTracker, pipedIn);
                     OutputStream stderr = new NullOutputStream();
// Path: src/test/java/org/apache/sshd/util/test/JSchLogger.java
// public class JSchLogger implements Logger {
//     private final org.slf4j.Logger log = LoggerFactory.getLogger(JSch.class);
// 
//     public JSchLogger() {
//         super();
//     }
// 
//     @Override
//     public boolean isEnabled(int level) {
//         switch (level) {
//             case INFO:  // INFO is too "chatty" so we map it to debug
//             case DEBUG:
//                 return log.isDebugEnabled();
//             case WARN:
//                 return log.isWarnEnabled();
//             case ERROR:
//                 return log.isErrorEnabled();
//             case FATAL:
//                 return log.isErrorEnabled();
//             default:
//                 return false;
//         }
//     }
// 
//     @Override
//     public void log(int level, String message) {
//         switch (level) {
//             case INFO:  // INFO is too "chatty" so we map it to debug
//             case DEBUG:
//                 log.debug(message);
//                 break;
//             case WARN:
//                 log.warn(message);
//                 break;
//             case ERROR:
//             case FATAL:
//                 log.error(message);
//                 break;
//             default:
//                 log.error("[LEVEL=" + level + "]: " + message);
//         }
//     }
// 
//     public static void init() {
//         JSch.setLogger(new JSchLogger());
//     }
// }
// 
// Path: src/test/java/org/apache/sshd/util/test/OutputCountTrackingOutputStream.java
// public class OutputCountTrackingOutputStream extends FilterOutputStream {
//     protected long writeCount;
// 
//     public OutputCountTrackingOutputStream(OutputStream out) {
//         super(out);
//     }
// 
//     @Override
//     public void write(int b) throws IOException {
//         out.write(b);
//         updateWriteCount(1L);
//     }
// 
//     @Override
//     public void write(byte[] b, int off, int len) throws IOException {
//         out.write(b, off, len); // don't call super since it calls the single 'write'
//         updateWriteCount(len);
//     }
// 
//     public long getWriteCount() {
//         return writeCount;
//     }
// 
//     protected long updateWriteCount(long delta) {
//         writeCount += delta;
//         return writeCount;
//     }
// }


// Path: src/test/java/org/apache/sshd/KeyReExchangeTest.java
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import com.jcraft.jsch.JSch;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.channel.ClientChannel;
import org.apache.sshd.client.channel.ClientChannelEvent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.cipher.BuiltinCiphers;
import org.apache.sshd.common.future.KeyExchangeFuture;
import org.apache.sshd.common.kex.BuiltinDHFactories;
import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.session.SessionListener;
import org.apache.sshd.common.subsystem.sftp.SftpConstants;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.common.util.io.NullOutputStream;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.util.test.BaseTestSupport;
import org.apache.sshd.util.test.JSchLogger;
import org.apache.sshd.util.test.OutputCountTrackingOutputStream;
import org.apache.sshd.util.test.SimpleUserInfo;
import org.apache.sshd.util.test.TeeOutputStream;
import org.junit.After;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

                     }

                     @Override
                     public void write(byte[] b, int off, int len) {
                         super.write(b, off, len);
                         updateWriteCount(len);
                         pipedCount.release(len);
                     }

                     private void updateWriteCount(long delta) {
                         writeCount += delta;
                         outputDebugMessage("OUT write count=%d", writeCount);
                     }
                 }) {
                session.addPasswordIdentity(getCurrentTestName());
                session.auth().verify(5L, TimeUnit.SECONDS);

                byte[] sentData;
                try (ChannelShell channel = session.createShellChannel();
                     PipedOutputStream pipedIn = new PipedOutputStream();
                     OutputStream sentTracker = new OutputCountTrackingOutputStream(sent) {
                         @Override
                         protected long updateWriteCount(long delta) {
                             long result = super.updateWriteCount(delta);
                             outputDebugMessage("SENT write count=%d", result);
                             return result;
                         }
                     };
                     OutputStream teeOut = new TeeOutputStream(sentTracker, pipedIn);
                     OutputStream stderr = new NullOutputStream();
                     OutputStream stdout = new OutputCountTrackingOutputStream(out) {