[refactoring][bssl] Move check_int_result to util module

To facilitate its reuse in other modules such as hkdf and aead
later.

Test: atest libbssl_avf_nostd.test
Bug: 302286887
Change-Id: I5373047dcd6c264eee872d46c616cd1c2b475192
diff --git a/libs/bssl/Android.bp b/libs/bssl/Android.bp
index 9b464c6..949c2c4 100644
--- a/libs/bssl/Android.bp
+++ b/libs/bssl/Android.bp
@@ -24,6 +24,7 @@
         "libbssl_avf_error_nostd",
         "libbssl_ffi_nostd",
         "libcoset_nostd",
+        "liblog_rust_nostd",
         "libzeroize_nostd",
     ],
 }
diff --git a/libs/bssl/error/src/lib.rs b/libs/bssl/error/src/lib.rs
index 24e5a56..1f9751f 100644
--- a/libs/bssl/error/src/lib.rs
+++ b/libs/bssl/error/src/lib.rs
@@ -27,6 +27,9 @@
 pub enum Error {
     /// Failed to invoke a BoringSSL API.
     CallFailed(ApiName),
+
+    /// An unexpected internal error occurred.
+    InternalError,
 }
 
 impl fmt::Display for Error {
@@ -35,6 +38,7 @@
             Self::CallFailed(api_name) => {
                 write!(f, "Failed to invoke the BoringSSL API: {api_name:?}")
             }
+            Self::InternalError => write!(f, "An unexpected internal error occurred"),
         }
     }
 }
diff --git a/libs/bssl/src/ec_key.rs b/libs/bssl/src/ec_key.rs
index fdd6f61..901212f 100644
--- a/libs/bssl/src/ec_key.rs
+++ b/libs/bssl/src/ec_key.rs
@@ -16,6 +16,7 @@
 //! BoringSSL.
 
 use crate::cbb::CbbFixed;
+use crate::util::check_int_result;
 use alloc::vec::Vec;
 use bssl_avf_error::{ApiName, Error, Result};
 use bssl_ffi::{
@@ -199,13 +200,4 @@
     }
 }
 
-fn check_int_result(ret: i32, api_name: ApiName) -> Result<()> {
-    if ret == 1 {
-        Ok(())
-    } else {
-        assert_eq!(ret, 0, "Unexpected return value {ret} for {api_name:?}");
-        Err(Error::CallFailed(api_name))
-    }
-}
-
 // TODO(b/301068421): Unit tests the EcKey.
diff --git a/libs/bssl/src/lib.rs b/libs/bssl/src/lib.rs
index 500419b..1824080 100644
--- a/libs/bssl/src/lib.rs
+++ b/libs/bssl/src/lib.rs
@@ -22,6 +22,7 @@
 mod digest;
 mod ec_key;
 mod hmac;
+mod util;
 
 pub use bssl_avf_error::{ApiName, Error, Result};
 pub use cbb::CbbFixed;
diff --git a/libs/bssl/src/util.rs b/libs/bssl/src/util.rs
new file mode 100644
index 0000000..cb5e368
--- /dev/null
+++ b/libs/bssl/src/util.rs
@@ -0,0 +1,32 @@
+// Copyright 2023, The Android Open Source Project
+//
+// Licensed 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
+//
+//     http://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.
+
+//! Utility functions.
+
+use bssl_avf_error::{ApiName, Error, Result};
+use log::error;
+
+pub(crate) fn check_int_result(ret: i32, api_name: ApiName) -> Result<()> {
+    match ret {
+        1 => Ok(()),
+        0 => Err(Error::CallFailed(api_name)),
+        _ => {
+            error!(
+                "Received a return value ({}) other than 0 or 1 from the BoringSSL API: {:?}",
+                ret, api_name
+            );
+            Err(Error::InternalError)
+        }
+    }
+}