OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "webrtc/base/cryptstring.h" |
| 12 |
| 13 namespace rtc { |
| 14 |
| 15 size_t EmptyCryptStringImpl::GetLength() const { |
| 16 return 0; |
| 17 } |
| 18 |
| 19 void EmptyCryptStringImpl::CopyTo(char* dest, bool nullterminate) const { |
| 20 if (nullterminate) { |
| 21 *dest = '\0'; |
| 22 } |
| 23 } |
| 24 |
| 25 std::string EmptyCryptStringImpl::UrlEncode() const { |
| 26 return ""; |
| 27 } |
| 28 |
| 29 CryptStringImpl* EmptyCryptStringImpl::Copy() const { |
| 30 return new EmptyCryptStringImpl(); |
| 31 } |
| 32 |
| 33 void EmptyCryptStringImpl::CopyRawTo(std::vector<unsigned char>* dest) const { |
| 34 dest->clear(); |
| 35 } |
| 36 |
| 37 CryptString::CryptString() : impl_(new EmptyCryptStringImpl()) { |
| 38 } |
| 39 |
| 40 CryptString::CryptString(const CryptString& other) |
| 41 : impl_(other.impl_->Copy()) { |
| 42 } |
| 43 |
| 44 CryptString::CryptString(const CryptStringImpl& impl) : impl_(impl.Copy()) { |
| 45 } |
| 46 |
| 47 CryptString::~CryptString() = default; |
| 48 |
| 49 size_t InsecureCryptStringImpl::GetLength() const { |
| 50 return password_.size(); |
| 51 } |
| 52 |
| 53 void InsecureCryptStringImpl::CopyTo(char* dest, bool nullterminate) const { |
| 54 memcpy(dest, password_.data(), password_.size()); |
| 55 if (nullterminate) |
| 56 dest[password_.size()] = 0; |
| 57 } |
| 58 |
| 59 std::string InsecureCryptStringImpl::UrlEncode() const { |
| 60 return password_; |
| 61 } |
| 62 |
| 63 CryptStringImpl* InsecureCryptStringImpl::Copy() const { |
| 64 InsecureCryptStringImpl* copy = new InsecureCryptStringImpl; |
| 65 copy->password() = password_; |
| 66 return copy; |
| 67 } |
| 68 |
| 69 void InsecureCryptStringImpl::CopyRawTo( |
| 70 std::vector<unsigned char>* dest) const { |
| 71 dest->resize(password_.size()); |
| 72 memcpy(&dest->front(), password_.data(), password_.size()); |
| 73 } |
| 74 |
| 75 }; // namespace rtc |
OLD | NEW |