Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/com/hierynomus/sshj/secg/SecgUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.security.spec.EllipticCurve;
import java.util.Arrays;

public class SecgUtils {
public interface SecgUtils {
/**
* SECG 2.3.4 Octet String to ECPoint
*/
public static ECPoint getDecoded(byte[] M, EllipticCurve curve) {
static ECPoint getDecoded(byte[] M, EllipticCurve curve) {
int elementSize = getElementSize(curve);
if (M.length != 2 * elementSize + 1 || M[0] != 0x04) {
throw new SSHRuntimeException("Invalid 'f' for Elliptic Curve " + curve.toString());
Expand All @@ -41,7 +41,7 @@ public static ECPoint getDecoded(byte[] M, EllipticCurve curve) {
/**
* SECG 2.3.3 ECPoint to Octet String
*/
public static byte[] getEncoded(ECPoint point, EllipticCurve curve) {
static byte[] getEncoded(ECPoint point, EllipticCurve curve) {
int elementSize = getElementSize(curve);
byte[] M = new byte[2 * elementSize + 1];
M[0] = 0x04;
Expand All @@ -53,7 +53,7 @@ public static byte[] getEncoded(ECPoint point, EllipticCurve curve) {
return M;
}

private static byte[] stripLeadingZeroes(byte[] bytes) {
static byte[] stripLeadingZeroes(byte[] bytes) {
int start = 0;
while (bytes[start] == 0x0) {
start++;
Expand All @@ -62,7 +62,7 @@ private static byte[] stripLeadingZeroes(byte[] bytes) {
return Arrays.copyOfRange(bytes, start, bytes.length);
}

private static int getElementSize(EllipticCurve curve) {
static int getElementSize(EllipticCurve curve) {
int fieldSize = curve.getField().getFieldSize();
return (fieldSize + 7) / 8;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
import java.io.Reader;
import java.security.PublicKey;

public class OpenSSHKeyFileUtil {
private OpenSSHKeyFileUtil() {
}
public interface OpenSSHKeyFileUtil {

public static File getPublicKeyFile(File privateKeyFile) {
static File getPublicKeyFile(File privateKeyFile) {
File pubKey = new File(privateKeyFile + "-cert.pub");
if (!pubKey.exists()) {
pubKey = new File(privateKeyFile + ".pub");
Expand All @@ -46,7 +44,7 @@ public static File getPublicKeyFile(File privateKeyFile) {
*
* @param publicKey Public key accessible through a {@code Reader}
*/
public static ParsedPubKey initPubKey(Reader publicKey) throws IOException {
static ParsedPubKey initPubKey(Reader publicKey) throws IOException {
try (BufferedReader br = new BufferedReader(publicKey)) {
String keydata;
while ((keydata = br.readLine()) != null) {
Expand All @@ -71,7 +69,7 @@ public static ParsedPubKey initPubKey(Reader publicKey) throws IOException {
}


public static class ParsedPubKey {
class ParsedPubKey {
private final KeyType type;
private final PublicKey pubKey;

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/schmizz/concurrent/ErrorDeliveryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@

import java.util.Collection;

public class ErrorDeliveryUtil {
public interface ErrorDeliveryUtil {

public static void alertPromises(Throwable x, Promise<?, ?>... promises) {
static void alertPromises(Throwable x, Promise<?, ?>... promises) {
for (Promise<?, ?> p : promises)
p.deliverError(x);
}

public static void alertPromises(Throwable x, Collection<? extends Promise<?, ?>> promises) {
static void alertPromises(Throwable x, Collection<? extends Promise<?, ?>> promises) {
for (Promise<?, ?> p : promises)
p.deliverError(x);
}

public static void alertEvents(Throwable x, Event<?>... events) {
static void alertEvents(Throwable x, Event<?>... events) {
for (Event<?> e : events)
e.deliverError(x);
}

public static void alertEvents(Throwable x, Collection<? extends Event<?>> events) {
static void alertEvents(Throwable x, Collection<? extends Event<?>> events) {
for (Event<?> e : events)
e.deliverError(x);
}
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/net/schmizz/sshj/common/Base64Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package net.schmizz.sshj.common;

import java.io.IOException;
import java.util.Base64;

/**
Expand All @@ -25,19 +24,17 @@
*
* <p>Please use this class instead of {@link java.util.Base64.Decoder}.</p>
*/
public class Base64Decoder {
private Base64Decoder() {
}
public interface Base64Decoder {

public static byte[] decode(byte[] source) throws Base64DecodingException {
static byte[] decode(byte[] source) throws Base64DecodingException {
try {
return Base64.getDecoder().decode(source);
} catch (IllegalArgumentException err) {
throw new Base64DecodingException(err);
}
}

public static byte[] decode(String src) throws Base64DecodingException {
static byte[] decode(String src) throws Base64DecodingException {
try {
return Base64.getDecoder().decode(src);
} catch (IllegalArgumentException err) {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/net/schmizz/sshj/common/ByteArrayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import java.util.Arrays;

/** Utility functions for byte arrays. */
public class ByteArrayUtils {
public interface ByteArrayUtils {

final static char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

/**
* Check whether some part or whole of two byte arrays is equal, for <code>length</code> bytes starting at some
Expand All @@ -38,7 +38,7 @@ public class ByteArrayUtils {
*
* @return <code>true</code> or <code>false</code>
*/
public static boolean equals(byte[] a1, int a1Offset, byte[] a2, int a2Offset, int length) {
static boolean equals(byte[] a1, int a1Offset, byte[] a2, int a2Offset, int length) {
if (a1.length < a1Offset + length || a2.length < a2Offset + length)
return false;
while (length-- > 0)
Expand All @@ -57,7 +57,7 @@ public static boolean equals(byte[] a1, int a1Offset, byte[] a2, int a2Offset, i
*
* @return hex string, each octet delimited by a space
*/
public static String printHex(byte[] array, int offset, int len) {
static String printHex(byte[] array, int offset, int len) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) {
byte b = array[offset + i];
Expand All @@ -76,7 +76,7 @@ public static String printHex(byte[] array, int offset, int len) {
*
* @return hex string
*/
public static String toHex(byte[] array) {
static String toHex(byte[] array) {
return toHex(array, 0, array.length);
}

Expand All @@ -90,7 +90,7 @@ public static String toHex(byte[] array) {
*
* @return hex string
*/
public static String toHex(byte[] array, int offset, int len) {
static String toHex(byte[] array, int offset, int len) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) {
byte b = array[offset + i];
Expand All @@ -101,7 +101,7 @@ public static String toHex(byte[] array, int offset, int len) {
}


public static byte[] parseHex(String hex) {
static byte[] parseHex(String hex) {
if (hex == null) {
throw new IllegalArgumentException("Hex string is null");
}
Expand All @@ -118,7 +118,7 @@ public static byte[] parseHex(String hex) {
return result;
}

private static int parseHexDigit(char c) {
static int parseHexDigit(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
Expand All @@ -140,7 +140,7 @@ private static int parseHexDigit(char c) {
*
* @return UTF-8 bytes of the string
*/
public static byte[] encodeSensitiveStringToUtf8(char[] str) {
static byte[] encodeSensitiveStringToUtf8(char[] str) {
CharsetEncoder charsetEncoder = StandardCharsets.UTF_8.newEncoder();
ByteBuffer utf8Buffer = ByteBuffer.allocate((int) (str.length * charsetEncoder.maxBytesPerChar()));
assert utf8Buffer.hasArray();
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/net/schmizz/sshj/common/ECDSAKeyFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@
/**
* Factory for generating Elliptic Curve Keys using Java Security components for NIST Curves
*/
public class ECDSAKeyFactory {

private ECDSAKeyFactory() {

}
public interface ECDSAKeyFactory {

/**
* Get Elliptic Curve Private Key for private key value and Curve Name
Expand All @@ -47,7 +43,7 @@ private ECDSAKeyFactory() {
* @return Elliptic Curve Private Key
* @throws GeneralSecurityException Thrown on failure to create parameter specification
*/
public static PrivateKey getPrivateKey(final BigInteger privateKeyInteger, final ECDSACurve ecdsaCurve) throws GeneralSecurityException {
static PrivateKey getPrivateKey(final BigInteger privateKeyInteger, final ECDSACurve ecdsaCurve) throws GeneralSecurityException {
Objects.requireNonNull(privateKeyInteger, "Private Key integer required");
Objects.requireNonNull(ecdsaCurve, "Curve required");

Expand All @@ -66,7 +62,7 @@ public static PrivateKey getPrivateKey(final BigInteger privateKeyInteger, final
* @return Elliptic Curve Public Key
* @throws GeneralSecurityException Thrown on failure to create parameter specification
*/
public static PublicKey getPublicKey(final ECPoint point, final ECDSACurve ecdsaCurve) throws GeneralSecurityException {
static PublicKey getPublicKey(final ECPoint point, final ECDSACurve ecdsaCurve) throws GeneralSecurityException {
Objects.requireNonNull(point, "Elliptic Curve Point required");
Objects.requireNonNull(ecdsaCurve, "Curve required");

Expand All @@ -77,7 +73,7 @@ public static PublicKey getPublicKey(final ECPoint point, final ECDSACurve ecdsa
return keyFactory.generatePublic(publicKeySpec);
}

private static ECParameterSpec getParameterSpec(final ECDSACurve ecdsaCurve) throws GeneralSecurityException {
static ECParameterSpec getParameterSpec(final ECDSACurve ecdsaCurve) throws GeneralSecurityException {
final ECGenParameterSpec genParameterSpec = new ECGenParameterSpec(ecdsaCurve.getCurveName());
final AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance(KeyAlgorithm.EC_KEYSTORE);
algorithmParameters.init(genParameterSpec);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/schmizz/sshj/common/ErrorNotifiable.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
public interface ErrorNotifiable {

/** Utility functions. */
class Util {
interface Util {

/** Notify all {@code notifiables} of given {@code error}. */
public static void alertAll(SSHException error, ErrorNotifiable... notifiables) {
static void alertAll(SSHException error, ErrorNotifiable... notifiables) {
for (ErrorNotifiable notifiable : notifiables)
notifiable.notifyError(error);
}

/** Notify all {@code notifiables} of given {@code error}. */
public static void alertAll(SSHException error, Collection<? extends ErrorNotifiable> notifiables) {
static void alertAll(SSHException error, Collection<? extends ErrorNotifiable> notifiables) {
for (ErrorNotifiable notifiable : notifiables)
notifiable.notifyError(error);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/schmizz/sshj/common/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
import java.io.IOException;
import java.io.InputStream;

public class IOUtils {
public interface IOUtils {

public static void closeQuietly(Closeable... closeables) {
static void closeQuietly(Closeable... closeables) {
closeQuietly(LoggerFactory.DEFAULT, closeables);
}

public static ByteArrayOutputStream readFully(InputStream stream)
static ByteArrayOutputStream readFully(InputStream stream)
throws IOException {
return readFully(stream, LoggerFactory.DEFAULT);
}

public static void closeQuietly(LoggerFactory loggerFactory, Closeable... closeables) {
static void closeQuietly(LoggerFactory loggerFactory, Closeable... closeables) {
for (Closeable c : closeables) {
try {
if (c != null)
Expand All @@ -42,7 +42,7 @@ public static void closeQuietly(LoggerFactory loggerFactory, Closeable... closea
}
}

public static ByteArrayOutputStream readFully(InputStream stream, LoggerFactory loggerFactory)
static ByteArrayOutputStream readFully(InputStream stream, LoggerFactory loggerFactory)
throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
new StreamCopier(stream, baos, loggerFactory).copy();
Expand Down
Loading