Fixed formatting warnings of Codacy

This commit is contained in:
Jeroen van Erp
2016-09-13 15:34:08 +02:00
parent a2fb4fbd98
commit c9775ca2c7
5 changed files with 57 additions and 84 deletions

View File

@@ -223,43 +223,6 @@ public final class TransportImpl
if (ident.isEmpty()) {
return ident;
}
//
// byte[] data = new byte[256];
// for (; ; ) {
// int savedBufPos = buffer.rpos();
// int pos = 0;
// boolean needLF = false;
// for (; ; ) {
// if (buffer.available() == 0) {
// // Need more data, so undo reading and return null
// buffer.rpos(savedBufPos);
// return "";
// }
// byte b = buffer.readByte();
// if (b == '\r') {
// needLF = true;
// continue;
// }
// if (b == '\n')
// break;
// if (needLF) {
// log.error("Incorrect identification, was expecting a '\n' after the '\r', got: '{}' (hex: {})", b, Integer.toHexString(b & 0xFF));
// log.error("Data received up til here was: {}", new String(data, 0, pos));
// throw new TransportException("Incorrect identification: bad line ending: " + ByteArrayUtils.toHex(data, 0, pos));
// }
// if (pos >= data.length) {
// log.error("Incorrect identification String received, line was longer than expected: {}", new String(data, 0, pos));
// log.error("Just for good measure, bytes were: {}", ByteArrayUtils.printHex(data, 0, pos));
// throw new TransportException("Incorrect identification: line too long: " + ByteArrayUtils.printHex(data, 0, pos));
// }
// data[pos++] = b;
// }
// ident = new String(data, 0, pos);
// if (ident.startsWith("SSH-"))
// break;
// if (buffer.rpos() > 16 * 1024)
// throw new TransportException("Incorrect identification: too many header lines");
// }
if (!ident.startsWith("SSH-2.0-") && !ident.startsWith("SSH-1.99-"))
throw new TransportException(DisconnectReason.PROTOCOL_VERSION_NOT_SUPPORTED,

View File

@@ -16,22 +16,26 @@
package net.schmizz.sshj.transport.digest;
public class SHA384 extends BaseDigest {
/** Named factory for SHA384 digest */
public static class Factory
implements net.schmizz.sshj.common.Factory.Named<Digest> {
/**
* Named factory for SHA384 digest
*/
public static class Factory
implements net.schmizz.sshj.common.Factory.Named<Digest> {
@Override
public Digest create() {
return new SHA384();
@Override
public Digest create() {
return new SHA384();
}
@Override
public String getName() {
return "sha384";
}
}
@Override
public String getName() {
return "sha384";
}
}
/** Create a new instance of a SHA384 digest */
/**
* Create a new instance of a SHA384 digest
*/
public SHA384() {
super("SHA-384", 48);
}

View File

@@ -16,22 +16,26 @@
package net.schmizz.sshj.transport.digest;
public class SHA512 extends BaseDigest {
/** Named factory for SHA384 digest */
public static class Factory
implements net.schmizz.sshj.common.Factory.Named<Digest> {
/**
* Named factory for SHA384 digest
*/
public static class Factory
implements net.schmizz.sshj.common.Factory.Named<Digest> {
@Override
public Digest create() {
return new SHA512();
@Override
public Digest create() {
return new SHA512();
}
@Override
public String getName() {
return "sha512";
}
}
@Override
public String getName() {
return "sha512";
}
}
/** Create a new instance of a SHA384 digest */
/**
* Create a new instance of a SHA384 digest
*/
public SHA512() {
super("SHA-512", 64);
}

View File

@@ -32,7 +32,9 @@ import java.security.*;
import java.security.spec.*;
import java.util.Arrays;
/** Represents a PKCS5-encoded key file. This is the format typically used by OpenSSH, OpenSSL, Amazon, etc. */
/**
* Represents a PKCS5-encoded key file. This is the format typically used by OpenSSH, OpenSSL, Amazon, etc.
*/
public class PKCS5KeyFile
implements FileKeyProvider {
@@ -171,7 +173,7 @@ public class PKCS5KeyFile
if (ptr == -1) {
throw new FormatException("Unrecognized DEK-Info: " + line.substring(10));
} else {
String algorithm = line.substring(10,ptr);
String algorithm = line.substring(10, ptr);
if ("DES-EDE3-CBC".equals(algorithm)) {
cipher = new TripleDESCBC();
} else if ("AES-128-CBC".equals(algorithm)) {
@@ -183,7 +185,7 @@ public class PKCS5KeyFile
} else {
throw new FormatException("Not a supported algorithm: " + algorithm);
}
iv = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(line.substring(ptr+1)), 0, cipher.getIVSize());
iv = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(line.substring(ptr + 1)), 0, cipher.getIVSize());
}
} else if (line.length() > 0) {
sb.append(line);
@@ -239,7 +241,7 @@ public class PKCS5KeyFile
ByteBuffer bb = IOUtils.UTF8.encode(cb);
byte[] result = Arrays.copyOfRange(bb.array(), bb.position(), bb.limit());
Arrays.fill(cb.array(), '\u0000');
Arrays.fill(bb.array(), (byte)0);
Arrays.fill(bb.array(), (byte) 0);
return result;
}
@@ -256,9 +258,9 @@ public class PKCS5KeyFile
byte[] hn = new byte[hnlen];
byte[] tmp = null;
byte[] passphrase = getPassphraseBytes();
for (int i=0; i + hsize <= hn.length;) {
for (int i = 0; i + hsize <= hn.length; ) {
if (tmp != null) {
md5.update(tmp, 0, tmp.length);
md5.update(tmp, 0, tmp.length);
}
md5.update(passphrase, 0, passphrase.length);
md5.update(iv, 0, iv.length > 8 ? 8 : iv.length);
@@ -266,10 +268,10 @@ public class PKCS5KeyFile
System.arraycopy(tmp, 0, hn, i, tmp.length);
i += tmp.length;
}
Arrays.fill(passphrase, (byte)0);
Arrays.fill(passphrase, (byte) 0);
byte[] key = Arrays.copyOfRange(hn, 0, bsize);
cipher.init(Cipher.Mode.Decrypt, key, iv);
Arrays.fill(key, (byte)0);
Arrays.fill(key, (byte) 0);
byte[] decrypted = Arrays.copyOf(raw, raw.length);
cipher.update(decrypted, 0, decrypted.length);
if (ASN1Data.MAGIC == decrypted[0]) {
@@ -280,7 +282,7 @@ public class PKCS5KeyFile
}
class ASN1Data {
static final byte MAGIC = (byte)0x30;
static final byte MAGIC = (byte) 0x30;
private byte[] buff;
private int index, length;

View File

@@ -22,17 +22,17 @@ import static org.junit.Assert.assertThat;
public class FileModeTest {
@Test
public void shouldDetectDirectoryWithLinuxMask() {
FileMode fileMode = new FileMode(040755);
assertThat(fileMode.toString(), equalTo("[mask=40755]"));
assertThat(fileMode.getType(), equalTo(FileMode.Type.DIRECTORY));
}
@Test
public void shouldDetectDirectoryWithLinuxMask() {
FileMode fileMode = new FileMode(040755);
assertThat(fileMode.toString(), equalTo("[mask=40755]"));
assertThat(fileMode.getType(), equalTo(FileMode.Type.DIRECTORY));
}
@Test
public void shouldDetectDirectoryWithAixUnixMask() {
FileMode fileMode = new FileMode(0240755);
assertThat(fileMode.toString(), equalTo("[mask=240755]"));
assertThat(fileMode.getType(), equalTo(FileMode.Type.DIRECTORY));
}
@Test
public void shouldDetectDirectoryWithAixUnixMask() {
FileMode fileMode = new FileMode(0240755);
assertThat(fileMode.toString(), equalTo("[mask=240755]"));
assertThat(fileMode.getType(), equalTo(FileMode.Type.DIRECTORY));
}
}