Skip to content
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

pcsc: switch to bitflags 2 #58

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 <[email protected]>"]
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 <[email protected]>"]
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