read_auth_file.cc (1240B)
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" 12 13 #include <cstddef> 14 #include <istream> 15 #include <map> 16 #include <string> 17 18 #include "absl/strings/string_view.h" 19 #include "api/array_view.h" 20 #include "rtc_base/string_encode.h" 21 22 namespace webrtc_examples { 23 24 std::map<std::string, std::string> ReadAuthFile(std::istream* s) { 25 std::map<std::string, std::string> name_to_key; 26 for (std::string line; std::getline(*s, line);) { 27 const size_t sep = line.find('='); 28 if (sep == std::string::npos) 29 continue; 30 char buf[32]; 31 size_t len = webrtc::hex_decode(webrtc::ArrayView<char>(buf), 32 absl::string_view(line).substr(sep + 1)); 33 if (len > 0) { 34 name_to_key.emplace(line.substr(0, sep), std::string(buf, len)); 35 } 36 } 37 return name_to_key; 38 } 39 40 } // namespace webrtc_examples