blob: adb2fd894ad76a4efce5e2c490b3d4948fbc0918 [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
16std::map<std::string, std::string> ReadAuthFile(
17 std::istream* s) { // no-presubmit-check TODO(webrtc:8982)
18 std::map<std::string, std::string> name_to_key;
19 for (std::string line; std::getline(*s, line);) {
20 const size_t sep = line.find('=');
21 if (sep == std::string::npos)
22 continue;
23 char buf[32];
24 size_t len = rtc::hex_decode(buf, sizeof(buf), line.data() + sep + 1,
25 line.size() - sep - 1);
26 if (len > 0) {
27 name_to_key.emplace(line.substr(0, sep), std::string(buf, len));
28 }
29 }
30 return name_to_key;
31}
32
33} // namespace webrtc_examples