This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs-object-store.git


The following commit(s) were added to refs/heads/main by this push:
     new 83235d1  fix(gcp): don't panic if read pem fails (#421)
83235d1 is described below

commit 83235d1b174802c6b623e9de543f1e528f5e5e6d
Author: HugoCasa <[email protected]>
AuthorDate: Tue Jul 8 09:11:04 2025 +0200

    fix(gcp): don't panic if read pem fails (#421)
---
 src/gcp/credential.rs | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/gcp/credential.rs b/src/gcp/credential.rs
index bd77fed..1e067f5 100644
--- a/src/gcp/credential.rs
+++ b/src/gcp/credential.rs
@@ -89,6 +89,9 @@ pub enum Error {
 
     #[error("Error getting token response body: {}", source)]
     TokenResponseBody { source: HttpError },
+
+    #[error("Error reading pem file: {}", source)]
+    ReadPem { source: std::io::Error },
 }
 
 impl From<Error> for crate::Error {
@@ -130,11 +133,13 @@ impl ServiceAccountKey {
         let mut cursor = Cursor::new(encoded);
         let mut reader = BufReader::new(&mut cursor);
 
-        // Reading from string is infallible
-        match rustls_pemfile::read_one(&mut reader).unwrap() {
-            Some(Item::Pkcs8Key(key)) => 
Self::from_pkcs8(key.secret_pkcs8_der()),
-            Some(Item::Pkcs1Key(key)) => 
Self::from_der(key.secret_pkcs1_der()),
-            _ => Err(Error::MissingKey),
+        match rustls_pemfile::read_one(&mut reader) {
+            Ok(item) => match item {
+                Some(Item::Pkcs8Key(key)) => 
Self::from_pkcs8(key.secret_pkcs8_der()),
+                Some(Item::Pkcs1Key(key)) => 
Self::from_der(key.secret_pkcs1_der()),
+                _ => Err(Error::MissingKey),
+            },
+            Err(e) => Err(Error::ReadPem { source: e }),
         }
     }
 

Reply via email to