martinzink commented on code in PR #2225:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2225#discussion_r4106016168


##########
minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service.rs:
##########
@@ -0,0 +1,249 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#[cfg(test)]
+use crate::controller_services::key_lookup::key_matches;
+use minifi_native::macros::ComponentIdentifier;
+use minifi_native::{EnableControllerService, GetProperty, Logger, MinifiError};
+use pgp::composed::{SignedSecretKey, TheRing};
+#[cfg(test)]
+use pgp::types::KeyDetails;
+use service_def::*;
+
+#[derive(Debug, ComponentIdentifier)]
+pub(crate) struct PGPPrivateKeyService {
+    private_keys: Vec<SignedSecretKey>,
+    passphrase: pgp::types::Password,
+}
+
+impl EnableControllerService for PGPPrivateKeyService {
+    fn enable<P: GetProperty, L: Logger>(context: &P, _logger: &L) -> 
Result<Self, MinifiError>
+    where
+        Self: Sized,
+    {
+        let mut private_keys = 
context.get_property(&KEY_FILE)?.unwrap_or_default();
+        private_keys.extend(context.get_property(&KEY)?.unwrap_or_default());
+
+        let passphrase = 
context.get_property(&KEY_PASSWORD)?.unwrap_or_default();
+
+        if private_keys.is_empty() {
+            return Err(MinifiError::validation("Could not load any valid 
keys"));
+        }
+        Ok(Self {
+            private_keys,
+            passphrase,
+        })
+    }
+}
+
+impl PGPPrivateKeyService {
+    pub fn get_the_ring(&'_ self) -> TheRing<'_> {
+        TheRing {
+            secret_keys: self.private_keys.iter().collect(),
+            key_passwords: vec![&self.passphrase],
+            message_password: vec![],
+            session_keys: vec![],
+            decrypt_options: Default::default(),
+        }
+    }
+
+    #[cfg(test)]
+    pub fn get_secret_key(&self, target_id: &str) -> Option<&SignedSecretKey> {
+        self.private_keys.iter().find(|private_key| {
+            key_matches(
+                &private_key.primary_key.legacy_key_id(),
+                &private_key.details,
+                target_id,
+            )
+        })
+    }
+}
+
+mod service_def {
+    use crate::controller_services::key_file_property::SecretKeyFile;
+    use crate::controller_services::key_property::SecretKey;
+    use crate::controller_services::private_key_service::PGPPrivateKeyService;
+    use crate::utils;
+    use minifi_native::{
+        ControllerServiceDefinition, Property, PropertyDefinition, 
ProvidedInterface,
+        property_definitions,
+    };
+
+    pub(super) const KEY_FILE: Property<Option<SecretKeyFile>> = Property::new(
+        "Key File",
+        "File path to PGP Secret Key encoded in binary or ASCII Armor",
+    )
+    .supports_expression_language();
+
+    pub(super) const KEY: Property<Option<SecretKey>> =
+        Property::new("Key", "Secret Key encoded in ASCII Armor").sensitive();

Review Comment:
   [Key -> Keyring, Key File -> Keyring 
File](https://github.com/apache/nifi-minifi-cpp/pull/2225/commits/522f3999b44a5c92763cfb3f6b86c471f0a938d1)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to