blob: e51111f8a4c76ca3f3c8184a2e500e25ca5fcead [file] [log] [blame]
Jonas Oreland1cd39fa2018-10-11 07:47:12 +02001/*
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 "p2p/base/icecredentialsiterator.h"
Yves Gerey3e707812018-11-28 16:47:49 +010012
13#include "p2p/base/p2pconstants.h"
Jonas Oreland1cd39fa2018-10-11 07:47:12 +020014#include "rtc_base/helpers.h"
15
16namespace cricket {
17
18IceCredentialsIterator::IceCredentialsIterator(
19 const std::vector<IceParameters>& pooled_credentials)
20 : pooled_ice_credentials_(pooled_credentials) {}
21
22IceCredentialsIterator::~IceCredentialsIterator() = default;
23
24IceParameters IceCredentialsIterator::CreateRandomIceCredentials() {
25 return IceParameters(rtc::CreateRandomString(ICE_UFRAG_LENGTH),
26 rtc::CreateRandomString(ICE_PWD_LENGTH), false);
27}
28
29IceParameters IceCredentialsIterator::GetIceCredentials() {
30 if (pooled_ice_credentials_.empty()) {
31 return CreateRandomIceCredentials();
32 }
33 IceParameters credentials = pooled_ice_credentials_.back();
34 pooled_ice_credentials_.pop_back();
35 return credentials;
36}
37
38} // namespace cricket