public void withPublicKey(String username, InputStream privateKey, String passphrase) throws HgAuthFailedException {
if (username == null) {
// FIXME AuthFailure and AuthFailed or similar distinct exceptions to tell true authentication issues from
// failures around it.
throw new HgAuthFailedException("Need username", null);
}
if (privateKey == null) {
throw new HgAuthFailedException("Need private key", null);
}
CharArrayWriter a = new CharArrayWriter(2048);
int r;
try {
while((r = privateKey.read()) != -1) {
a.append((char) r);
}
} catch (IOException ex) {
throw new HgAuthFailedException("Failed to read private key", ex);
}
try {
boolean success = conn.authenticateWithPublicKey(username, a.toCharArray(), passphrase);
if (!success) {
throw authFailed(username);