1 /*
2 * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch> and others
3 *
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.
7 *
8 * SPDX-License-Identifier: BSD-3-Clause
9 */
10 package org.eclipse.jgit.transport.sshd;
11
12 import java.nio.file.Path;
13 import java.security.KeyPair;
14 import java.util.function.Function;
15
16 /**
17 * A cache for {@link KeyPair}s.
18 *
19 * @since 5.2
20 */
21 public interface KeyCache {
22
23 /**
24 * Obtains a {@link KeyPair} from the cache. Implementations must be
25 * thread-safe.
26 *
27 * @param path
28 * of the key
29 * @param loader
30 * to load the key if it isn't present in the cache yet
31 * @return the {@link KeyPair}, or {@code null} if not present and could not
32 * be loaded
33 */
34 KeyPair get(Path path, Function<? super Path, ? extends KeyPair> loader);
35
36 /**
37 * Removes all {@link KeyPair} from this cache and destroys their private
38 * keys. This cache instance must not be used anymore thereafter.
39 */
40 void close();
41 }