提交 69d95cb2 编写于 作者: K Kohsuke Kawaguchi

added more convenience method

上级 25b5c6cb
......@@ -58,6 +58,7 @@ import java.security.spec.DSAPrivateKeySpec;
import java.security.spec.DSAPublicKeySpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
......@@ -150,7 +151,7 @@ public class CLI {
}
public int execute(List<String> args, InputStream stdin, OutputStream stdout, OutputStream stderr) {
return entryPoint.main(args,Locale.getDefault(),
return entryPoint.main(args, Locale.getDefault(),
new RemoteInputStream(stdin),
new RemoteOutputStream(stdout),
new RemoteOutputStream(stderr));
......@@ -282,7 +283,10 @@ public class CLI {
}
}
private static KeyPair loadKey(File f) throws IOException, GeneralSecurityException {
/**
* Loads RSA/DSA private key in a PEM format into {@link KeyPair}.
*/
public static KeyPair loadKey(File f) throws IOException, GeneralSecurityException {
DataInputStream dis = new DataInputStream(new FileInputStream(f));
byte[] bytes = new byte[(int) f.length()];
dis.readFully(bytes);
......@@ -290,6 +294,9 @@ public class CLI {
return loadKey(new String(bytes));
}
/**
* Loads RSA/DSA private key in a PEM format into {@link KeyPair}.
*/
public static KeyPair loadKey(String pemString) throws IOException, GeneralSecurityException {
Object key = PEMDecoder.decode(pemString.toCharArray(), null);
if (key instanceof com.trilead.ssh2.signature.RSAPrivateKey) {
......@@ -362,6 +369,10 @@ public class CLI {
}
}
public PublicKey authenticate(KeyPair key) throws IOException, GeneralSecurityException {
return authenticate(Collections.singleton(key));
}
private static void printUsage(String msg) {
if(msg!=null) System.out.println(msg);
System.err.println(Messages.CLI_Usage());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册