Sha256: ab9d0ac0139f2b5085f3eff21e528ca89f4c481d1ab88eabd40949b4c13cde8c

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
 *     Copyright 2018 Couchbase, Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

#include "mechanism.h"

#include <algorithm>
#include <iterator>
#include <vector>

namespace couchbase::core::sasl
{

Mechanism
select_mechanism(const std::vector<std::string>& available_mechanisms)
{
    // Search what we've got backends for
    const std::vector<std::pair<std::string, Mechanism>> mechs = { { std::string{ "SCRAM-SHA512" }, Mechanism::SCRAM_SHA512 },
                                                                   { std::string{ "SCRAM-SHA256" }, Mechanism::SCRAM_SHA256 },
                                                                   { std::string{ "SCRAM-SHA1" }, Mechanism::SCRAM_SHA1 },
                                                                   { std::string{ "PLAIN" }, Mechanism::PLAIN } };

    for (const auto& [name, code] : mechs) {
        if (std::find(available_mechanisms.begin(), available_mechanisms.end(), name) != available_mechanisms.end()) {
            return code;
        }
    }

    throw unknown_mechanism("unknown mechanism"); // TODO: avoid this exception
}

} // namespace couchbase::core::sasl

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
couchbase-3.5.1 ext/couchbase/core/sasl/mechanism.cc
couchbase-3.5.0 ext/couchbase/core/sasl/mechanism.cc
couchbase-3.4.5 ext/couchbase/core/sasl/mechanism.cc
couchbase-3.4.4 ext/couchbase/core/sasl/mechanism.cc
couchbase-3.4.3 ext/couchbase/core/sasl/mechanism.cc
couchbase-3.4.2 ext/couchbase/core/sasl/mechanism.cc
couchbase-3.4.1 ext/couchbase/core/sasl/mechanism.cc
couchbase-3.4.0 ext/couchbase/core/sasl/mechanism.cc