[bssl] Replace ok_or with ok_or_else in bssl for lazy evaluation
Prior to the cl, the bssl library used `ok_or` in a way that
resulted in the evaluation of the argument even when no error
occurred.
This cl replaces `ok_or` with `ok_or_else` to introduce lazy
evaluation in the error case.
Test: atest rialto_test
Change-Id: Ib9c514b577f68dc6da3cb00251ac88223c7a0402
diff --git a/libs/bssl/src/evp.rs b/libs/bssl/src/evp.rs
index fca189c..719bb1d 100644
--- a/libs/bssl/src/evp.rs
+++ b/libs/bssl/src/evp.rs
@@ -54,7 +54,7 @@
fn new_pkey() -> Result<NonNull<EVP_PKEY>> {
// SAFETY: The returned pointer is checked below.
let key = unsafe { EVP_PKEY_new() };
- NonNull::new(key).ok_or(to_call_failed_error(ApiName::EVP_PKEY_new))
+ NonNull::new(key).ok_or_else(|| to_call_failed_error(ApiName::EVP_PKEY_new))
}
impl TryFrom<EcKey> for PKey {
@@ -94,7 +94,7 @@
// SAFETY: This is safe because the CBB pointer is initialized with `CBB_init_fixed()`,
// and it has been flushed, thus it has no active children.
let len = unsafe { CBB_len(cbb.as_ref()) };
- Ok(buf.get(0..len).ok_or(to_call_failed_error(ApiName::CBB_len))?.to_vec())
+ Ok(buf.get(0..len).ok_or_else(|| to_call_failed_error(ApiName::CBB_len))?.to_vec())
}
/// This function takes a raw public key data slice and creates a `PKey` instance wrapping
@@ -118,8 +118,8 @@
raw_public_key.len(),
)
};
- let pkey =
- NonNull::new(pkey).ok_or(to_call_failed_error(ApiName::EVP_PKEY_new_raw_public_key))?;
+ let pkey = NonNull::new(pkey)
+ .ok_or_else(|| to_call_failed_error(ApiName::EVP_PKEY_new_raw_public_key))?;
Ok(Self { pkey, _inner_ec_key: None })
}