Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_:hammer_and_wrench: Refactor suggestion_ #190

Open
smuu opened this issue Dec 29, 2024 · 0 comments
Open

_:hammer_and_wrench: Refactor suggestion_ #190

smuu opened this issue Dec 29, 2024 · 0 comments

Comments

@smuu
Copy link
Contributor

smuu commented Dec 29, 2024

          _:hammer_and_wrench: Refactor suggestion_

Consider implementing proper error handling instead of using expect.

The current implementation uses expect which could cause panic in a library context. Consider propagating errors instead:

-    pub fn register_service_with_random_keys(
-        &mut self,
-        algorithm: KeyAlgorithm,
-        id: &str,
-    ) -> UncommittedTransaction {
-        let random_service_challenge_key = SigningKey::new_with_algorithm(algorithm).expect("Failed to create challenge key");
-        let random_service_signing_key = SigningKey::new_with_algorithm(algorithm).expect("Failed to create signing key");
+    pub fn register_service_with_random_keys(
+        &mut self,
+        algorithm: KeyAlgorithm,
+        id: &str,
+    ) -> Result<UncommittedTransaction, Box<dyn std::error::Error>> {
+        let random_service_challenge_key = SigningKey::new_with_algorithm(algorithm)
+            .map_err(|e| format!("Failed to create challenge key: {}", e))?;
+        let random_service_signing_key = SigningKey::new_with_algorithm(algorithm)
+            .map_err(|e| format!("Failed to create signing key: {}", e))?;
+        Ok(self.register_service(id, random_service_challenge_key, random_service_signing_key))

Committable suggestion skipped: line range outside the PR's diff.

Originally posted by @coderabbitai[bot] in #186 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant