mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 07:10:53 +03:00
Remove jzlib dependency (#772)
* Remove jzlib dependency * Document the Java 7 prerequisite
This commit is contained in:
@@ -95,7 +95,7 @@ If you need something that is not included, it shouldn't be too hard to add (do
|
|||||||
http://ssh-comparison.quendi.de/comparison.html[SSH Implementation Comparison]
|
http://ssh-comparison.quendi.de/comparison.html[SSH Implementation Comparison]
|
||||||
|
|
||||||
== Dependencies
|
== Dependencies
|
||||||
Java 6+. http://www.slf4j.org/download.html[slf4j] is required. http://www.bouncycastle.org/java.html[bouncycastle] is highly recommended and required for using some of the crypto algorithms. http://www.jcraft.com/jzlib/[jzlib] is required for using zlib compression.
|
Java 7+. http://www.slf4j.org/download.html[slf4j] is required. http://www.bouncycastle.org/java.html[bouncycastle] is highly recommended and required for using some of the crypto algorithms.
|
||||||
|
|
||||||
== Reporting bugs
|
== Reporting bugs
|
||||||
Issue tracker: https://github.com/hierynomus/sshj/issues
|
Issue tracker: https://github.com/hierynomus/sshj/issues
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ dependencies {
|
|||||||
compile "org.slf4j:slf4j-api:1.7.7"
|
compile "org.slf4j:slf4j-api:1.7.7"
|
||||||
compile "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion"
|
compile "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion"
|
||||||
compile "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"
|
compile "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"
|
||||||
compile "com.jcraft:jzlib:1.1.3"
|
|
||||||
|
|
||||||
testCompile "junit:junit:4.11"
|
testCompile "junit:junit:4.11"
|
||||||
testCompile "org.mockito:mockito-core:1.9.5"
|
testCompile "org.mockito:mockito-core:1.9.5"
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ dependencies {
|
|||||||
implementation "org.slf4j:slf4j-api:1.7.36"
|
implementation "org.slf4j:slf4j-api:1.7.36"
|
||||||
implementation "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion"
|
implementation "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion"
|
||||||
implementation "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"
|
implementation "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"
|
||||||
implementation "com.jcraft:jzlib:1.1.3"
|
|
||||||
implementation "com.hierynomus:asn-one:0.6.0"
|
implementation "com.hierynomus:asn-one:0.6.0"
|
||||||
|
|
||||||
implementation "net.i2p.crypto:eddsa:0.3.0"
|
implementation "net.i2p.crypto:eddsa:0.3.0"
|
||||||
|
|||||||
@@ -15,18 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package net.schmizz.sshj.transport.compression;
|
package net.schmizz.sshj.transport.compression;
|
||||||
|
|
||||||
import com.jcraft.jzlib.Deflater;
|
import java.util.zip.DataFormatException;
|
||||||
import com.jcraft.jzlib.GZIPException;
|
import java.util.zip.Deflater;
|
||||||
import com.jcraft.jzlib.Inflater;
|
import java.util.zip.Inflater;
|
||||||
import com.jcraft.jzlib.JZlib;
|
|
||||||
import net.schmizz.sshj.common.Buffer;
|
import net.schmizz.sshj.common.Buffer;
|
||||||
import net.schmizz.sshj.common.DisconnectReason;
|
import net.schmizz.sshj.common.DisconnectReason;
|
||||||
import net.schmizz.sshj.common.SSHRuntimeException;
|
|
||||||
import net.schmizz.sshj.transport.TransportException;
|
import net.schmizz.sshj.transport.TransportException;
|
||||||
|
import net.schmizz.sshj.transport.compression.Compression;
|
||||||
|
|
||||||
/** ZLib based Compression. */
|
public class ZlibCompression implements Compression {
|
||||||
public class ZlibCompression
|
|
||||||
implements Compression {
|
|
||||||
|
|
||||||
/** Named factory for the ZLib Compression. */
|
/** Named factory for the ZLib Compression. */
|
||||||
public static class Factory
|
public static class Factory
|
||||||
@@ -52,19 +50,15 @@ public class ZlibCompression
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Mode mode) {
|
public void init(Mode mode) {
|
||||||
try {
|
switch (mode) {
|
||||||
switch (mode) {
|
case DEFLATE:
|
||||||
case DEFLATE:
|
deflater = new Deflater(Deflater.DEFAULT_COMPRESSION);
|
||||||
deflater = new Deflater(JZlib.Z_DEFAULT_COMPRESSION);
|
break;
|
||||||
break;
|
case INFLATE:
|
||||||
case INFLATE:
|
inflater = new Inflater();
|
||||||
inflater = new Inflater();
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
assert false;
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
} catch (GZIPException gze) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,43 +69,28 @@ public class ZlibCompression
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void compress(Buffer buffer) {
|
public void compress(Buffer buffer) {
|
||||||
deflater.setNextIn(buffer.array());
|
deflater.setInput(buffer.array(), buffer.rpos(), buffer.available());
|
||||||
deflater.setNextInIndex(buffer.rpos());
|
|
||||||
deflater.setAvailIn(buffer.available());
|
|
||||||
buffer.wpos(buffer.rpos());
|
buffer.wpos(buffer.rpos());
|
||||||
do {
|
do {
|
||||||
deflater.setNextOut(tempBuf);
|
final int len = deflater.deflate(tempBuf, 0, BUF_SIZE, Deflater.SYNC_FLUSH);
|
||||||
deflater.setNextOutIndex(0);
|
buffer.putRawBytes(tempBuf, 0, len);
|
||||||
deflater.setAvailOut(BUF_SIZE);
|
} while (!deflater.needsInput());
|
||||||
final int status = deflater.deflate(JZlib.Z_PARTIAL_FLUSH);
|
|
||||||
if (status == JZlib.Z_OK) {
|
|
||||||
buffer.putRawBytes(tempBuf, 0, BUF_SIZE - deflater.getAvailOut());
|
|
||||||
} else {
|
|
||||||
throw new SSHRuntimeException("compress: deflate returned " + status);
|
|
||||||
}
|
|
||||||
} while (deflater.getAvailOut() == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uncompress(Buffer from, Buffer to)
|
public void uncompress(Buffer from, Buffer to)
|
||||||
throws TransportException {
|
throws TransportException {
|
||||||
inflater.setNextIn(from.array());
|
inflater.setInput(from.array(), from.rpos(), from.available());
|
||||||
inflater.setNextInIndex(from.rpos());
|
|
||||||
inflater.setAvailIn(from.available());
|
|
||||||
while (true) {
|
while (true) {
|
||||||
inflater.setNextOut(tempBuf);
|
try {
|
||||||
inflater.setNextOutIndex(0);
|
int len = inflater.inflate(tempBuf, 0, BUF_SIZE);
|
||||||
inflater.setAvailOut(BUF_SIZE);
|
if(len > 0) {
|
||||||
final int status = inflater.inflate(JZlib.Z_PARTIAL_FLUSH);
|
to.putRawBytes(tempBuf, 0, len);
|
||||||
switch (status) {
|
} else {
|
||||||
case JZlib.Z_OK:
|
|
||||||
to.putRawBytes(tempBuf, 0, BUF_SIZE - inflater.getAvailOut());
|
|
||||||
break;
|
|
||||||
case JZlib.Z_BUF_ERROR:
|
|
||||||
return;
|
return;
|
||||||
default:
|
}
|
||||||
throw new TransportException(DisconnectReason.COMPRESSION_ERROR, "uncompress: inflate returned " + status);
|
} catch (DataFormatException e) {
|
||||||
|
throw new TransportException(DisconnectReason.COMPRESSION_ERROR, "uncompress: inflate returned " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user