Skip to content

Commit

Permalink
pcsc: switch to bitflags 2
Browse files Browse the repository at this point in the history
bitflags releases a major version, but we use it in the public
interface, so upgrading is a breaking change. However, the bitflags
changelog provides guidance on how to keep 2 mostly compatible with 1:
https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md#200

This is not perfect, there is still some chance of breaking dependents,
but I think/hope it is OK. I think it's better than sticking with 1 only
or bumping pcsc major.

The MSRV is bumped to match bitflags.
  • Loading branch information
bluetech committed Dec 14, 2024
1 parent 3d0dd9b commit 0f5e1e4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
os: [ubuntu-22.04, windows-2022, macos-14]
toolchain: [stable]
include:
- {os: ubuntu-22.04, toolchain: '1.38.0'}
- {os: ubuntu-22.04, toolchain: '1.56.0'}
- {os: ubuntu-22.04, toolchain: beta}
- {os: ubuntu-22.04, toolchain: nightly}

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["pcsc", "pcsc-sys"]
resolver = "2"
4 changes: 2 additions & 2 deletions pcsc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ homepage = "https://github.com/bluetech/pcsc-rust"
authors = ["Ran Benita <ran@unusedvar.com>"]
build = "build.rs"
links = "pcsc"
rust-version = "1.38"
edition = "2018"
rust-version = "1.56"
edition = "2021"

[build-dependencies]
pkg-config = "0.3.9"
6 changes: 3 additions & 3 deletions pcsc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ repository = "https://github.com/bluetech/pcsc-rust"
homepage = "https://github.com/bluetech/pcsc-rust"
readme = "../README.md"
authors = ["Ran Benita <ran@unusedvar.com>"]
rust-version = "1.38"
edition = "2018"
rust-version = "1.56"
edition = "2021"

[dependencies]
bitflags = "1.2.1"
bitflags = "2"
pcsc-sys = { version = "1.2.0", path = "../pcsc-sys" }
28 changes: 28 additions & 0 deletions pcsc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ const DUMMY_DWORD: DWORD = 0xdead_beef;

bitflags! {
/// A mask of the state a card reader.
// Derives to keep backward compat with bitflags 1.
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
pub struct State: DWORD {
const UNAWARE = ffi::SCARD_STATE_UNAWARE;
const IGNORE = ffi::SCARD_STATE_IGNORE;
Expand All @@ -140,6 +142,14 @@ bitflags! {
}
}

// Backward compat with bitflags 1.
impl State {
#[deprecated = "use the safe `from_bits_retain` method instead"]
pub unsafe fn from_bits_unchecked(bits: DWORD) -> Self {
Self::from_bits_retain(bits)
}
}

bitflags! {
/// A mask of the status of a card in a card reader.
///
Expand All @@ -148,6 +158,8 @@ bitflags! {
/// On Windows, Status always has exactly one bit set, and the bit values do
/// not correspond to underlying PC/SC constants. This allows Status to be
/// used in the same way across all platforms.
// Derives to keep backward compat with bitflags 1.
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
pub struct Status: DWORD {
const UNKNOWN = {
#[cfg(not(target_os = "windows"))] { ffi::SCARD_UNKNOWN }
Expand Down Expand Up @@ -197,6 +209,12 @@ impl Status {
#[cfg(not(target_os = "windows"))]
Status::from_bits_truncate(raw_status)
}

// Backward compat with bitflags 1.
#[deprecated = "use the safe `from_bits_retain` method instead"]
pub unsafe fn from_bits_unchecked(bits: DWORD) -> Self {
Self::from_bits_retain(bits)
}
}

/// How a reader connection is shared.
Expand Down Expand Up @@ -239,6 +257,8 @@ impl Protocol {

bitflags! {
/// A mask of possible communication protocols.
// Derives to keep backward compat with bitflags 1.
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
pub struct Protocols: DWORD {
const UNDEFINED = ffi::SCARD_PROTOCOL_UNDEFINED;
const T0 = ffi::SCARD_PROTOCOL_T0;
Expand All @@ -248,6 +268,14 @@ bitflags! {
}
}

// Backward compat with bitflags 1.
impl Protocols {
#[deprecated = "use the safe `from_bits_retain` method instead"]
pub unsafe fn from_bits_unchecked(bits: DWORD) -> Self {
Self::from_bits_retain(bits)
}
}

/// Disposition method when disconnecting from a card reader.
#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down

0 comments on commit 0f5e1e4

Please sign in to comment.