Sha256: 455009e098c9ec80e417b8705cc11efe32b4b6360aa02431b1ca18875d77edd6

Contents?: true

Size: 1.72 KB

Versions: 2

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 <cbsasl/mechanism.h>

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

namespace couchbase::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::sasl

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
couchbase-3.2.0-universal-darwin-20 ext/couchbase/cbsasl/mechanism.cc
couchbase-3.2.0 ext/couchbase/cbsasl/mechanism.cc