blob: ed0ff163bab9bb887e44d294b8e33932ba25a2aa [file] [log] [blame]
deadbeeff137e972017-03-23 22:45:491/*
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 Anton10542f22019-01-11 17:11:0011#include "rtc_base/crypt_string.h"
deadbeeff137e972017-03-23 22:45:4912
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
Yves Gerey665174f2018-06-19 13:03:0537CryptString::CryptString() : impl_(new EmptyCryptStringImpl()) {}
deadbeeff137e972017-03-23 22:45:4938
39CryptString::CryptString(const CryptString& other)
Yves Gerey665174f2018-06-19 13:03:0540 : impl_(other.impl_->Copy()) {}
deadbeeff137e972017-03-23 22:45:4941
Yves Gerey665174f2018-06-19 13:03:0542CryptString::CryptString(const CryptStringImpl& impl) : impl_(impl.Copy()) {}
deadbeeff137e972017-03-23 22:45:4943
44CryptString::~CryptString() = default;
45
46size_t InsecureCryptStringImpl::GetLength() const {
47 return password_.size();
48}
49
50void InsecureCryptStringImpl::CopyTo(char* dest, bool nullterminate) const {
51 memcpy(dest, password_.data(), password_.size());
52 if (nullterminate)
53 dest[password_.size()] = 0;
54}
55
56std::string InsecureCryptStringImpl::UrlEncode() const {
57 return password_;
58}
59
60CryptStringImpl* InsecureCryptStringImpl::Copy() const {
61 InsecureCryptStringImpl* copy = new InsecureCryptStringImpl;
62 copy->password() = password_;
63 return copy;
64}
65
66void 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 Weber22f99252019-02-20 15:13:1672} // namespace rtc