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 "p2p/base/ice_credentials_iterator.h"
12 
13 #include "p2p/base/p2p_constants.h"
14 #include "rtc_base/helpers.h"
15 
16 namespace cricket {
17 
IceCredentialsIterator(const std::vector<IceParameters> & pooled_credentials)18 IceCredentialsIterator::IceCredentialsIterator(
19     const std::vector<IceParameters>& pooled_credentials)
20     : pooled_ice_credentials_(pooled_credentials) {}
21 
22 IceCredentialsIterator::~IceCredentialsIterator() = default;
23 
CreateRandomIceCredentials()24 IceParameters IceCredentialsIterator::CreateRandomIceCredentials() {
25   return IceParameters(rtc::CreateRandomString(ICE_UFRAG_LENGTH),
26                        rtc::CreateRandomString(ICE_PWD_LENGTH), false);
27 }
28 
GetIceCredentials()29 IceParameters 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
39