RTCCertificate serialization.
This CL adds the ability to convert RTCCertificate objects to and from
PEM string representations of it (its private key and certificate).
The RTCCertificate being a wrapper of SSLIdentity, this is where the
meat is.
Changes:
- SSLIdentity::PrivateKeyToPEMString() added. It together with the
already existing SSLCertificate::ToPEMString() yields both private
key and certificate PEM strings, both of which are required
parameters to SSLIdentity::FromPEMStrings().
- Its only implementation, OpenSSLIdentity::PrivateKeyToPemString().
- SSLIdentity::PublicKeyToPEMString() added, used by tests.
- sslidentity_unittest.cc updated:
* FromPEMStringsRSA and FromPEMStringsEC updated.
* CloneIdentityRSA and CloneIdentityECDSA added.
- RTCCertificate::To/FromPem added, using new class RTCCertificatePem.
- rtccertificate_unittest.cc: New test CloneWithPemSerialization.
- Renamed rtc_unittests.cc to rtccertificate_unittest.cc to match
convention.
BUG=webrtc:5794, chromium:581354
Review-Url: https://codereview.webrtc.org/1898383003
Cr-Commit-Position: refs/heads/master@{#12546}
diff --git a/webrtc/base/rtccertificate.cc b/webrtc/base/rtccertificate.cc
index 70959ee..574bf75 100644
--- a/webrtc/base/rtccertificate.cc
+++ b/webrtc/base/rtccertificate.cc
@@ -45,4 +45,24 @@
return identity_->certificate();
}
+RTCCertificatePEM RTCCertificate::ToPEM() const {
+ return RTCCertificatePEM(identity_->PrivateKeyToPEMString(),
+ ssl_certificate().ToPEMString());
+}
+
+scoped_refptr<RTCCertificate> RTCCertificate::FromPEM(
+ const RTCCertificatePEM& pem) {
+ std::unique_ptr<SSLIdentity> identity(SSLIdentity::FromPEMStrings(
+ pem.private_key(), pem.certificate()));
+ return new RefCountedObject<RTCCertificate>(identity.release());
+}
+
+bool RTCCertificate::operator==(const RTCCertificate& certificate) const {
+ return *this->identity_ == *certificate.identity_;
+}
+
+bool RTCCertificate::operator!=(const RTCCertificate& certificate) const {
+ return !(*this == certificate);
+}
+
} // namespace rtc