rust: bssl-tls: make DER encoding use slice sanitation

Signed-off-by: Xiangfei Ding <xfding@google.com>
Change-Id: I4975ac67e8751a17c68655d08192f9526a6a6964
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/97287
Presubmit-BoringSSL-Verified: boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com <boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Rudolf Polzer <rpolzer@google.com>
diff --git a/rust/bssl-tls/src/credentials.rs b/rust/bssl-tls/src/credentials.rs
index aecab4d..a67650c 100644
--- a/rust/bssl-tls/src/credentials.rs
+++ b/rust/bssl-tls/src/credentials.rs
@@ -475,12 +475,9 @@
                 bssl_sys::CRYPTO_BUFFER_len(self.ptr()),
             )
         };
-        if data.is_null() || len == 0 || len >= isize::MAX as usize {
-            return &[];
-        }
         unsafe {
             // Safety: `data` will be outlived by `self`
-            core::slice::from_raw_parts(data, len)
+            sanitize_slice(data, len).expect("buffer is too large")
         }
     }
 }