diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/DecryptContentPGP.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/DecryptContentPGP.java index 048d483b9c..72a510eccf 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/DecryptContentPGP.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/DecryptContentPGP.java @@ -38,7 +38,7 @@ import org.apache.nifi.processor.util.StandardValidators; import org.apache.nifi.processors.pgp.attributes.DecryptionStrategy; import org.apache.nifi.processors.pgp.exception.PGPDecryptionException; import org.apache.nifi.processors.pgp.exception.PGPProcessException; -import org.apache.nifi.processors.pgp.io.KeyIdentifierConverter; +import org.apache.nifi.pgp.service.api.KeyIdentifierConverter; import org.apache.nifi.stream.io.StreamUtils; import org.apache.nifi.util.StringUtils; diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/SignContentPGP.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/SignContentPGP.java index 87726fa7d2..e965edb45e 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/SignContentPGP.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/SignContentPGP.java @@ -39,7 +39,7 @@ import org.apache.nifi.processors.pgp.attributes.HashAlgorithm; import org.apache.nifi.processors.pgp.attributes.SigningStrategy; import org.apache.nifi.processors.pgp.exception.PGPProcessException; import org.apache.nifi.processors.pgp.io.EncodingStreamCallback; -import org.apache.nifi.processors.pgp.io.KeyIdentifierConverter; +import org.apache.nifi.pgp.service.api.KeyIdentifierConverter; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPLiteralDataGenerator; import org.bouncycastle.openpgp.PGPOnePassSignature; diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/VerifyContentPGP.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/VerifyContentPGP.java index 115ffddab3..d932d3fc20 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/VerifyContentPGP.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/VerifyContentPGP.java @@ -31,7 +31,7 @@ import org.apache.nifi.processor.ProcessSession; import org.apache.nifi.processor.Relationship; import org.apache.nifi.processor.io.StreamCallback; import org.apache.nifi.processors.pgp.exception.PGPProcessException; -import org.apache.nifi.processors.pgp.io.KeyIdentifierConverter; +import org.apache.nifi.pgp.service.api.KeyIdentifierConverter; import org.apache.nifi.stream.io.StreamUtils; import org.bouncycastle.openpgp.PGPCompressedData; import org.bouncycastle.openpgp.PGPException; diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/EncryptContentPGPTest.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/EncryptContentPGPTest.java index 34a845f013..acfd413184 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/EncryptContentPGPTest.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/EncryptContentPGPTest.java @@ -21,7 +21,7 @@ import org.apache.nifi.pgp.util.PGPOperationUtils; import org.apache.nifi.processors.pgp.attributes.DecryptionStrategy; import org.apache.nifi.processors.pgp.attributes.FileEncoding; import org.apache.nifi.processors.pgp.attributes.SymmetricKeyAlgorithm; -import org.apache.nifi.processors.pgp.io.KeyIdentifierConverter; +import org.apache.nifi.pgp.service.api.KeyIdentifierConverter; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.stream.io.StreamUtils; import org.apache.nifi.util.MockFlowFile; diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/SignContentPGPTest.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/SignContentPGPTest.java index 81cff89c01..0baada4a89 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/SignContentPGPTest.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/SignContentPGPTest.java @@ -21,7 +21,7 @@ import org.apache.nifi.pgp.util.PGPSecretKeyGenerator; import org.apache.nifi.processors.pgp.attributes.FileEncoding; import org.apache.nifi.processors.pgp.attributes.HashAlgorithm; import org.apache.nifi.processors.pgp.attributes.SigningStrategy; -import org.apache.nifi.processors.pgp.io.KeyIdentifierConverter; +import org.apache.nifi.pgp.service.api.KeyIdentifierConverter; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.util.LogMessage; import org.apache.nifi.util.MockFlowFile; diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/VerifyContentPGPTest.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/VerifyContentPGPTest.java index 33e74c347e..a5b5e54af5 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/VerifyContentPGPTest.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/VerifyContentPGPTest.java @@ -20,7 +20,7 @@ import org.apache.nifi.pgp.service.api.PGPPublicKeyService; import org.apache.nifi.pgp.util.PGPFileUtils; import org.apache.nifi.pgp.util.PGPSecretKeyGenerator; import org.apache.nifi.pgp.util.PGPOperationUtils; -import org.apache.nifi.processors.pgp.io.KeyIdentifierConverter; +import org.apache.nifi.pgp.service.api.KeyIdentifierConverter; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.util.LogMessage; import org.apache.nifi.util.MockFlowFile; diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/io/KeyIdentifierConverter.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service-api/src/main/java/org/apache/nifi/pgp/service/api/KeyIdentifierConverter.java similarity index 91% rename from nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/io/KeyIdentifierConverter.java rename to nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service-api/src/main/java/org/apache/nifi/pgp/service/api/KeyIdentifierConverter.java index 25e5d916f9..abee47e1b5 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/io/KeyIdentifierConverter.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service-api/src/main/java/org/apache/nifi/pgp/service/api/KeyIdentifierConverter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.nifi.processors.pgp.io; +package org.apache.nifi.pgp.service.api; import java.math.BigInteger; @@ -24,6 +24,8 @@ import java.math.BigInteger; public class KeyIdentifierConverter { private static final int HEXADECIMAL_RADIX = 16; + private static final String KEY_ID_FORMAT = "%016X"; + /** * Format numeric key identifier as uppercase hexadecimal string * @@ -31,7 +33,7 @@ public class KeyIdentifierConverter { * @return Uppercase hexadecimal string */ public static String format(final long keyId) { - return Long.toHexString(keyId).toUpperCase(); + return String.format(KEY_ID_FORMAT, keyId); } /** diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/io/KeyIdentifierConverterTest.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service-api/src/test/java/org/apache/nifi/pgp/service/api/KeyIdentifierConverterTest.java similarity index 97% rename from nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/io/KeyIdentifierConverterTest.java rename to nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service-api/src/test/java/org/apache/nifi/pgp/service/api/KeyIdentifierConverterTest.java index 7c047b31f9..76b76811a0 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/io/KeyIdentifierConverterTest.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service-api/src/test/java/org/apache/nifi/pgp/service/api/KeyIdentifierConverterTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.nifi.processors.pgp.io; +package org.apache.nifi.pgp.service.api; import org.junit.jupiter.api.Test; diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/main/java/org/apache/nifi/pgp/service/standard/StandardPGPPrivateKeyService.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/main/java/org/apache/nifi/pgp/service/standard/StandardPGPPrivateKeyService.java index d43bfa8a7a..c1251e5e09 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/main/java/org/apache/nifi/pgp/service/standard/StandardPGPPrivateKeyService.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/main/java/org/apache/nifi/pgp/service/standard/StandardPGPPrivateKeyService.java @@ -27,6 +27,7 @@ import org.apache.nifi.context.PropertyContext; import org.apache.nifi.controller.AbstractControllerService; import org.apache.nifi.controller.ConfigurationContext; import org.apache.nifi.expression.ExpressionLanguageScope; +import org.apache.nifi.pgp.service.api.KeyIdentifierConverter; import org.apache.nifi.pgp.service.api.PGPPrivateKeyService; import org.apache.nifi.pgp.service.standard.exception.PGPConfigurationException; import org.apache.nifi.processor.util.StandardValidators; @@ -142,7 +143,7 @@ public class StandardPGPPrivateKeyService extends AbstractControllerService impl */ @Override public Optional findPrivateKey(final long keyIdentifier) { - getLogger().debug("Find Private Key [{}]", Long.toHexString(keyIdentifier).toUpperCase()); + getLogger().debug("Find Private Key [{}]", KeyIdentifierConverter.format(keyIdentifier)); return Optional.ofNullable(privateKeys.get(keyIdentifier)); } @@ -256,7 +257,7 @@ public class StandardPGPPrivateKeyService extends AbstractControllerService impl for (final PGPSecretKeyRing keyRing : keyRings) { for (final PGPSecretKey secretKey : keyRing) { final long keyId = secretKey.getKeyID(); - final String keyIdentifier = Long.toHexString(keyId).toUpperCase(); + final String keyIdentifier = KeyIdentifierConverter.format(keyId); try { final PGPPrivateKey privateKey = secretKey.extractPrivateKey(keyDecryptor); extractedPrivateKeys.add(privateKey); diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/main/java/org/apache/nifi/pgp/service/standard/StandardPGPPublicKeyService.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/main/java/org/apache/nifi/pgp/service/standard/StandardPGPPublicKeyService.java index 880ff222b1..0aac1c2b14 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/main/java/org/apache/nifi/pgp/service/standard/StandardPGPPublicKeyService.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/main/java/org/apache/nifi/pgp/service/standard/StandardPGPPublicKeyService.java @@ -27,6 +27,7 @@ import org.apache.nifi.context.PropertyContext; import org.apache.nifi.controller.AbstractControllerService; import org.apache.nifi.controller.ConfigurationContext; import org.apache.nifi.expression.ExpressionLanguageScope; +import org.apache.nifi.pgp.service.api.KeyIdentifierConverter; import org.apache.nifi.pgp.service.api.PGPPublicKeyService; import org.apache.nifi.pgp.service.standard.exception.PGPConfigurationException; import org.apache.nifi.processor.util.StandardValidators; @@ -186,7 +187,7 @@ public class StandardPGPPublicKeyService extends AbstractControllerService imple private boolean isPublicKeyMatched(final PGPPublicKey publicKey, final String search) { boolean matched = false; - final String keyId = Long.toHexString(publicKey.getKeyID()).toUpperCase(); + final String keyId = KeyIdentifierConverter.format(publicKey.getKeyID()); if (keyId.equals(search)) { matched = true; } else { diff --git a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/test/java/org/apche/nifi/pgp/service/standard/StandardPGPPublicKeyServiceTest.java b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/test/java/org/apche/nifi/pgp/service/standard/StandardPGPPublicKeyServiceTest.java index a0a6f76b74..10268f0c54 100644 --- a/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/test/java/org/apche/nifi/pgp/service/standard/StandardPGPPublicKeyServiceTest.java +++ b/nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-service/src/test/java/org/apche/nifi/pgp/service/standard/StandardPGPPublicKeyServiceTest.java @@ -16,6 +16,7 @@ */ package org.apche.nifi.pgp.service.standard; +import org.apache.nifi.pgp.service.api.KeyIdentifierConverter; import org.apache.nifi.pgp.service.standard.StandardPGPPublicKeyService; import org.apache.nifi.pgp.util.PGPFileUtils; import org.apache.nifi.pgp.util.PGPSecretKeyGenerator; @@ -129,7 +130,7 @@ public class StandardPGPPublicKeyServiceTest { private void assertPublicKeyFound(final PGPSecretKey secretKey) { final long keyIdentifier = secretKey.getKeyID(); - final String publicKeySearch = Long.toHexString(keyIdentifier).toUpperCase(); + final String publicKeySearch = KeyIdentifierConverter.format(keyIdentifier); final Optional optionalPublicKey = service.findPublicKey(publicKeySearch); assertTrue(optionalPublicKey.isPresent()); final PGPPublicKey publicKey = optionalPublicKey.get();