[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/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)
+ }
+ }
+}