Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/76#discussion_r37697905
  
    --- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/OpenPGPKeyBasedEncryptor.java
 ---
    @@ -85,49 +85,61 @@ public StreamCallback getDecryptionCallback() throws 
Exception {
         /*
          * Validate secret keyring passphrase
          */
    -    public static boolean validateKeyring(String provider, String 
secretKeyringFile, char[] passphrase) throws IOException,
    +    public static boolean validateKeyring(String provider,
    +            String secretKeyringFile, char[] passphrase) throws 
IOException,
                 PGPException, NoSuchProviderException {
    -        PGPSecretKeyRingCollection pgpsec = new 
PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(Files.newInputStream(Paths
    -                .get(secretKeyringFile))));
    -        Iterator ringit = pgpsec.getKeyRings();
    -        while (ringit.hasNext()) {
    -            PGPSecretKeyRing secretkeyring = (PGPSecretKeyRing) 
ringit.next();
    -            PGPSecretKey secretkey = secretkeyring.getSecretKey();
    -            secretkey.extractPrivateKey(passphrase, provider);
    -            return true;
    +        try (InputStream fin = Files.newInputStream(Paths
    +                .get(secretKeyringFile))) {
    +            try (InputStream pin = PGPUtil.getDecoderStream(fin)) {
    +                PGPSecretKeyRingCollection pgpsec = new 
PGPSecretKeyRingCollection(
    +                        pin);
    +                Iterator ringit = pgpsec.getKeyRings();
    +                while (ringit.hasNext()) {
    +                    PGPSecretKeyRing secretkeyring = (PGPSecretKeyRing) 
ringit
    +                            .next();
    +                    PGPSecretKey secretkey = secretkeyring.getSecretKey();
    +                    secretkey.extractPrivateKey(passphrase, provider);
    +                    return true;
    +                }
    +                return false;
    +            }
             }
    -        return false;
         }
     
         /*
          * Get the public key for a specific user id from a keyring.
          */
         @SuppressWarnings("rawtypes")
    -    public static PGPPublicKey getPublicKey(String userId, String 
publicKeyring) throws IOException, PGPException {
    +    public static PGPPublicKey getPublicKey(String userId, String 
publicKeyring)
    +            throws IOException, PGPException {
             PGPPublicKey pubkey = null;
    -        PGPPublicKeyRingCollection pgppub = new
    -                
PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(Files.newInputStream(Paths.get(publicKeyring))));
    -
    -        Iterator ringit = pgppub.getKeyRings();
    -        while (ringit.hasNext()) {
    -            PGPPublicKeyRing kring = (PGPPublicKeyRing) ringit.next();
    -
    -            Iterator keyit = kring.getPublicKeys();
    -            while (keyit.hasNext()) {
    -                pubkey = (PGPPublicKey) keyit.next();
    -                boolean userIdMatch = false;
    -
    -                Iterator userit = pubkey.getUserIDs();
    -                while (userit.hasNext()) {
    -                    String id = userit.next().toString();
    -                    if (id.contains(userId)) {
    -                        userIdMatch = true;
    -                        break;
    +        try (InputStream fin = 
Files.newInputStream(Paths.get(publicKeyring))) {
    +            try (InputStream pin = PGPUtil.getDecoderStream(fin)) {
    --- End diff --
    
    I would wrap this up with the previous try-with-resources so that we have:
    
    try (InputStream fin = Files.newInputStream(Paths.get(publicKeyring)); 
          InputStream pin = PGPUtil.getDecoderStream(fin)) { ...
    
    rather than having a new try-with-resources embedded within the outer one.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to