Skip to content

Using PolySharp to allow use of C#13 #132

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 46 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2b71bc2
Remove PolyFills project.
DennisDyallo Jul 30, 2024
fffe147
Fix warnings
DennisDyallo Jul 30, 2024
d338850
Analysis warning
DennisDyallo Jul 30, 2024
e219573
C#12 Language refactors
DennisDyallo Jul 30, 2024
f51b5f1
Disable analysis on SampleProjects
DennisDyallo Jul 30, 2024
9729977
Merge branch 'develop' into dennisdyallo/polysharp
DennisDyallo Jul 30, 2024
687083e
Ignore warning on tests
DennisDyallo Jul 30, 2024
8a8d09f
Add .net6 to github setup for test project
DennisDyallo Jul 30, 2024
85a888e
Disable analysis on test-app
DennisDyallo Jul 30, 2024
9dd6ff8
fix merge conflicts
DennisDyallo Jan 11, 2025
4d1d89b
Updated PolySharp 1.15. LangVersion 13
DennisDyallo Jan 13, 2025
e14e62d
Visual Studio updated sln file
DennisDyallo Jan 13, 2025
2bf20a7
bump to .net9 in setup dotnet gh actions and globaljson
DennisDyallo Jan 13, 2025
9349b6f
misc: fix warnings
DennisDyallo Jan 13, 2025
a5ea782
misc: fix warnings
DennisDyallo Jan 13, 2025
f3d15f1
misc: fix warnings
DennisDyallo Jan 13, 2025
4172c71
Bump to .NET9 in sample and test projects
DennisDyallo Jan 13, 2025
7a7a3ff
tests: fix warnings
DennisDyallo Jan 13, 2025
4b8fcee
misc: SharedSampleProject
DennisDyallo Jan 13, 2025
cf10d92
Merge branch 'develop' into dennisdyallo/polysharp
DennisDyallo Feb 6, 2025
194397a
Merge branch 'develop' into dennisdyallo/polysharp
DennisDyallo Feb 6, 2025
082769c
refactor: remove obsolete Index and Range implementations
DennisDyallo Feb 7, 2025
7961f8b
refactor: use internal static classes CryptographicOperations
DennisDyallo Feb 13, 2025
e5cd2e7
refactor: change CryptographicOperations class from internal to publi…
DennisDyallo Feb 13, 2025
3dd3c82
misc: remove unused project DotnetPolyfills
DennisDyallo Feb 13, 2025
4b413c4
tests: add Microsoft.Bcl.Cryptography package reference and update ce…
DennisDyallo Feb 13, 2025
eb37476
Merge branch 'develop' into dennisdyallo/polysharp
DennisDyallo Feb 13, 2025
e949aa4
delete: remove CSharpLangFeaturesExamples class and related code
DennisDyallo Feb 13, 2025
b2eb647
docs: update README structure and improve section headings for clarity
DennisDyallo Feb 13, 2025
5e4628d
misc: run dotnet format
DennisDyallo Feb 13, 2025
3e46970
misc: specify type for readerStateList in CheckForUpdates method
DennisDyallo Feb 13, 2025
01fdf50
misc: move CryptographicOperations to System.Security.Cryptography an…
DennisDyallo Feb 13, 2025
447c03f
misc: update license references for CryptographicOperations and Rando…
DennisDyallo Feb 13, 2025
aafd2fe
misc: use var for readerStateList in CheckForUpdates method
DennisDyallo Feb 13, 2025
5638712
misc: inadvertent change regarding reverted (SdkPlatformInfo)
DennisDyallo Feb 13, 2025
020cef2
misc: enable implicit object creation when type is apparent (editorco…
DennisDyallo Feb 13, 2025
97a5c8a
misc: fix namespaces and minor things
DennisDyallo Feb 13, 2025
7e4d0fa
misc: prevent automatic updates for PolySharp package
DennisDyallo Feb 13, 2025
2d1ae97
misc: clean up code formatting and suppress string comparison warning…
DennisDyallo Feb 13, 2025
2b8a74e
misc: temporary disable code style warning
DennisDyallo Feb 13, 2025
25e1ceb
misc: add appsettings.json for unit tests configuration
DennisDyallo Feb 13, 2025
18acd83
misc: reorder PackageReference for Xunit.SkippableFact in unit tests …
DennisDyallo Feb 13, 2025
a49ec72
misc: remove references to Yubico.DotNetPolyfills and update document…
DennisDyallo Feb 13, 2025
85b35f0
misc: downgrade target framework from net9.0 to net8.0 in project files
DennisDyallo Feb 13, 2025
9563c41
misc: comment out listener creation tests in HidDeviceListenerTests a…
DennisDyallo Feb 13, 2025
8c4428c
Revert "misc: downgrade target framework from net9.0 to net8.0 in pro…
DennisDyallo Feb 13, 2025
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
11 changes: 9 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ resharper_csharp_wrap_parameters_style = chop_always
# C# files
[*.cs]

# Use concrete types when possible for improved performance
dotnet_diagnostic.CA1859.severity = suggestion

#### Core EditorConfig Options ####

# We can't do this until C# 9.
csharp_style_implicit_object_creation_when_type_is_apparent = false
csharp_style_implicit_object_creation_when_type_is_apparent = true

# Indentation and spacing
indent_size = 4
Expand Down Expand Up @@ -341,6 +343,9 @@ csharp_style_var_for_built_in_types = true:suggestion
csharp_style_unused_value_expression_statement_preference = unused_local_variable:none
resharper_for_simple_types = use_var

# CA1860: Avoid using 'Enumerable.Any()' extension method
dotnet_diagnostic.CA1860.severity = suggestion

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

Expand All @@ -362,3 +367,5 @@ dotnet_diagnostic.ca1014.severity = none
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = true:warning
dotnet_diagnostic.IDE0007.severity = none
dotnet_diagnostic.IDE0008.severity = none
2 changes: 0 additions & 2 deletions .github/workflows/build-pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ jobs:
with:
name: Nuget Packages ReleaseWithDocs
path: |
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/*.nupkg
Yubico.Core/src/bin/ReleaseWithDocs/*.nupkg
Yubico.YubiKey/src/bin/ReleaseWithDocs/*.nupkg

Expand All @@ -72,6 +71,5 @@ jobs:
with:
name: Assemblies ReleaseWithDocs
path: |
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/**/*.dll
Yubico.Core/src/bin/ReleaseWithDocs/**/*.dll
Yubico.YubiKey/src/bin/ReleaseWithDocs/**/*.dll
12 changes: 1 addition & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

global-json-file: "./global.json"
- name: Add local NuGet repository
run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json"

Expand All @@ -81,7 +80,6 @@ jobs:
run: |
$file = gci ./build/Versions.props
$versionProp = [xml](gc $file.FullName)
$versionProp.Project.PropertyGroup.YubicoDotNetPolyfillsVersion = "${{ github.event.inputs.version }}"
$versionProp.Project.PropertyGroup.YubicoCoreVersion = "${{ github.event.inputs.version }}"
$versionProp.Project.PropertyGroup.YubicoYubiKeyVersion = "${{ github.event.inputs.version }}"
$versionProp.Save($file.FullName)
Expand All @@ -102,7 +100,6 @@ jobs:
with:
name: Nuget Packages
path: |
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/*.nupkg
Yubico.Core/src/bin/ReleaseWithDocs/*.nupkg
Yubico.YubiKey/src/bin/ReleaseWithDocs/*.nupkg

Expand All @@ -111,7 +108,6 @@ jobs:
with:
name: Symbols Packages
path: |
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/*.snupkg
Yubico.Core/src/bin/ReleaseWithDocs/*.snupkg
Yubico.YubiKey/src/bin/ReleaseWithDocs/*.snupkg

Expand All @@ -120,21 +116,17 @@ jobs:
with:
name: Assemblies
path: |
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/**/*.dll
Yubico.Core/src/bin/ReleaseWithDocs/**/*.dll
Yubico.YubiKey/src/bin/ReleaseWithDocs/**/*.dll

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-path: |
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/*.nupkg
Yubico.Core/src/bin/ReleaseWithDocs/*.nupkg
Yubico.YubiKey/src/bin/ReleaseWithDocs/*.nupkg
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/*.snupkg
Yubico.Core/src/bin/ReleaseWithDocs/*.snupkg
Yubico.YubiKey/src/bin/ReleaseWithDocs/*.snupkg
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/**/*.dll
Yubico.Core/src/bin/ReleaseWithDocs/**/*.dll
Yubico.YubiKey/src/bin/ReleaseWithDocs/**/*.dll

Expand Down Expand Up @@ -179,10 +171,8 @@ jobs:
with:
name: Nuget Packages
- run: |
$polyfills = (Get-ChildItem -Recurse Yubico.DotnetPolyfills/*.nupkg)[0].FullName
$core = (Get-ChildItem -Recurse Yubico.Core/*.nupkg)[0].FullName
$yubikey = (Get-ChildItem -Recurse Yubico.YubiKey/*.nupkg)[0].FullName
dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json"
dotnet nuget push $polyfills --source "github" --api-key ${{ secrets.GITHUB_TOKEN }}
dotnet nuget push $core --source "github" --api-key ${{ secrets.GITHUB_TOKEN }}
dotnet nuget push $yubikey --source "github" --api-key ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
global-json-file: "./global.json"

- name: Add local NuGet repository
run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
global-json-file: "./global.json"

- name: Add local NuGet repository
run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
global-json-file: "./global.json"

- name: Add local NuGet repository
run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json"

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/verify-code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
global-json-file: "./global.json"

- name: Add local NuGet repository
run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json"
#- name: Build Yubico.NET.SDK.sln
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,5 @@ The following rules must be followed for PRs that include files from another pro
- The contribution is correctly attributed, as needed (generally in LICENSE.txt or NOTICE.txt in
project root).

See [CborTag.cs](./Yubico.DotNetPolyfills/src/System.Formats.Cbor/CborTag.cs) for an example of a
See [CryptographicOperations.cs](./Yubico.Core/src/System.Security.Cryptography/CryptographicOperations.cs) for an example of a
file copied from another project and attributed in the [LICENSE.txt](./LICENSE.txt) file.
33 changes: 1 addition & 32 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,41 +200,10 @@
See the License for the specific language governing permissions and
limitations under the License.



==================================================
The following license applies to
\Yubico.DotNetPolyfills\src\Contrib.Bcl.Ranges\Range.cs
\Yubico.DotNetPolyfills\src\Contrib.Bcl.Ranges\Index.cs

MIT License

Copyright (c) 2019 Stuart Lang
Copyright (c) .NET Foundation and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


==================================================
The following license applies to
\CONTRIBUTING.md
\Yubico.DotNetPolyfills\src\System.Security.Cryptography\CryptographicOperations.cs
\Yubico.Core\src\System.Security.Cryptography\CryptographicOperations.cs
\Yubico.YubiKey\src\Yubico\YubiKey\Cryptography\RandomNumberGeneratorExt.cs

The MIT License (MIT)
Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ limitations under the License. -->
Enterprise-grade cross-platform SDK for YubiKey integration, built on .NET.

## Table of Contents
- [Quick Start](#quick-start)
- [Documentation](#documentation)
- [SDK Support](#sdk-support)
- [SDK Packages](#sdk-packages)
- [Project Structure](#project-structure)
- [Contributing](#contributing)
- [Security](#security)
- [.NET YubiKey SDK](#net-yubikey-sdk)
- [Table of Contents](#table-of-contents)
- [Quick Start](#quick-start)
- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Documentation](#documentation)
- [SDK Support](#sdk-support)
- [SDK Packages](#sdk-packages)
- [Public Assemblies](#public-assemblies)
- [Yubico.YubiKey](#yubicoyubikey)
- [Yubico.Core](#yubicocore)
- [Internal Assemblies](#internal-assemblies)
- [Yubico.NativeShims](#yubiconativeshims)
- [Project Structure](#project-structure)
- [Contributing](#contributing)
- [Building the Project](#building-the-project)
- [Connect with us](#connect-with-us)

## Quick Start

Expand All @@ -44,7 +54,7 @@ dotnet add package Yubico.YubiKey
using Yubico.YubiKey;

// Chooses the first YubiKey found on the computer.
IYubiKeyDevice? SampleChooseYubiKey()
IYubiKeyDevice? GetFirstYubiKey()
{
IEnumerable<IYubiKeyDevice> list = YubiKeyDevice.FindAll();
return list.First();
Expand Down Expand Up @@ -83,10 +93,6 @@ Platform abstraction layer (PAL) providing:

### Internal Assemblies

#### Yubico.DotNetPolyfills
> ⚠️ **Not for public use**
> Backports BCL features needed by the SDK.

#### Yubico.NativeShims
> ⚠️ **Not for public use**
> 🔧 **Unmanaged Library**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using System.Runtime.CompilerServices;

#if !NETSTANDARD2_0
#if NETSTANDARD2_1_OR_GREATER
[assembly: TypeForwardedTo(typeof(System.Security.Cryptography.CryptographicOperations))]

#else
Expand Down
14 changes: 12 additions & 2 deletions Yubico.Core/src/Yubico.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,26 @@ limitations under the License. -->


<ItemGroup>
<PackageReference Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<!-- Before updating PolySharp, we should do some due dilligence on the update -->
<PackageReference Include="PolySharp" Version="1.15.0" AllowUpdates="false">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
<!-- The wildcard version tag allows us to include the latest minor and pre-release versions -->
<PackageReference Include="Yubico.NativeShims" Version="1.*-*" />
<ProjectReference Include="..\..\Yubico.DotNetPolyfills\src\Yubico.DotNetPolyfills.csproj" />
</ItemGroup>

<ItemGroup Label="Expose internal test hooks to Unit Test projects">
Expand Down
4 changes: 3 additions & 1 deletion Yubico.Core/src/Yubico/Core/Buffers/MultiString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace Yubico.Core.Buffers
/// </summary>
public static class MultiString
{
private static readonly char[] _separator = ['\0'];

/// <summary>
/// Converts the byte array representing a multi-null-terminated string and return them as
/// .NET strings.
Expand All @@ -40,7 +42,7 @@ public static string[] GetStrings(byte[] value, Encoding encoding)

return encoding
.GetString(value)
.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions Yubico.Core/src/Yubico/Core/Devices/Hid/WindowsHidDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ private void ResolveIdsFromInstancePath(string instancePath)
// 012345678901234567890123456789
// ^--- ^---

// Disable string comparison warning for this method as it needs to compile for both net47, netstandard 2.0 and 2.1
#pragma warning disable CA1862
if (instancePath.ToUpperInvariant().Contains("VID") && instancePath.ToUpperInvariant().Contains("HID"))
#pragma warning restore CA1862
{
// If this fails, vendorId will be 0.
_ = TryGetHexShort(instancePath, 12, 4, out ushort vendorId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private void ListenForReaderChanges()
#region IDisposable Support

private bool _disposedValue; // To detect redundant calls
internal static readonly string[] readerNames = new[] { "\\\\?\\Pnp\\Notifications" };

/// <summary>
/// Disposes the objects.
Expand Down Expand Up @@ -192,7 +193,7 @@ private bool CheckForUpdates(int timeout, bool usePnpWorkaround)
SCARD_READER_STATE[] removedReaderStates = newStates.Except(eventStateList, new ReaderStateComparer()).ToArray();

// Don't get status changes if there are no updates in state list.
if (!addedReaderStates.Any() && !removedReaderStates.Any())
if (addedReaderStates.Length == 0 && removedReaderStates.Length == 0)
{
break;
}
Expand All @@ -214,7 +215,7 @@ private bool CheckForUpdates(int timeout, bool usePnpWorkaround)
// Only call get status change if a new reader was added. If nothing was added,
// we would otherwise hang / timeout here because all changes (in SCard's mind)
// have been dealt with.
if (addedReaderStates.Any())
if (addedReaderStates.Length != 0)
{
_log.LogInformation("Additional smart card readers were found. Calling GetStatusChange for more information.");
getStatusChangeResult = SCardGetStatusChange(_context, 0, updatedStates, updatedStates.Length);
Expand Down Expand Up @@ -280,7 +281,7 @@ private bool CheckForUpdates(int timeout, bool usePnpWorkaround)
// us of the change.
private bool UsePnpWorkaround()
{
SCARD_READER_STATE[] testState = SCARD_READER_STATE.CreateFromReaderNames(new[] { "\\\\?\\Pnp\\Notifications" });
SCARD_READER_STATE[] testState = SCARD_READER_STATE.CreateFromReaderNames(readerNames);
_ = SCardGetStatusChange(_context, 0, testState, testState.Length);
bool usePnpWorkaround = testState[0].EventState.HasFlag(SCARD_STATE.UNKNOWN);
return usePnpWorkaround;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal struct SCARD_IO_REQUEST
public SCARD_IO_REQUEST(SCARD_PROTOCOL protocol)
{
Protocol = protocol;
PciLength = Marshal.SizeOf(typeof(SCARD_IO_REQUEST));
PciLength = Marshal.SizeOf<SCARD_IO_REQUEST>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,24 @@ namespace Yubico.PlatformInterop
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
// Justification: Fields are read/write via interop. Readonly might not have any effect there, but it may give
// maintainers a falls impression about the true nature of these fields.
// maintainers a false impression about the true nature of these fields.
[SuppressMessage("ReSharper", "FieldCanBeMadeReadOnly.Local")]
[SuppressMessage("Style", "IDE0044:Add readonly modifier")]
internal struct SCARD_READER_STATE
{
[MarshalAs(UnmanagedType.LPStr)]
private string _readerName;
private IntPtr _userData;
private uint _currentState;
private uint _eventState;
private uint _atrLength;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 36)]
private byte[] _answerToReset;

private const uint SequenceMask = 0xFFFF_0000;
private const uint StateMask = 0x0000_FFFF;

public string ReaderName
{
get => _readerName;
set => _readerName = value;
}
[field: MarshalAs(UnmanagedType.LPStr)]
public string ReaderName { get; set; }

public SCARD_STATE CurrentState => (SCARD_STATE)(_currentState & StateMask);
public SCARD_STATE EventState => (SCARD_STATE)(_eventState & StateMask);
Expand Down
Loading
Loading