Sha256: b8b3916cb4e458692e89a870166f86a8b838fcba52a3284e3e2e3c2b7e8e74e3

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 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

2 entries across 2 versions & 1 rubygems

Version Path
couchbase-3.5.3 ext/couchbase/core/sasl/mechanism.cc
couchbase-3.5.2 ext/couchbase/core/sasl/mechanism.cc