Kea 2.7.6
basic_auth.cc
Go to the documentation of this file.
1// Copyright (C) 2020-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <http/basic_auth.h>
10#include <util/encode/encode.h>
11#include <util/encode/utf8.h>
12
13using namespace isc::util::encode;
14using namespace std;
15
16namespace isc {
17namespace http {
18
19BasicHttpAuth::BasicHttpAuth(const std::string& user,
20 const std::string& password)
21 : user_(user), password_(password) {
22 if (user.find(':') != string::npos) {
23 isc_throw(BadValue, "user '" << user << "' must not contain a ':'");
24 }
25 buildSecret();
26 buildCredential();
27}
28
29BasicHttpAuth::BasicHttpAuth(const std::string& secret) : secret_(secret) {
30 if (secret.find(':') == string::npos) {
31 isc_throw(BadValue, "secret '" << secret << "' must contain a ':");
32 }
33 buildCredential();
34}
35
36void BasicHttpAuth::buildSecret() {
37 secret_ = user_ + ":" + password_;
38}
39
40void BasicHttpAuth::buildCredential() {
41 credential_ = encodeBase64(encodeUtf8(secret_));
42}
43
44} // end of namespace isc::http
45} // end of namespace isc
BasicHttpAuth(const std::string &user, const std::string &password)
Constructor.
Definition basic_auth.cc:19
string encodeBase64(const vector< uint8_t > &binary)
Encode binary data in the base64 format.
Definition encode.cc:337
std::vector< uint8_t > encodeUtf8(const std::string &value)
Encode value string into UTF-8.
Definition utf8.cc:15
Defines the logger used by the top-level component of kea-lfc.