blob: de5465e82fe8339b01d527cf4642e03a06bf662a [file] [log] [blame]
Niels Möller9862c2e2018-10-30 12:20:03 +01001/*
2 * Copyright 2018 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "examples/turnserver/read_auth_file.h"
12#include "rtc_base/stringencode.h"
13
14namespace webrtc_examples {
15
Mirko Bonadei44ca9a32018-11-13 11:16:40 +010016std::map<std::string, std::string> ReadAuthFile(std::istream* s) {
Niels Möller9862c2e2018-10-30 12:20:03 +010017 std::map<std::string, std::string> name_to_key;
18 for (std::string line; std::getline(*s, line);) {
19 const size_t sep = line.find('=');
20 if (sep == std::string::npos)
21 continue;
22 char buf[32];
23 size_t len = rtc::hex_decode(buf, sizeof(buf), line.data() + sep + 1,
24 line.size() - sep - 1);
25 if (len > 0) {
26 name_to_key.emplace(line.substr(0, sep), std::string(buf, len));
27 }
28 }
29 return name_to_key;
30}
31
32} // namespace webrtc_examples