Skip to content

Commit

Permalink
Fixed formatting warnings of Codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
hierynomus committed Sep 13, 2016
1 parent a2fb4fb commit c9775ca
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 82 deletions.
37 changes: 0 additions & 37 deletions src/main/java/net/schmizz/sshj/transport/TransportImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,43 +223,6 @@ private String readIdentification(Buffer.PlainBuffer buffer)
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,
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/net/schmizz/sshj/transport/digest/SHA384.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/net/schmizz/sshj/transport/digest/SHA512.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
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 {

Expand Down Expand Up @@ -171,7 +173,7 @@ protected KeyPair readKeyPair()
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)) {
Expand All @@ -183,7 +185,7 @@ protected KeyPair readKeyPair()
} 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);
Expand Down Expand Up @@ -239,7 +241,7 @@ private byte[] getPassphraseBytes() {
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;
}

Expand All @@ -256,20 +258,20 @@ private byte[] decrypt(byte[] raw, Cipher cipher, byte[] iv) throws DecryptExcep
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);
tmp = md5.digest();
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]) {
Expand All @@ -280,7 +282,7 @@ private byte[] decrypt(byte[] raw, Cipher cipher, byte[] iv) throws DecryptExcep
}

class ASN1Data {
static final byte MAGIC = (byte)0x30;
static final byte MAGIC = (byte) 0x30;

private byte[] buff;
private int index, length;
Expand Down
24 changes: 12 additions & 12 deletions src/test/java/net/schmizz/sshj/sftp/FileModeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@

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));
}
}

0 comments on commit c9775ca

Please sign in to comment.