blob: 566cf573ecb877741dfd66830549869bb4329570 (
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
|
// Copyright (c) 2011 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 "net/curvecp/connection_key.h"
#include <string.h>
namespace net {
ConnectionKey::ConnectionKey() {
memset(key_, 0, sizeof(key_));
}
ConnectionKey::ConnectionKey(unsigned char bytes[]) {
memcpy(key_, bytes, sizeof(key_));
}
ConnectionKey::ConnectionKey(const ConnectionKey& other) {
memcpy(key_, other.key_, sizeof(key_));
}
ConnectionKey& ConnectionKey::operator=(const ConnectionKey& other) {
memcpy(key_, other.key_, sizeof(key_));
return *this;
}
bool ConnectionKey::operator==(const ConnectionKey& other) const {
return memcmp(key_, other.key_, sizeof(key_)) == 0;
}
bool ConnectionKey::operator<(const ConnectionKey& other) const {
return memcmp(key_, other.key_, sizeof(key_)) < 0;
}
std::string ConnectionKey::ToString() const {
// TODO(mbelshe): make this a nice hex formatter
return std::string("key") +
std::string(reinterpret_cast<const char*>(key_), 32);
}
} // namespace net
|