Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: webrtc/base/rtccertificate.h

Issue 2877023002: Move webrtc/{base => rtc_base} (Closed)
Patch Set: update presubmit.py and DEPS include rules Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/rollingaccumulator_unittest.cc ('k') | webrtc/base/rtccertificate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_BASE_RTCCERTIFICATE_H_ 11 #ifndef WEBRTC_BASE_RTCCERTIFICATE_H_
12 #define WEBRTC_BASE_RTCCERTIFICATE_H_ 12 #define WEBRTC_BASE_RTCCERTIFICATE_H_
13 13
14 #include <stdint.h>
15 14
16 #include <memory> 15 // This header is deprecated and is just left here temporarily during
17 16 // refactoring. See https://bugs.webrtc.org/7634 for more details.
18 #include "webrtc/base/refcount.h" 17 #include "webrtc/rtc_base/rtccertificate.h"
19 #include "webrtc/base/scoped_ref_ptr.h"
20 #include "webrtc/base/sslidentity.h"
21
22 namespace rtc {
23
24 // This class contains PEM strings of an RTCCertificate's private key and
25 // certificate and acts as a text representation of RTCCertificate. Certificates
26 // can be serialized and deserialized to and from this format, which allows for
27 // cloning and storing of certificates to disk. The PEM format is that of
28 // |SSLIdentity::PrivateKeyToPEMString| and |SSLCertificate::ToPEMString|, e.g.
29 // the string representations used by OpenSSL.
30 class RTCCertificatePEM {
31 public:
32 RTCCertificatePEM(
33 const std::string& private_key,
34 const std::string& certificate)
35 : private_key_(private_key),
36 certificate_(certificate) {}
37
38 const std::string& private_key() const { return private_key_; }
39 const std::string& certificate() const { return certificate_; }
40
41 private:
42 std::string private_key_;
43 std::string certificate_;
44 };
45
46 // A thin abstraction layer between "lower level crypto stuff" like
47 // SSLCertificate and WebRTC usage. Takes ownership of some lower level objects,
48 // reference counting protects these from premature destruction.
49 class RTCCertificate : public RefCountInterface {
50 public:
51 // Takes ownership of |identity|.
52 static scoped_refptr<RTCCertificate> Create(
53 std::unique_ptr<SSLIdentity> identity);
54
55 // Returns the expiration time in ms relative to epoch, 1970-01-01T00:00:00Z.
56 uint64_t Expires() const;
57 // Checks if the certificate has expired, where |now| is expressed in ms
58 // relative to epoch, 1970-01-01T00:00:00Z.
59 bool HasExpired(uint64_t now) const;
60 const SSLCertificate& ssl_certificate() const;
61
62 // TODO(hbos): If possible, remove once RTCCertificate and its
63 // ssl_certificate() is used in all relevant places. Should not pass around
64 // raw SSLIdentity* for the sake of accessing SSLIdentity::certificate().
65 // However, some places might need SSLIdentity* for its public/private key...
66 SSLIdentity* identity() const { return identity_.get(); }
67
68 // To/from PEM, a text representation of the RTCCertificate.
69 RTCCertificatePEM ToPEM() const;
70 // Can return nullptr if the certificate is invalid.
71 static scoped_refptr<RTCCertificate> FromPEM(const RTCCertificatePEM& pem);
72 bool operator==(const RTCCertificate& certificate) const;
73 bool operator!=(const RTCCertificate& certificate) const;
74
75 protected:
76 explicit RTCCertificate(SSLIdentity* identity);
77 ~RTCCertificate() override;
78
79 private:
80 // The SSLIdentity is the owner of the SSLCertificate. To protect our
81 // ssl_certificate() we take ownership of |identity_|.
82 std::unique_ptr<SSLIdentity> identity_;
83 };
84
85 } // namespace rtc
86 18
87 #endif // WEBRTC_BASE_RTCCERTIFICATE_H_ 19 #endif // WEBRTC_BASE_RTCCERTIFICATE_H_
OLDNEW
« no previous file with comments | « webrtc/base/rollingaccumulator_unittest.cc ('k') | webrtc/base/rtccertificate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698