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

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

Issue 1920043002: Replace scoped_ptr with unique_ptr in webrtc/base/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 4 years, 7 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/criticalsection_unittest.cc ('k') | webrtc/base/dbus_unittest.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 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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_CRYPTSTRING_H_ 11 #ifndef _WEBRTC_BASE_CRYPTSTRING_H_
12 #define _WEBRTC_BASE_CRYPTSTRING_H_ 12 #define _WEBRTC_BASE_CRYPTSTRING_H_
13 13
14 #include <string.h> 14 #include <string.h>
15 15
16 #include <memory>
16 #include <string> 17 #include <string>
17 #include <vector> 18 #include <vector>
18 19
19 #include "webrtc/base/linked_ptr.h" 20 #include "webrtc/base/linked_ptr.h"
20 #include "webrtc/base/scoped_ptr.h"
21 21
22 namespace rtc { 22 namespace rtc {
23 23
24 class CryptStringImpl { 24 class CryptStringImpl {
25 public: 25 public:
26 virtual ~CryptStringImpl() {} 26 virtual ~CryptStringImpl() {}
27 virtual size_t GetLength() const = 0; 27 virtual size_t GetLength() const = 0;
28 virtual void CopyTo(char * dest, bool nullterminate) const = 0; 28 virtual void CopyTo(char * dest, bool nullterminate) const = 0;
29 virtual std::string UrlEncode() const = 0; 29 virtual std::string UrlEncode() const = 0;
30 virtual CryptStringImpl * Copy() const = 0; 30 virtual CryptStringImpl * Copy() const = 0;
31 virtual void CopyRawTo(std::vector<unsigned char> * dest) const = 0; 31 virtual void CopyRawTo(std::vector<unsigned char> * dest) const = 0;
32 }; 32 };
33 33
34 class EmptyCryptStringImpl : public CryptStringImpl { 34 class EmptyCryptStringImpl : public CryptStringImpl {
35 public: 35 public:
36 ~EmptyCryptStringImpl() override {} 36 ~EmptyCryptStringImpl() override {}
37 size_t GetLength() const override; 37 size_t GetLength() const override;
38 void CopyTo(char* dest, bool nullterminate) const override; 38 void CopyTo(char* dest, bool nullterminate) const override;
39 std::string UrlEncode() const override; 39 std::string UrlEncode() const override;
40 CryptStringImpl* Copy() const override; 40 CryptStringImpl* Copy() const override;
41 void CopyRawTo(std::vector<unsigned char>* dest) const override; 41 void CopyRawTo(std::vector<unsigned char>* dest) const override;
42 }; 42 };
43 43
44 class CryptString { 44 class CryptString {
45 public: 45 public:
46 CryptString(); 46 CryptString();
47 size_t GetLength() const { return impl_->GetLength(); } 47 size_t GetLength() const { return impl_->GetLength(); }
48 void CopyTo(char * dest, bool nullterminate) const { impl_->CopyTo(dest, nullt erminate); } 48 void CopyTo(char * dest, bool nullterminate) const { impl_->CopyTo(dest, nullt erminate); }
49 CryptString(const CryptString& other); 49 CryptString(const CryptString& other);
50 explicit CryptString(const CryptStringImpl& impl); 50 explicit CryptString(const CryptStringImpl& impl);
51 ~CryptString(); 51 ~CryptString();
52 CryptString & operator=(const CryptString & other) { 52 CryptString & operator=(const CryptString & other) {
53 if (this != &other) { 53 if (this != &other) {
54 impl_.reset(other.impl_->Copy()); 54 impl_.reset(other.impl_->Copy());
55 } 55 }
56 return *this; 56 return *this;
57 } 57 }
58 void Clear() { impl_.reset(new EmptyCryptStringImpl()); } 58 void Clear() { impl_.reset(new EmptyCryptStringImpl()); }
59 std::string UrlEncode() const { return impl_->UrlEncode(); } 59 std::string UrlEncode() const { return impl_->UrlEncode(); }
60 void CopyRawTo(std::vector<unsigned char> * dest) const { 60 void CopyRawTo(std::vector<unsigned char> * dest) const {
61 return impl_->CopyRawTo(dest); 61 return impl_->CopyRawTo(dest);
62 } 62 }
63 63
64 private: 64 private:
65 scoped_ptr<const CryptStringImpl> impl_; 65 std::unique_ptr<const CryptStringImpl> impl_;
66 }; 66 };
67 67
68 68
69 // Used for constructing strings where a password is involved and we 69 // Used for constructing strings where a password is involved and we
70 // need to ensure that we zero memory afterwards 70 // need to ensure that we zero memory afterwards
71 class FormatCryptString { 71 class FormatCryptString {
72 public: 72 public:
73 FormatCryptString() { 73 FormatCryptString() {
74 storage_ = new char[32]; 74 storage_ = new char[32];
75 capacity_ = 32; 75 capacity_ = 32;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 CryptStringImpl* Copy() const override; 160 CryptStringImpl* Copy() const override;
161 void CopyRawTo(std::vector<unsigned char>* dest) const override; 161 void CopyRawTo(std::vector<unsigned char>* dest) const override;
162 162
163 private: 163 private:
164 std::string password_; 164 std::string password_;
165 }; 165 };
166 166
167 } 167 }
168 168
169 #endif // _WEBRTC_BASE_CRYPTSTRING_H_ 169 #endif // _WEBRTC_BASE_CRYPTSTRING_H_
OLDNEW
« no previous file with comments | « webrtc/base/criticalsection_unittest.cc ('k') | webrtc/base/dbus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698