summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2018-07-28 11:45:35 (GMT)
committerTobias Markmann <tm@ayena.de>2018-07-30 13:27:15 (GMT)
commit798f8ec3331043a92f6ca3bc810b9477c3f8261e (patch)
tree868bde2ddcbad1a66d4256edd6050f486860eb2b /Swiften/StreamStack/TLSLayer.cpp
parent48596613cfe0f45c0916beabbcc3a27e01752c4b (diff)
downloadswift-798f8ec3331043a92f6ca3bc810b9477c3f8261e.zip
swift-798f8ec3331043a92f6ca3bc810b9477c3f8261e.tar.bz2
Use std::unique_ptr to have TLS classes own the TLSContext
TLSLayer and TLSConnection now own the TLSContext they use. The TLSContextFactory interface is adjusted to use std::unique_ptr. Test-Information: Builds and all tests pass on macOS with clang-7-master. Change-Id: I14e33c98b48445094f404b73ea41af0a51d2dde6
Diffstat (limited to 'Swiften/StreamStack/TLSLayer.cpp')
-rw-r--r--Swiften/StreamStack/TLSLayer.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/Swiften/StreamStack/TLSLayer.cpp b/Swiften/StreamStack/TLSLayer.cpp
index ced879e..9f84889 100644
--- a/Swiften/StreamStack/TLSLayer.cpp
+++ b/Swiften/StreamStack/TLSLayer.cpp
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
@@ -8,2 +8,4 @@
+#include <memory>
+
#include <boost/bind.hpp>
@@ -15,8 +17,7 @@ namespace Swift {
-TLSLayer::TLSLayer(TLSContextFactory* factory, const TLSOptions& tlsOptions) {
- context = factory->createTLSContext(tlsOptions);
- context->onDataForNetwork.connect(boost::bind(&TLSLayer::writeDataToChildLayer, this, _1));
- context->onDataForApplication.connect(boost::bind(&TLSLayer::writeDataToParentLayer, this, _1));
- context->onConnected.connect(onConnected);
- context->onError.connect(onError);
+TLSLayer::TLSLayer(std::unique_ptr<TLSContext> tlsContext) : context_(std::move(tlsContext)) {
+ context_->onDataForNetwork.connect(boost::bind(&TLSLayer::writeDataToChildLayer, this, _1));
+ context_->onDataForApplication.connect(boost::bind(&TLSLayer::writeDataToParentLayer, this, _1));
+ context_->onConnected.connect(onConnected);
+ context_->onError.connect(onError);
}
@@ -24,3 +25,2 @@ TLSLayer::TLSLayer(TLSContextFactory* factory, const TLSOptions& tlsOptions) {
TLSLayer::~TLSLayer() {
- delete context;
}
@@ -28,3 +28,3 @@ TLSLayer::~TLSLayer() {
void TLSLayer::connect() {
- context->connect();
+ context_->connect();
}
@@ -32,3 +32,3 @@ void TLSLayer::connect() {
void TLSLayer::writeData(const SafeByteArray& data) {
- context->handleDataFromApplication(data);
+ context_->handleDataFromApplication(data);
}
@@ -36,3 +36,3 @@ void TLSLayer::writeData(const SafeByteArray& data) {
void TLSLayer::handleDataRead(const SafeByteArray& data) {
- context->handleDataFromNetwork(data);
+ context_->handleDataFromNetwork(data);
}
@@ -40,3 +40,3 @@ void TLSLayer::handleDataRead(const SafeByteArray& data) {
bool TLSLayer::setClientCertificate(CertificateWithKey::ref certificate) {
- return context->setClientCertificate(certificate);
+ return context_->setClientCertificate(certificate);
}
@@ -44,3 +44,3 @@ bool TLSLayer::setClientCertificate(CertificateWithKey::ref certificate) {
Certificate::ref TLSLayer::getPeerCertificate() const {
- return context->getPeerCertificate();
+ return context_->getPeerCertificate();
}
@@ -48,3 +48,3 @@ Certificate::ref TLSLayer::getPeerCertificate() const {
std::vector<Certificate::ref> TLSLayer::getPeerCertificateChain() const {
- return context->getPeerCertificateChain();
+ return context_->getPeerCertificateChain();
}
@@ -52,3 +52,3 @@ std::vector<Certificate::ref> TLSLayer::getPeerCertificateChain() const {
std::shared_ptr<CertificateVerificationError> TLSLayer::getPeerCertificateVerificationError() const {
- return context->getPeerCertificateVerificationError();
+ return context_->getPeerCertificateVerificationError();
}