Return nullptr from RTCCertificate::FromPEM on failure.
BUG=webrtc:6488 Review-Url: https://codereview.webrtc.org/2424093002 Cr-Commit-Position: refs/heads/master@{#14710}
This commit is contained in:
parent
58000a0c3d
commit
b9eaeba71f
@ -54,6 +54,8 @@ scoped_refptr<RTCCertificate> RTCCertificate::FromPEM(
|
||||
const RTCCertificatePEM& pem) {
|
||||
std::unique_ptr<SSLIdentity> identity(SSLIdentity::FromPEMStrings(
|
||||
pem.private_key(), pem.certificate()));
|
||||
if (!identity)
|
||||
return nullptr;
|
||||
return new RefCountedObject<RTCCertificate>(identity.release());
|
||||
}
|
||||
|
||||
|
||||
@ -66,6 +66,7 @@ class RTCCertificate : public RefCountInterface {
|
||||
|
||||
// To/from PEM, a text representation of the RTCCertificate.
|
||||
RTCCertificatePEM ToPEM() const;
|
||||
// Can return nullptr if the certificate is invalid.
|
||||
static scoped_refptr<RTCCertificate> FromPEM(const RTCCertificatePEM& pem);
|
||||
bool operator==(const RTCCertificate& certificate) const;
|
||||
bool operator!=(const RTCCertificate& certificate) const;
|
||||
|
||||
@ -137,4 +137,10 @@ TEST_F(RTCCertificateTest, CloneWithPEMSerialization) {
|
||||
EXPECT_EQ(orig->Expires(), clone->Expires());
|
||||
}
|
||||
|
||||
TEST_F(RTCCertificateTest, FromPEMWithInvalidPEM) {
|
||||
RTCCertificatePEM pem("not a valid PEM", "not a valid PEM");
|
||||
scoped_refptr<RTCCertificate> certificate = RTCCertificate::FromPEM(pem);
|
||||
EXPECT_FALSE(certificate);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user