use of org.pgpainless.key.OpenPgpV4Fingerprint in project Smack by igniterealtime.
the class OpenPgpStoreTest method t06_key_keyReloadTest.
@Test
public void t06_key_keyReloadTest() throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, IOException, MissingUserIdOnKeyException {
PGPSecretKeyRing secretKeys = openPgpStoreInstance1.generateKeyRing(alice);
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(secretKeys);
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
openPgpStoreInstance1.importSecretKey(alice, secretKeys);
openPgpStoreInstance1.importPublicKey(alice, publicKeys);
assertNotNull(openPgpStoreInstance2.getSecretKeysOf(alice));
assertNotNull(openPgpStoreInstance2.getPublicKeysOf(alice));
// Clean up
openPgpStoreInstance1.deletePublicKeyRing(alice, fingerprint);
openPgpStoreInstance1.deleteSecretKeyRing(alice, fingerprint);
openPgpStoreInstance2.deletePublicKeyRing(alice, fingerprint);
openPgpStoreInstance2.deleteSecretKeyRing(alice, fingerprint);
}
use of org.pgpainless.key.OpenPgpV4Fingerprint in project Smack by igniterealtime.
the class OpenPgpStoreTest method t02_key_importKeysTest.
@Test
public void t02_key_importKeysTest() throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, MissingUserIdOnKeyException {
// Test for nullity of all possible values.
PGPSecretKeyRing secretKeys = openPgpStoreInstance1.generateKeyRing(alice);
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
assertNotNull(secretKeys);
assertNotNull(publicKeys);
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(secretKeys);
OpenPgpContact cAlice = openPgpStoreInstance1.getOpenPgpContact(alice);
assertNull(cAlice.getAnyPublicKeys());
assertEquals(fingerprint, new OpenPgpV4Fingerprint(secretKeys));
assertNull(openPgpStoreInstance1.getPublicKeysOf(alice));
assertNull(openPgpStoreInstance1.getSecretKeysOf(alice));
openPgpStoreInstance1.importPublicKey(alice, publicKeys);
assertArrayEquals(publicKeys.getEncoded(), openPgpStoreInstance1.getPublicKeysOf(alice).getEncoded());
assertNotNull(openPgpStoreInstance1.getPublicKeyRing(alice, fingerprint));
assertNull(openPgpStoreInstance1.getSecretKeysOf(alice));
cAlice = openPgpStoreInstance1.getOpenPgpContact(alice);
assertNotNull(cAlice.getAnyPublicKeys());
// Import keys a second time -> No change expected.
openPgpStoreInstance1.importPublicKey(alice, publicKeys);
assertArrayEquals(publicKeys.getEncoded(), openPgpStoreInstance1.getPublicKeysOf(alice).getEncoded());
openPgpStoreInstance1.importSecretKey(alice, secretKeys);
assertArrayEquals(secretKeys.getEncoded(), openPgpStoreInstance1.getSecretKeysOf(alice).getEncoded());
openPgpStoreInstance1.importSecretKey(alice, secretKeys);
assertNotNull(openPgpStoreInstance1.getSecretKeysOf(alice));
assertArrayEquals(secretKeys.getEncoded(), openPgpStoreInstance1.getSecretKeysOf(alice).getEncoded());
assertNotNull(openPgpStoreInstance1.getSecretKeyRing(alice, fingerprint));
assertArrayEquals(secretKeys.getEncoded(), openPgpStoreInstance1.getSecretKeyRing(alice, fingerprint).getEncoded());
assertArrayEquals(publicKeys.getEncoded(), openPgpStoreInstance1.getPublicKeyRing(alice, fingerprint).getEncoded());
// Clean up
openPgpStoreInstance1.deletePublicKeyRing(alice, fingerprint);
openPgpStoreInstance1.deleteSecretKeyRing(alice, fingerprint);
}
use of org.pgpainless.key.OpenPgpV4Fingerprint in project Smack by igniterealtime.
the class OpenPgpStoreTest method t11_key_fetchDateTest.
@Test
public void t11_key_fetchDateTest() throws IOException {
Map<OpenPgpV4Fingerprint, Date> fetchDates1 = openPgpStoreInstance1.getPublicKeyFetchDates(alice);
assertNotNull(fetchDates1);
assertTrue(fetchDates1.isEmpty());
Date date1 = new Date(85092830954L);
fetchDates1.put(finger1, date1);
openPgpStoreInstance1.setPublicKeyFetchDates(alice, fetchDates1);
Map<OpenPgpV4Fingerprint, Date> fetchDates2 = openPgpStoreInstance1.getPublicKeyFetchDates(alice);
assertNotNull(fetchDates2);
assertFalse(fetchDates2.isEmpty());
assertEquals(fetchDates1, fetchDates2);
Map<OpenPgpV4Fingerprint, Date> fetchDates3 = openPgpStoreInstance2.getPublicKeyFetchDates(alice);
assertNotNull(fetchDates3);
assertEquals(fetchDates1, fetchDates3);
openPgpStoreInstance1.setPublicKeyFetchDates(alice, null);
openPgpStoreInstance2.setPublicKeyFetchDates(alice, null);
assertNotNull(openPgpStoreInstance1.getPublicKeyFetchDates(alice));
assertTrue(openPgpStoreInstance1.getPublicKeyFetchDates(alice).isEmpty());
}
use of org.pgpainless.key.OpenPgpV4Fingerprint in project Smack by igniterealtime.
the class OpenPgpStoreTest method t10_meta_emptyStoreTest.
/*
OpenPgpMetadataStore
*/
@Test
public void t10_meta_emptyStoreTest() throws IOException {
assertNotNull(openPgpStoreInstance1.getAnnouncedFingerprintsOf(alice));
assertTrue(openPgpStoreInstance1.getAnnouncedFingerprintsOf(alice).isEmpty());
Map<OpenPgpV4Fingerprint, Date> map = new HashMap<>();
Date date1 = new Date(12354563423L);
Date date2 = new Date(8274729879812L);
map.put(finger1, date1);
map.put(finger2, date2);
openPgpStoreInstance1.setAnnouncedFingerprintsOf(alice, map);
assertFalse(openPgpStoreInstance1.getAnnouncedFingerprintsOf(alice).isEmpty());
assertEquals(map, openPgpStoreInstance1.getAnnouncedFingerprintsOf(alice));
assertTrue(openPgpStoreInstance1.getAnnouncedFingerprintsOf(bob).isEmpty());
assertFalse(openPgpStoreInstance2.getAnnouncedFingerprintsOf(alice).isEmpty());
assertEquals(map, openPgpStoreInstance2.getAnnouncedFingerprintsOf(alice));
openPgpStoreInstance1.setAnnouncedFingerprintsOf(alice, Collections.emptyMap());
openPgpStoreInstance2.setAnnouncedFingerprintsOf(alice, Collections.emptyMap());
}
use of org.pgpainless.key.OpenPgpV4Fingerprint in project Smack by igniterealtime.
the class OpenPgpStoreTest method t00_deleteTest.
/*
OpenPgpKeyStore
*/
@Test
public void t00_deleteTest() throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, MissingUserIdOnKeyException {
assertNull(openPgpStoreInstance1.getSecretKeysOf(alice));
assertNull(openPgpStoreInstance1.getPublicKeysOf(alice));
PGPSecretKeyRing keys = openPgpStoreInstance1.generateKeyRing(alice);
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(keys);
openPgpStoreInstance1.importSecretKey(alice, keys);
openPgpStoreInstance1.importPublicKey(alice, KeyRingUtils.publicKeyRingFrom(keys));
assertNotNull(openPgpStoreInstance1.getSecretKeysOf(alice));
assertNotNull(openPgpStoreInstance1.getPublicKeysOf(alice));
openPgpStoreInstance1.deleteSecretKeyRing(alice, fingerprint);
openPgpStoreInstance1.deletePublicKeyRing(alice, fingerprint);
assertNull(openPgpStoreInstance1.getPublicKeysOf(alice));
assertNull(openPgpStoreInstance1.getSecretKeysOf(alice));
}
Aggregations