2 * Copyright (C) 2021, Thomas Wolf <thomas.wolf@paranor.ch> and others
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0 which is available at
6 * https://www.eclipse.org/org/documents/edl-v10.php.
8 * SPDX-License-Identifier: BSD-3-Clause
10 package org.eclipse.jgit.internal.transport.sshd.agent.connector;
12 import java.io.IOException;
14 import org.eclipse.jgit.transport.sshd.agent.AbstractConnector;
17 * A connector using Pageant's shared memory IPC mechanism.
19 public class PageantConnector extends AbstractConnector {
21 private final PageantLibrary lib;
24 * Creates a new {@link PageantConnector}.
26 public PageantConnector() {
27 super(); // Use default maximum message size
28 this.lib = new PageantLibrary();
32 public boolean connect() throws IOException {
33 return lib.isPageantAvailable();
37 public void close() throws IOException {
42 public byte[] rpc(byte command, byte[] message) throws IOException {
43 try (PageantLibrary.Pipe pipe = lib
44 .createPipe(getClass().getSimpleName(),
45 getMaximumMessageLength())) {
46 prepareMessage(command, message);
48 byte[] lengthBuf = new byte[4];
49 pipe.receive(lengthBuf);
50 int length = toLength(command, lengthBuf);
51 byte[] payload = new byte[length];
52 pipe.receive(payload);