Niels Möller | 9862c2e | 2018-10-30 12:20:03 +0100 | [diff] [blame] | 1 | /* |
| 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" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 12 | |
| 13 | #include <stddef.h> |
| 14 | |
Ali Tofigh | fd6a4d6 | 2022-03-31 10:36:48 +0200 | [diff] [blame] | 15 | #include "absl/strings/string_view.h" |
| 16 | #include "api/array_view.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 17 | #include "rtc_base/string_encode.h" |
Niels Möller | 9862c2e | 2018-10-30 12:20:03 +0100 | [diff] [blame] | 18 | |
| 19 | namespace webrtc_examples { |
| 20 | |
Mirko Bonadei | 44ca9a3 | 2018-11-13 11:16:40 +0100 | [diff] [blame] | 21 | std::map<std::string, std::string> ReadAuthFile(std::istream* s) { |
Niels Möller | 9862c2e | 2018-10-30 12:20:03 +0100 | [diff] [blame] | 22 | std::map<std::string, std::string> name_to_key; |
| 23 | for (std::string line; std::getline(*s, line);) { |
| 24 | const size_t sep = line.find('='); |
| 25 | if (sep == std::string::npos) |
| 26 | continue; |
| 27 | char buf[32]; |
Ali Tofigh | fd6a4d6 | 2022-03-31 10:36:48 +0200 | [diff] [blame] | 28 | size_t len = rtc::hex_decode(rtc::ArrayView<char>(buf), |
| 29 | absl::string_view(line).substr(sep + 1)); |
Niels Möller | 9862c2e | 2018-10-30 12:20:03 +0100 | [diff] [blame] | 30 | if (len > 0) { |
| 31 | name_to_key.emplace(line.substr(0, sep), std::string(buf, len)); |
| 32 | } |
| 33 | } |
| 34 | return name_to_key; |
| 35 | } |
| 36 | |
| 37 | } // namespace webrtc_examples |