-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connector warns on concurrent PC/SC calls (#782)
Add warning logs into Smart Card Connector whenever a client application emits illegal concurrent PC/SC requests: an SCARDCONTEXT must only be used from a single thread (with the only exception of SCardCancel that can be called concurrently). This is preparation for disallowing concurrent PC/SC calls in the future as planned in #136. Concurrent calls are not allowed by the PC/SC API specification, and the PC/SC-Lite's implementation breaks in subtle ways when this is violated.
- Loading branch information
1 parent
23b88ac
commit d640559
Showing
7 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2022 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef GOOGLE_SMART_CARD_COMMON_JOIN_STRING_H_ | ||
#define GOOGLE_SMART_CARD_COMMON_JOIN_STRING_H_ | ||
|
||
#include <string> | ||
|
||
namespace google_smart_card { | ||
|
||
template <typename Container> | ||
std::string JoinStrings(const Container& container, | ||
const std::string& separator) { | ||
if (container.empty()) { | ||
return ""; | ||
} | ||
|
||
size_t need_size = separator.size() * (container.size() - 1); | ||
for (const auto& item : container) { | ||
need_size += item.length(); | ||
} | ||
|
||
std::string joined; | ||
joined.reserve(need_size); | ||
bool is_first = true; | ||
for (const auto& item : container) { | ||
if (!is_first) { | ||
joined += separator; | ||
} | ||
is_first = false; | ||
joined += item; | ||
} | ||
return joined; | ||
} | ||
|
||
} // namespace google_smart_card | ||
|
||
#endif // GOOGLE_SMART_CARD_COMMON_JOIN_STRING_H_ |
62 changes: 62 additions & 0 deletions
62
common/cpp/src/google_smart_card_common/join_string_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2022 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <google_smart_card_common/join_string.h> | ||
|
||
#include <set> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace google_smart_card { | ||
namespace { | ||
|
||
TEST(JoinString, EmptyVector) { | ||
std::vector<std::string> vec; | ||
EXPECT_EQ(JoinStrings(vec, /*separator=*/","), ""); | ||
} | ||
|
||
TEST(JoinString, OneItemVector) { | ||
std::vector<std::string> vec = {"foo"}; | ||
EXPECT_EQ(JoinStrings(vec, /*separator=*/","), "foo"); | ||
} | ||
|
||
TEST(JoinString, TwoItemsVector) { | ||
std::vector<std::string> vec = {"foo", "bar"}; | ||
EXPECT_EQ(JoinStrings(vec, /*separator=*/","), "foo,bar"); | ||
} | ||
|
||
TEST(JoinString, TwoItemsSet) { | ||
std::set<std::string> vec = {"a", "b"}; | ||
EXPECT_EQ(JoinStrings(vec, /*separator=*/" - "), "a - b"); | ||
} | ||
|
||
TEST(JoinString, EmptySeparator) { | ||
std::vector<std::string> vec = {"foo", "bar", "foo"}; | ||
EXPECT_EQ(JoinStrings(vec, /*separator=*/""), "foobarfoo"); | ||
} | ||
|
||
TEST(JoinString, EmptyItem) { | ||
std::vector<std::string> vec = {"foo", "", "bar"}; | ||
EXPECT_EQ(JoinStrings(vec, /*separator=*/","), "foo,,bar"); | ||
} | ||
|
||
TEST(JoinString, EmptyItemsOnly) { | ||
std::vector<std::string> vec = {"", "", ""}; | ||
EXPECT_EQ(JoinStrings(vec, /*separator=*/","), ",,"); | ||
} | ||
|
||
} // namespace | ||
} // namespace google_smart_card |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.