mirror of
https://codeberg.org/PGPainless/cert-d-java.git
synced 2024-12-22 13:47:59 +01:00
Add SubkeyLookupFactory class
This commit is contained in:
parent
a3162f0cf9
commit
991fea2503
3 changed files with 65 additions and 0 deletions
|
@ -0,0 +1,33 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.cert_d.jdbc.sqlite;
|
||||
|
||||
import pgp.cert_d.subkey_lookup.SubkeyLookup;
|
||||
import pgp.cert_d.subkey_lookup.SubkeyLookupFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Implementation of {@link SubkeyLookupFactory} which creates a SQLite-based {@link DatabaseSubkeyLookup}.
|
||||
*/
|
||||
public class DatabaseSubkeyLookupFactory implements SubkeyLookupFactory {
|
||||
|
||||
@Override
|
||||
public SubkeyLookup createFileBasedInstance(File baseDirectory) {
|
||||
File databaseFile = new File(baseDirectory, "_pgpainless_subkey_map.db");
|
||||
SubkeyLookupDao dao;
|
||||
try {
|
||||
if (!databaseFile.exists()) {
|
||||
databaseFile.createNewFile();
|
||||
}
|
||||
dao = SqliteSubkeyLookupDaoImpl.forDatabaseFile(databaseFile);
|
||||
} catch (SQLException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return new DatabaseSubkeyLookup(dao);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.cert_d.subkey_lookup;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class InMemorySubkeyLookupFactory implements SubkeyLookupFactory {
|
||||
@Override
|
||||
public SubkeyLookup createFileBasedInstance(File baseDirectory) {
|
||||
return new InMemorySubkeyLookup();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.cert_d.subkey_lookup;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface SubkeyLookupFactory {
|
||||
|
||||
/**
|
||||
* Create a new {@link SubkeyLookup} instance that lives in the given baseDirectory.
|
||||
*
|
||||
* @param baseDirectory base directory
|
||||
* @return subkey lookup
|
||||
*/
|
||||
SubkeyLookup createFileBasedInstance(File baseDirectory);
|
||||
}
|
Loading…
Reference in a new issue