Skip to content

Adding functionality to read and set additional pages of device info #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cd56fdc
Rename Ccid to SmartCard connection
DennisDyallo May 15, 2024
6faa10f
Set device info for nfc restricted
DennisDyallo May 15, 2024
34c17ac
Fix cref in documentation
DennisDyallo May 15, 2024
d7f818f
Fix doc cref
DennisDyallo May 15, 2024
8917cd4
Marking old methods as obsolete
DennisDyallo May 15, 2024
b60de79
Adding paged device info
DennisDyallo May 15, 2024
01b562e
Remove warning
DennisDyallo May 15, 2024
cfc698c
Fix doc cref
DennisDyallo May 15, 2024
501bc46
Adding tags
DennisDyallo May 15, 2024
0e0fc48
Minor refactor
DennisDyallo May 15, 2024
ab71f14
Test changes
DennisDyallo May 15, 2024
c045a87
Not supported in this lang version
DennisDyallo May 16, 2024
dff6fb6
Refactoring of paged device info
DennisDyallo May 16, 2024
48c87da
Discard
DennisDyallo May 17, 2024
f9f957b
inheritdoc
DennisDyallo May 17, 2024
96b2923
Handle nullable
DennisDyallo May 17, 2024
3ec1374
Add doc
DennisDyallo May 17, 2024
0f84938
Refactor
DennisDyallo May 17, 2024
e7c46e1
Rename
DennisDyallo May 17, 2024
15ad2f2
Fix tests
DennisDyallo May 17, 2024
0010b13
dotnet format
DennisDyallo May 17, 2024
0b2ff30
XMl doc
DennisDyallo May 17, 2024
ea58382
dotnet format
DennisDyallo May 17, 2024
16a899f
Rename
DennisDyallo May 17, 2024
580cab5
Renames
DennisDyallo May 17, 2024
7b1c868
Add feature flag
DennisDyallo May 17, 2024
907b5d5
Add tests
DennisDyallo May 17, 2024
12a38de
Amendments
DennisDyallo May 17, 2024
6a50bb2
Amendments
DennisDyallo May 17, 2024
c6e6648
Add additional tags
DennisDyallo May 17, 2024
53f1815
Refactor
DennisDyallo May 17, 2024
05e68f5
Add additional tags
DennisDyallo May 17, 2024
29b9101
Rename for readability
DennisDyallo May 17, 2024
e3d0793
Remove unused usings
DennisDyallo May 17, 2024
df3476b
dotnet format and editorconfig changes
DennisDyallo May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 76 additions & 67 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
root = true
# Copyright 2021 Yubico AB
#
# Licensed under the Apache License, Version 2.0 (the "License").
Expand All @@ -12,15 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

root = true

# All files
[*]

# IDE0073: File header
dotnet_diagnostic.IDE0073.severity = suggestion
dotnet_diagnostic.ide0073.severity = suggestion
file_header_template = Copyright 2023 Yubico AB\n\nLicensed under the Apache License, Version 2.0 (the "License").\nYou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an "AS IS" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.


# C# files
[*.cs]

Expand Down Expand Up @@ -187,30 +188,29 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

# ReSharper properties
resharper_space_within_single_line_array_initializer_braces=true


#
# Dev project rules
Expand All @@ -220,7 +220,7 @@ resharper_space_within_single_line_array_initializer_braces=true

# Make this go away once the current ones are fixed.
# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = suggestion
dotnet_diagnostic.cs1591.severity = suggestion

# Expression-bodied members
csharp_style_expression_bodied_accessors = true:warning
Expand All @@ -236,87 +236,96 @@ csharp_style_expression_bodied_properties = when_on_single_line:warning
dotnet_code_quality_unused_parameters = all:warning

# ReSharper properties
resharper_align_first_arg_by_paren=false
resharper_align_linq_query=true
resharper_align_multiline_argument=true
resharper_align_multiline_array_and_object_initializer=false
resharper_align_multiline_binary_expressions_chain=false
resharper_align_multiline_calls_chain=false
resharper_align_multiline_expression=true
resharper_align_multiline_extends_list=true
resharper_align_multiline_for_stmt=false
resharper_align_multline_type_parameter_constrains=false
resharper_align_multline_type_parameter_list=false
resharper_align_tuple_components=false
resharper_blank_lines_after_control_transfer_statements=1
resharper_blank_lines_after_multiline_statements=1
resharper_blank_lines_before_block_statements=1
resharper_blank_lines_before_control_transfer_statements=1
resharper_blank_lines_before_multiline_statements=1
resharper_blank_lines_before_single_line_comment=1
resharper_csharp_align_multiline_argument=false
resharper_csharp_align_multiline_expression=false
resharper_csharp_align_multiline_parameter=true
resharper_csharp_align_multiple_declaration=false
resharper_csharp_indent_pars=outside
resharper_csharp_keep_blank_lines_in_code=1
resharper_csharp_keep_blank_lines_in_declarations=1
resharper_csharp_new_line_before_while=true
resharper_csharp_stick_comment=false
resharper_indent_invocation_pars=outside
resharper_indent_method_decl_pars=outside
resharper_indent_nested_foreach_stmt=true
resharper_indent_nested_for_stmt=true
resharper_indent_nested_while_stmt=true
resharper_indent_preprocessor_other=usual_indent
resharper_indent_statement_pars=outside
resharper_indent_typearg_angles=outside
resharper_indent_typeparam_angles=outside
resharper_keep_existing_declaration_parens_arrangement=false
resharper_keep_existing_expr_member_arrangement=false
resharper_align_first_arg_by_paren = false
resharper_align_linq_query = true
resharper_align_multiline_argument = true
resharper_align_multiline_array_and_object_initializer = false
resharper_align_multiline_binary_expressions_chain = false
resharper_align_multiline_calls_chain = false
resharper_align_multiline_expression = true
resharper_align_multiline_extends_list = true
resharper_align_multiline_for_stmt = false
resharper_align_multline_type_parameter_constrains = false
resharper_align_multline_type_parameter_list = false
resharper_align_tuple_components = false
resharper_blank_lines_after_control_transfer_statements = 1
resharper_blank_lines_before_single_line_comment = 1
resharper_csharp_align_multiline_argument = false
resharper_csharp_align_multiline_expression = false
resharper_csharp_align_multiline_parameter = true
resharper_csharp_align_multiple_declaration = false
resharper_csharp_indent_pars = outside
resharper_csharp_keep_blank_lines_in_code = 1
resharper_csharp_keep_blank_lines_in_declarations = 1
resharper_csharp_new_line_before_while = true
resharper_csharp_stick_comment = false
resharper_indent_invocation_pars = outside
resharper_indent_method_decl_pars = outside
resharper_indent_nested_foreach_stmt = true
resharper_indent_nested_for_stmt = true
resharper_indent_nested_while_stmt = true
resharper_indent_preprocessor_other = usual_indent
resharper_indent_statement_pars = outside
resharper_indent_typearg_angles = outside
resharper_indent_typeparam_angles = outside
resharper_keep_existing_declaration_parens_arrangement = false
resharper_keep_existing_expr_member_arrangement = false

resharper_space_within_single_line_array_initializer_braces = true

resharper_arguments_skip_single = true
resharper_blank_lines_after_multiline_statements = 1
resharper_blank_lines_before_block_statements = 0
resharper_blank_lines_before_control_transfer_statements = 0
resharper_blank_lines_before_multiline_statements = 0
resharper_csharp_max_line_length = 120
resharper_csharp_wrap_after_invocation_lpar = true
resharper_csharp_wrap_parameters_style = chop_if_long
resharper_parentheses_redundancy_style = remove

# CA1822: Mark members as static
# Changing public members to static would be a breaking change,
# so only run this test on private and internal members
dotnet_code_quality.CA1822.api_surface = private, internal
dotnet_code_quality.ca1822.api_surface = private, internal

# CA1024: Use properties where appropriate
dotnet_diagnostic.CA1024.severity = none
dotnet_diagnostic.ca1024.severity = none

# CA1027: Mark enums with FlagsAttribute
dotnet_diagnostic.CA1027.severity = none
dotnet_diagnostic.ca1027.severity = none

# CA1028: Enum storage should be Int32
dotnet_diagnostic.CA1028.severity = none
dotnet_diagnostic.ca1028.severity = none

# Not going to use LoggerMessage delegates.
dotnet_diagnostic.CA1848.severity = none
dotnet_diagnostic.ca1848.severity = none

# This is a .NET bug.
# https://github.com/dotnet/roslyn-analyzers/issues/5626
dotnet_diagnostic.CA2254.severity = none
dotnet_diagnostic.ca2254.severity = none

# This is a .NET bug.
# https://github.com/dotnet/roslyn-analyzers/issues/5479
dotnet_diagnostic.CA2101.severity = none
dotnet_diagnostic.ca2101.severity = none

# Hitting a weird CA1508 issue.
dotnet_diagnostic.CA1508.severity = none
dotnet_diagnostic.ca1508.severity = none

# CA2244: Redundant element initialization at index '''. Object initializer
# has another element initializer with the same index that overwrites this value
dotnet_diagnostic.CA2244.severity = none
dotnet_diagnostic.ca2244.severity = none

# CA2201: Exception type System.Exception is not sufficiently specific
dotnet_diagnostic.CA2201.severity = none
dotnet_diagnostic.ca2201.severity = none

# CA2208: Instantiate argument exceptions correctly
dotnet_diagnostic.CA2208.severity = none
dotnet_diagnostic.ca2208.severity = none

# CA1014: Mark assemblies with CLSCompliantAttribute
dotnet_diagnostic.CA1014.severity = none
dotnet_diagnostic.ca1014.severity = none

# CA2208: Instantiate argument exceptions correctly
dotnet_diagnostic.CA2208.severity = none
dotnet_diagnostic.ca2208.severity = none

#
# Test project rules
Expand All @@ -325,7 +334,7 @@ dotnet_diagnostic.CA2208.severity = none
[**/tests/**/*.cs]

# CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1707.severity = none
dotnet_diagnostic.ca1707.severity = none

#
# IntegrationTests project rules
Expand All @@ -334,7 +343,7 @@ dotnet_diagnostic.CA1707.severity = none
[**/integrationTests/**/*.cs]

# CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1707.severity = none
dotnet_diagnostic.ca1707.severity = none

#
# Examples project rules
Expand All @@ -343,4 +352,4 @@ dotnet_diagnostic.CA1707.severity = none
[**/examples/**/*.cs]

# CA1014: Mark assemblies with CLSCompliant
dotnet_diagnostic.CA1014.severity = none
dotnet_diagnostic.ca1014.severity = none
22 changes: 12 additions & 10 deletions Yubico.Core/tests/Yubico/Core/Devices/Hid/HidTranslatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class HidTranslatorTests
[InlineData(KeyboardLayout.sv_SE)]
public void GetHidCodes_GivenKeyboardLayout_ReturnsCorrectInstance(KeyboardLayout layout)
{
HidCodeTranslator hid = HidCodeTranslator.GetInstance(layout);
var hid = HidCodeTranslator.GetInstance(layout);
Assert.Equal(layout, hid.Layout);
}

Expand All @@ -46,7 +46,7 @@ public void GetHidCodes_GivenKeyboardLayout_ReturnsCorrectInstance(KeyboardLayou
[InlineData(KeyboardLayout.sv_SE, new byte[] { 0x9c, 0x18, 0x05, 0x0c, 0x06, 0x12, 0x9e })]
public void GetHidCodes_GivenString_ReturnsCorrectCodes(KeyboardLayout layout, byte[] expected)
{
HidCodeTranslator hid = HidCodeTranslator.GetInstance(layout);
var hid = HidCodeTranslator.GetInstance(layout);
string s = "Yubico!";
byte[] actual = hid.GetHidCodes(s);
Assert.Equal(expected, actual);
Expand All @@ -62,7 +62,7 @@ public void GetHidCodes_GivenString_ReturnsCorrectCodes(KeyboardLayout layout, b
[InlineData(KeyboardLayout.sv_SE, new byte[] { 0x9c, 0x18, 0x05, 0x0c, 0x06, 0x12, 0x9e })]
public void GetHidCodes_GivenCharArray_ReturnsCorrectCodes(KeyboardLayout layout, byte[] expected)
{
HidCodeTranslator hid = HidCodeTranslator.GetInstance(layout);
var hid = HidCodeTranslator.GetInstance(layout);
char[] s = { 'Y', 'u', 'b', 'i', 'c', 'o', '!' };
byte[] actual = hid.GetHidCodes(s);
Assert.Equal(expected, actual);
Expand All @@ -79,7 +79,7 @@ public void GetHidCodes_GivenCharArray_ReturnsCorrectCodes(KeyboardLayout layout
public void GetString_GivenHidCodes_ReturnsCorrectString(KeyboardLayout layout, byte[] input)
{
string expected = "Yubico!";
HidCodeTranslator hid = HidCodeTranslator.GetInstance(layout);
var hid = HidCodeTranslator.GetInstance(layout);
string actual = hid.GetString(input);
Assert.Equal(expected, actual);
}
Expand All @@ -97,8 +97,8 @@ public void TestSpecializedKeyboardSupportsModhexCodes(KeyboardLayout layout)
// Since ModHex is a subset of all supported keyboard layouts, this
// will confirm that all ModHex HID codes are the same in non-ModHex
// layouts.
HidCodeTranslator testHid = HidCodeTranslator.GetInstance(layout);
HidCodeTranslator modHexHid = HidCodeTranslator.GetInstance(KeyboardLayout.ModHex);
var testHid = HidCodeTranslator.GetInstance(layout);
var modHexHid = HidCodeTranslator.GetInstance(KeyboardLayout.ModHex);
foreach (byte code in modHexHid.SupportedHidCodes)
{
Assert.Equal(modHexHid[code], testHid[code]);
Expand All @@ -117,8 +117,8 @@ public void TestSpecializedKeyboardSupportsModhexChars(KeyboardLayout layout)
{
// Since ModHex is a subset of all keyboard layouts, this will confirm
// that all ModHex chars are the same in non-ModHex layouts.
HidCodeTranslator testHid = HidCodeTranslator.GetInstance(layout);
HidCodeTranslator modHexHid = HidCodeTranslator.GetInstance(KeyboardLayout.ModHex);
var testHid = HidCodeTranslator.GetInstance(layout);
var modHexHid = HidCodeTranslator.GetInstance(KeyboardLayout.ModHex);
foreach (char ch in modHexHid.SupportedCharacters)
{
Assert.Equal(modHexHid[ch], testHid[ch]);
Expand All @@ -137,23 +137,25 @@ public void TestSpecializedKeyboardSupportsModhexString(KeyboardLayout layout)
{
// Since ModHex is a subset of all keyboard layouts, this will confirm
// that all ModHex chars are the same in non-ModHex layouts.
HidCodeTranslator hid = HidCodeTranslator.GetInstance(KeyboardLayout.ModHex);
var hid = HidCodeTranslator.GetInstance(KeyboardLayout.ModHex);
byte[] modHexCodes = hid.SupportedHidCodes;
string decoded = HidCodeTranslator.GetInstance(layout).GetString(modHexCodes);
Assert.Equal(hid.SupportedCharactersString, decoded);
}

#if Windows
#pragma warning disable CA1825
[Theory]
[MemberData(nameof(GetTestData))]
public void GetChar_GivenHidCode_ReturnsCorrectChar(KeyboardLayout layout, (char, byte)[] testData)
{
HidCodeTranslator hid = HidCodeTranslator.GetInstance(layout);
var hid = HidCodeTranslator.GetInstance(layout);
foreach ((char ch, byte code) item in testData)
{
Assert.Equal(item.ch, hid[item.code]);
}
}
#pragma warning restore CA1825
#endif

public static IEnumerable<object[]> GetTestData()
Expand Down
4 changes: 2 additions & 2 deletions Yubico.YubiKey/src/Yubico/YubiKey/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public bool TryCreateConnection(
{
IHidDevice { UsagePage: HidUsagePage.Fido } d => new FidoConnection(d),
IHidDevice { UsagePage: HidUsagePage.Keyboard } d => new KeyboardConnection(d),
ISmartCardDevice d => new CcidConnection(d, application),
ISmartCardDevice d => new SmartCardConnection(d, application),
_ => throw new NotSupportedException(ExceptionMessages.DeviceTypeNotRecognized)
};

Expand Down Expand Up @@ -266,7 +266,7 @@ public bool TryCreateConnection(
return false;
}

connection = new CcidConnection(smartCardDevice, applicationId);
connection = new SmartCardConnection(smartCardDevice, applicationId);
_ = _openConnections.Add(yubiKeyDevice);
}
finally
Expand Down
1 change: 0 additions & 1 deletion Yubico.YubiKey/src/Yubico/YubiKey/FidoConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public TResponse SendCommand<TResponse>(IYubiKeyCommand<TResponse> yubiKeyComman
where TResponse : IYubiKeyResponse
{
CommandApdu commandApdu = yubiKeyCommand.CreateCommandApdu();

ResponseApdu responseApdu = _apduPipeline.Invoke(commandApdu, yubiKeyCommand.GetType(), typeof(TResponse));

return yubiKeyCommand.CreateResponseForApdu(responseApdu);
Expand Down
Loading