mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-10 14:21:09 +01:00
Add OpenPgpFingerprint.parse(String)
This commit is contained in:
parent
8f473b513f
commit
6b9b956c2c
3 changed files with 39 additions and 0 deletions
|
|
@ -50,6 +50,23 @@ public abstract class OpenPgpFingerprint implements CharSequence, Comparable<Ope
|
|||
return of(ring.getPublicKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to parse an {@link OpenPgpFingerprint} from the given fingerprint string.
|
||||
*
|
||||
* @param fingerprint fingerprint
|
||||
* @return parsed fingerprint
|
||||
*/
|
||||
public static OpenPgpFingerprint parse(String fingerprint) {
|
||||
String fp = fingerprint.replace(" ", "").trim().toUpperCase();
|
||||
if (fp.matches("^[0-9A-F]{40}$")) {
|
||||
return new OpenPgpV4Fingerprint(fp);
|
||||
}
|
||||
if (fp.matches("^[0-9A-F]{64}$")) {
|
||||
return new OpenPgpV5Fingerprint(fp);
|
||||
}
|
||||
throw new IllegalArgumentException("Fingerprint does not appear to match any known fingerprint patterns.");
|
||||
}
|
||||
|
||||
public OpenPgpFingerprint(String fingerprint) {
|
||||
String fp = fingerprint.replace(" ", "").trim().toUpperCase();
|
||||
if (!isValid(fp)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue