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 <stddef.h> 14 15 #include "rtc_base/string_encode.h" 16 17 namespace webrtc_examples { 18 ReadAuthFile(std::istream * s)19std::map<std::string, std::string> ReadAuthFile(std::istream* s) { 20 std::map<std::string, std::string> name_to_key; 21 for (std::string line; std::getline(*s, line);) { 22 const size_t sep = line.find('='); 23 if (sep == std::string::npos) 24 continue; 25 char buf[32]; 26 size_t len = rtc::hex_decode(buf, sizeof(buf), line.data() + sep + 1, 27 line.size() - sep - 1); 28 if (len > 0) { 29 name_to_key.emplace(line.substr(0, sep), std::string(buf, len)); 30 } 31 } 32 return name_to_key; 33 } 34 35 } // namespace webrtc_examples 36