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

Side by Side Diff: webrtc/rtc_base/cryptstring.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/rtc_base/criticalsection_unittest.cc ('k') | webrtc/rtc_base/cryptstring.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_RTC_BASE_CRYPTSTRING_H_
12 #define _WEBRTC_BASE_CRYPTSTRING_H_ 12 #define WEBRTC_RTC_BASE_CRYPTSTRING_H_
13 13
14 #include <string.h> 14 #include <string.h>
15 15
16 #include <memory> 16 #include <memory>
17 #include <string> 17 #include <string>
18 #include <vector> 18 #include <vector>
19 19
20 namespace rtc { 20 namespace rtc {
21 21
22 class CryptStringImpl { 22 class CryptStringImpl {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Used for constructing strings where a password is involved and we 67 // Used for constructing strings where a password is involved and we
68 // need to ensure that we zero memory afterwards 68 // need to ensure that we zero memory afterwards
69 class FormatCryptString { 69 class FormatCryptString {
70 public: 70 public:
71 FormatCryptString() { 71 FormatCryptString() {
72 storage_ = new char[32]; 72 storage_ = new char[32];
73 capacity_ = 32; 73 capacity_ = 32;
74 length_ = 0; 74 length_ = 0;
75 storage_[0] = 0; 75 storage_[0] = 0;
76 } 76 }
77 77
78 void Append(const std::string & text) { 78 void Append(const std::string & text) {
79 Append(text.data(), text.length()); 79 Append(text.data(), text.length());
80 } 80 }
81 81
82 void Append(const char * data, size_t length) { 82 void Append(const char * data, size_t length) {
83 EnsureStorage(length_ + length + 1); 83 EnsureStorage(length_ + length + 1);
84 memcpy(storage_ + length_, data, length); 84 memcpy(storage_ + length_, data, length);
85 length_ += length; 85 length_ += length;
86 storage_[length_] = '\0'; 86 storage_[length_] = '\0';
87 } 87 }
88 88
89 void Append(const CryptString * password) { 89 void Append(const CryptString * password) {
90 size_t len = password->GetLength(); 90 size_t len = password->GetLength();
91 EnsureStorage(length_ + len + 1); 91 EnsureStorage(length_ + len + 1);
92 password->CopyTo(storage_ + length_, true); 92 password->CopyTo(storage_ + length_, true);
93 length_ += len; 93 length_ += len;
94 } 94 }
95 95
96 size_t GetLength() { 96 size_t GetLength() {
97 return length_; 97 return length_;
98 } 98 }
(...skipping 15 matching lines...) Expand all
114 for (;;) { 114 for (;;) {
115 capacity_ *= 2; 115 capacity_ *= 2;
116 if (capacity_ >= n) 116 if (capacity_ >= n)
117 break; 117 break;
118 } 118 }
119 119
120 storage_ = new char[capacity_]; 120 storage_ = new char[capacity_];
121 121
122 if (old_capacity) { 122 if (old_capacity) {
123 memcpy(storage_, old_storage, length_); 123 memcpy(storage_, old_storage, length_);
124 124
125 // zero memory in a way that an optimizer won't optimize it out 125 // zero memory in a way that an optimizer won't optimize it out
126 old_storage[0] = 0; 126 old_storage[0] = 0;
127 for (size_t i = 1; i < old_capacity; i++) { 127 for (size_t i = 1; i < old_capacity; i++) {
128 old_storage[i] = old_storage[i - 1]; 128 old_storage[i] = old_storage[i - 1];
129 } 129 }
130 delete[] old_storage; 130 delete[] old_storage;
131 } 131 }
132 } 132 }
133 133
134 ~FormatCryptString() { 134 ~FormatCryptString() {
135 if (capacity_) { 135 if (capacity_) {
136 storage_[0] = 0; 136 storage_[0] = 0;
137 for (size_t i = 1; i < capacity_; i++) { 137 for (size_t i = 1; i < capacity_; i++) {
138 storage_[i] = storage_[i - 1]; 138 storage_[i] = storage_[i - 1];
139 } 139 }
140 } 140 }
141 delete[] storage_; 141 delete[] storage_;
142 } 142 }
(...skipping 14 matching lines...) Expand all
157 std::string UrlEncode() const override; 157 std::string UrlEncode() const override;
158 CryptStringImpl* Copy() const override; 158 CryptStringImpl* Copy() const override;
159 void CopyRawTo(std::vector<unsigned char>* dest) const override; 159 void CopyRawTo(std::vector<unsigned char>* dest) const override;
160 160
161 private: 161 private:
162 std::string password_; 162 std::string password_;
163 }; 163 };
164 164
165 } 165 }
166 166
167 #endif // _WEBRTC_BASE_CRYPTSTRING_H_ 167 #endif // WEBRTC_RTC_BASE_CRYPTSTRING_H_
OLDNEW
« no previous file with comments | « webrtc/rtc_base/criticalsection_unittest.cc ('k') | webrtc/rtc_base/cryptstring.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698