From 15eb319b263fb4036115e11c49f03d1afe4776af Mon Sep 17 00:00:00 2001 From: David Blacka Date: Fri, 29 Mar 2024 21:58:16 -0400 Subject: [PATCH] refactor getVerifier() --- .../dnssec/security/DnsKeyPair.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/verisignlabs/dnssec/security/DnsKeyPair.java b/src/main/java/com/verisignlabs/dnssec/security/DnsKeyPair.java index eb3da10..aa083eb 100644 --- a/src/main/java/com/verisignlabs/dnssec/security/DnsKeyPair.java +++ b/src/main/java/com/verisignlabs/dnssec/security/DnsKeyPair.java @@ -264,18 +264,21 @@ public class DnsKeyPair { * @throws NoSuchAlgorithmException */ public Signature getVerifier() { - if (mVerifier == null) { - mVerifier = getSignature(); - PublicKey pk = getPublic(); - if (mVerifier != null && pk != null) { - try { - mVerifier.initVerify(pk); - } catch (InvalidKeyException e) { - } - } else { - // do not return an uninitialized verifier - return null; - } + if (mVerifier != null) return mVerifier; + + mVerifier = getSignature(); + PublicKey pk = getPublic(); + + if (mVerifier == null || pk == null) { + log.warning("Could not get a Signature object for this key pair" + this); + return null; + } + + try { + mVerifier.initVerify(pk); + } catch (InvalidKeyException e) { + log.warning("Key pair cannot initialize with public key: " + this); + return null; } return mVerifier;