deadbeef | f137e97 | 2017-03-23 22:45:49 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "rtc_base/crypt_string.h" |
deadbeef | f137e97 | 2017-03-23 22:45:49 | [diff] [blame] | 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 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 37 | CryptString::CryptString() : impl_(new EmptyCryptStringImpl()) {} |
deadbeef | f137e97 | 2017-03-23 22:45:49 | [diff] [blame] | 38 | |
| 39 | CryptString::CryptString(const CryptString& other) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 40 | : impl_(other.impl_->Copy()) {} |
deadbeef | f137e97 | 2017-03-23 22:45:49 | [diff] [blame] | 41 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 42 | CryptString::CryptString(const CryptStringImpl& impl) : impl_(impl.Copy()) {} |
deadbeef | f137e97 | 2017-03-23 22:45:49 | [diff] [blame] | 43 | |
| 44 | CryptString::~CryptString() = default; |
| 45 | |
| 46 | size_t InsecureCryptStringImpl::GetLength() const { |
| 47 | return password_.size(); |
| 48 | } |
| 49 | |
| 50 | void InsecureCryptStringImpl::CopyTo(char* dest, bool nullterminate) const { |
| 51 | memcpy(dest, password_.data(), password_.size()); |
| 52 | if (nullterminate) |
| 53 | dest[password_.size()] = 0; |
| 54 | } |
| 55 | |
| 56 | std::string InsecureCryptStringImpl::UrlEncode() const { |
| 57 | return password_; |
| 58 | } |
| 59 | |
| 60 | CryptStringImpl* InsecureCryptStringImpl::Copy() const { |
| 61 | InsecureCryptStringImpl* copy = new InsecureCryptStringImpl; |
| 62 | copy->password() = password_; |
| 63 | return copy; |
| 64 | } |
| 65 | |
| 66 | void InsecureCryptStringImpl::CopyRawTo( |
| 67 | std::vector<unsigned char>* dest) const { |
| 68 | dest->resize(password_.size()); |
| 69 | memcpy(&dest->front(), password_.data(), password_.size()); |
| 70 | } |
| 71 | |
Nico Weber | 22f9925 | 2019-02-20 15:13:16 | [diff] [blame^] | 72 | } // namespace rtc |