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:
jbroman 2016-10-20 10:27:21 -07:00 committed by Commit bot
parent 58000a0c3d
commit b9eaeba71f
3 changed files with 9 additions and 0 deletions

View File

@ -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());
}

View File

@ -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;

View File

@ -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