You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB

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