summaryrefslogtreecommitdiff
path: root/chromium/components/cryptauth/fake_secure_context.cc
blob: 1592302d1880d67c6fa4f2b9805f4d79db60e52c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/cryptauth/fake_secure_context.h"

#include <stddef.h>

#include "base/strings/string_util.h"

namespace cryptauth {

namespace {

const char kFakeEncodingSuffix[] = ", but encoded";
const size_t kFakeEncodingSuffixLen = sizeof(kFakeEncodingSuffix) - 1;
const char kChannelBindingData[] = "channel binding data";

}  // namespace

FakeSecureContext::FakeSecureContext()
    : protocol_version_(SecureContext::PROTOCOL_VERSION_THREE_ONE) {}

FakeSecureContext::~FakeSecureContext() {}

std::string FakeSecureContext::GetChannelBindingData() const {
  return kChannelBindingData;
}

SecureContext::ProtocolVersion FakeSecureContext::GetProtocolVersion() const {
  return protocol_version_;
}

void FakeSecureContext::Encode(const std::string& message,
                               const MessageCallback& callback) {
  callback.Run(message + kFakeEncodingSuffix);
}

void FakeSecureContext::Decode(const std::string& encoded_message,
                               const MessageCallback& callback) {
  if (!EndsWith(encoded_message, kFakeEncodingSuffix,
                base::CompareCase::SENSITIVE)) {
    callback.Run(std::string());
  }

  std::string decoded_message = encoded_message;
  decoded_message.erase(decoded_message.size() - kFakeEncodingSuffixLen);
  callback.Run(decoded_message);
}

}  // namespace cryptauth