blob: 421710c7c8d53cbcbff875abe5adcb4887c086cb [file] [log] [blame]
deadbeeff137e972017-03-23 15:45:49 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/cryptstring.h"
deadbeeff137e972017-03-23 15:45:49 -070012
13namespace rtc {
14
15size_t EmptyCryptStringImpl::GetLength() const {
16 return 0;
17}
18
19void EmptyCryptStringImpl::CopyTo(char* dest, bool nullterminate) const {
20 if (nullterminate) {
21 *dest = '\0';
22 }
23}
24
25std::string EmptyCryptStringImpl::UrlEncode() const {
26 return "";
27}
28
29CryptStringImpl* EmptyCryptStringImpl::Copy() const {
30 return new EmptyCryptStringImpl();
31}
32
33void EmptyCryptStringImpl::CopyRawTo(std::vector<unsigned char>* dest) const {
34 dest->clear();
35}
36
37CryptString::CryptString() : impl_(new EmptyCryptStringImpl()) {
38}
39
40CryptString::CryptString(const CryptString& other)
41 : impl_(other.impl_->Copy()) {
42}
43
44CryptString::CryptString(const CryptStringImpl& impl) : impl_(impl.Copy()) {
45}
46
47CryptString::~CryptString() = default;
48
49size_t InsecureCryptStringImpl::GetLength() const {
50 return password_.size();
51}
52
53void InsecureCryptStringImpl::CopyTo(char* dest, bool nullterminate) const {
54 memcpy(dest, password_.data(), password_.size());
55 if (nullterminate)
56 dest[password_.size()] = 0;
57}
58
59std::string InsecureCryptStringImpl::UrlEncode() const {
60 return password_;
61}
62
63CryptStringImpl* InsecureCryptStringImpl::Copy() const {
64 InsecureCryptStringImpl* copy = new InsecureCryptStringImpl;
65 copy->password() = password_;
66 return copy;
67}
68
69void 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