1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-14 04:39:39 +02:00

Add toUri/fromUri methods to OpenPgpV4Fingerprint

This commit is contained in:
Paul Schaub 2020-07-10 18:17:29 +02:00
parent 6c449b86af
commit 46af22cc50
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 38 additions and 0 deletions

View file

@ -19,6 +19,8 @@ import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertNotEquals;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.junit.Test;
@ -74,4 +76,21 @@ public class OpenPgpV4FingerprintTest {
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(key);
assertEquals(keyId, fingerprint.getKeyId());
}
@Test
public void testToUri() {
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint("5448452043414B452049532041204C4945212121");
URI uri = fingerprint.toUri();
assertEquals("openpgp4fpr:5448452043414B452049532041204C4945212121", uri.toString());
OpenPgpV4Fingerprint parsed = OpenPgpV4Fingerprint.fromUri(uri);
assertEquals(fingerprint, parsed);
}
@Test(expected = IllegalArgumentException.class)
public void testFromUriThrowsIfWrongScheme() throws URISyntaxException {
URI uri = new URI(null, "5448452043414B452049532041204C4945212121", null);
OpenPgpV4Fingerprint.fromUri(uri);
}
}