Also implement UpRef() for kAllowRefCountedUniquePtr types.

Bug: 42290295
Change-Id: Icd4fd916d8bd7db5e071818ee34b69806a6a6964
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/89068
Commit-Queue: Rudolf Polzer <rpolzer@google.com>
Reviewed-by: Xiangfei Ding <xfding@google.com>
Commit-Queue: Xiangfei Ding <xfding@google.com>
diff --git a/crypto/mem_internal.h b/crypto/mem_internal.h
index 3b0ed38..088e1b4 100644
--- a/crypto/mem_internal.h
+++ b/crypto/mem_internal.h
@@ -102,6 +102,21 @@
 
 }  // namespace internal
 
+// All types with kAllowRefCountedUniquePtr types also automatically get an
+// UpRef function. Other types may be C structs which require a
+// |BORINGSSL_MAKE_UP_REF| registration.
+template <typename T, typename = std::enable_if_t<T::kAllowRefCountedUniquePtr>>
+inline UniquePtr<T> UpRef(T *v) {
+  if (v != nullptr) {
+    v->UpRefInternal();
+  }
+  return UniquePtr<T>(v);
+}
+template <typename T, typename = std::enable_if_t<T::kAllowRefCountedUniquePtr>>
+inline UniquePtr<T> UpRef(const UniquePtr<T> &ptr) {
+  return UpRef(ptr.get());
+}
+
 // MakeUnique behaves like |std::make_unique| but returns nullptr on allocation
 // error.
 template <typename T, typename... Args>