1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-18 18:21:08 +01:00

Some testing and SubkeyLookup mechanism

This commit is contained in:
Paul Schaub 2022-02-07 10:31:36 +01:00
parent 53e8c03b8a
commit 2e6a1dcbc5
13 changed files with 226 additions and 49 deletions

View file

@ -5,6 +5,7 @@
package pgp.cert_d;
import java.io.File;
import java.nio.file.Paths;
public class BaseDirectoryProvider {
@ -18,29 +19,28 @@ public class BaseDirectoryProvider {
// return OS-specific default dir
String osName = System.getProperty("os.name", "generic")
.toLowerCase();
return getDefaultBaseDirForOS(osName, File.separator);
return getDefaultBaseDirForOS(osName);
}
public static File getDefaultBaseDirForOS(String osName, String separator) {
public static File getDefaultBaseDirForOS(String osName) {
String STORE_NAME = "pgp.cert.d";
if (osName.contains("win")) {
String appData = System.getenv("APPDATA");
String roaming = appData + separator + "Roaming";
return new File(roaming, STORE_NAME);
// %APPDATA%\Roaming\pgp.cert.d
return Paths.get(System.getenv("APPDATA"), "Roaming", STORE_NAME).toFile();
}
if (osName.contains("nux")) {
// $XDG_DATA_HOME/pgp.cert.d
String xdg_data_home = System.getenv("XDG_DATA_HOME");
String rootPath = xdg_data_home;
if (xdg_data_home == null) {
rootPath = System.getProperty("user.home") + separator + ".local" + separator + "share";
if (xdg_data_home != null) {
return Paths.get(xdg_data_home, STORE_NAME).toFile();
}
return new File(rootPath, STORE_NAME);
// $HOME/.local/share/pgp.cert.d
return Paths.get(System.getProperty("user.home"), ".local", "share", STORE_NAME).toFile();
}
if (osName.contains("mac")) {
String home = System.getenv("HOME");
return new File(home + separator + "Library" + separator + "Application Support", STORE_NAME);
return Paths.get(System.getenv("HOME"), "Library", "Application Support", STORE_NAME).toFile();
}
throw new IllegalArgumentException("Unknown OS " + osName);

View file

@ -75,6 +75,11 @@ public class CachingSharedPGPCertificateDirectoryWrapper
tagMap.clear();
}
@Override
public LockingMechanism getLock() {
return underlyingCertificateDirectory.getLock();
}
@Override
public Certificate getByFingerprint(String fingerprint)
throws IOException, BadNameException, BadDataException {

View file

@ -0,0 +1,23 @@
package pgp.cert_d;
import java.util.HashMap;
import java.util.Map;
public class InMemorySubkeyLookup implements SubkeyLookup {
private static final Map<Long, String> subkeyMap = new HashMap<>();
@Override
public String getIdentifierForSubkeyId(long subkeyId) {
return subkeyMap.get(subkeyId);
}
@Override
public void storeIdentifierForSubkeyId(long subkeyId, String identifier) {
subkeyMap.put(subkeyId, identifier);
}
public void clear() {
subkeyMap.clear();
}
}

View file

@ -15,6 +15,8 @@ import pgp.certificate_store.MergeCallback;
public interface SharedPGPCertificateDirectory {
LockingMechanism getLock();
Certificate getByFingerprint(String fingerprint)
throws IOException, BadNameException, BadDataException;

View file

@ -69,6 +69,11 @@ public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDi
}
}
@Override
public LockingMechanism getLock() {
return writeLock;
}
@Override
public Certificate getByFingerprint(String fingerprint)
throws IOException, BadNameException, BadDataException {

View file

@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package pgp.cert_d;
public interface SubkeyLookup {
/**
* Lookup the identifier of the certificate that contains the given subkey.
* If no record is found, return null.
*
* @param subkeyId subkey id
* @return identifier (fingerprint or special name) of the certificate
*/
String getIdentifierForSubkeyId(long subkeyId);
/**
* Store a record of the subkey id that points to the identifier.
*
* @param subkeyId subkey id
* @param identifier fingerprint or special name of the certificate
*/
void storeIdentifierForSubkeyId(long subkeyId, String identifier);
}

View file

@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package pgp.cert_d;
public class SubkeyLookupImpl implements SubkeyLookup {
@Override
public String getIdentifierForSubkeyId(long subkeyId) {
return null;
}
@Override
public void storeIdentifierForSubkeyId(long subkeyId, String identifier) {
}
}