Skip to content

Commit 8bc9da7

Browse files
authored
Merge pull request #20 from siketyan/fix-clippy
refactor: Fix clippy
2 parents 7d8d0cf + 3a4798e commit 8bc9da7

File tree

6 files changed

+38
-47
lines changed

6 files changed

+38
-47
lines changed

.github/workflows/rust.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111

1212
jobs:
1313
checks:
14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-22.04
1515
steps:
1616
- uses: actions/checkout@v2
1717
with:
@@ -33,24 +33,25 @@ jobs:
3333
components: rustfmt,clippy
3434

3535
- name: Install libpcsclite
36-
run: sudo apt install libudev-dev libpcsclite-dev
36+
run: sudo apt update && sudo apt install libudev-dev libpcsclite-dev
3737

3838
- name: Run clippy
3939
uses: actions-rs/clippy-check@v1
4040
with:
4141
token: ${{ secrets.GITHUB_TOKEN }}
42+
args: --workspace
4243

4344
- name: Run rustfmt
4445
uses: actions-rs/cargo@v1
4546
with:
4647
command: fmt
47-
args: -- --check
48+
args: --all --check
4849

4950
- name: Run tests
5051
uses: actions-rs/cargo@v1
5152
with:
5253
command: test
53-
args: --verbose
54+
args: --workspace --exclude jpki-android --verbose
5455

5556
build:
5657
needs:
@@ -76,16 +77,16 @@ jobs:
7677
cli: true
7778
android: false
7879
- target: x86_64-unknown-linux-gnu
79-
host: ubuntu-20.04
80+
host: ubuntu-22.04
8081
artifact: jpki-cli
8182
cli: true
8283
android: false
8384
- target: aarch64-linux-android
84-
host: ubuntu-20.04
85+
host: ubuntu-22.04
8586
cli: false
8687
android: true
8788
- target: armv7-linux-androideabi
88-
host: ubuntu-20.04
89+
host: ubuntu-22.04
8990
cli: false
9091
android: true
9192

@@ -111,8 +112,8 @@ jobs:
111112
target: ${{ matrix.target }}
112113

113114
- name: Install libpcsclite
114-
if: ${{ matrix.cli && matrix.host == 'ubuntu-20.04' }}
115-
run: sudo apt install libudev-dev libpcsclite-dev
115+
if: ${{ matrix.cli && startsWith(matrix.host, 'ubuntu-') }}
116+
run: sudo apt update && sudo apt install libudev-dev libpcsclite-dev
116117

117118
- name: Install Android NDK
118119
if: ${{ matrix.android }}
@@ -166,7 +167,7 @@ jobs:
166167
path: '.'
167168

168169
deploy:
169-
runs-on: ubuntu-20.04
170+
runs-on: ubuntu-22.04
170171
if: ${{ github.event_name == 'release' }}
171172
needs:
172173
- build
@@ -189,8 +190,8 @@ jobs:
189190
toolchain: stable
190191
override: true
191192

192-
- name: Install libnfc
193-
run: sudo apt install libnfc5 libnfc-dev udev libudev-dev pcscd libpcsclite-dev
193+
- name: Install libpcsclite
194+
run: sudo apt update && sudo apt install libudev-dev libpcsclite-dev
194195

195196
- name: Log into crates.io
196197
uses: actions-rs/cargo@v1

android/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::missing_safety_doc)]
2+
13
#[macro_use]
24
extern crate log;
35
extern crate android_log;

cli/src/main.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ enum Error {
2020
IO(#[from] std::io::Error),
2121

2222
#[error("Error occurred on communicating with NFC device: {0}")]
23-
NFC(#[from] nfc::Error),
23+
Nfc(#[from] nfc::Error),
2424

2525
#[error("The card returned an error: {0}")]
26-
APDU(#[from] jpki::nfc::apdu::Error),
26+
Apdu(#[from] jpki::nfc::apdu::Error),
2727
}
2828

2929
type Result<T> = std::result::Result<T, Error>;
@@ -52,15 +52,15 @@ enum CertType {
5252
AuthCA,
5353
}
5454

55-
impl Into<jpki_ap::CertType> for CertType {
56-
fn into(self) -> jpki_ap::CertType {
57-
use jpki_ap::CertType::*;
55+
impl From<CertType> for jpki_ap::CertType {
56+
fn from(ty: CertType) -> Self {
57+
use CertType::*;
5858

59-
match self {
60-
Self::Sign => Sign,
61-
Self::SignCA => SignCA,
62-
Self::Auth => Auth,
63-
Self::AuthCA => AuthCA,
59+
match ty {
60+
Sign => Self::Sign,
61+
SignCA => Self::SignCA,
62+
Auth => Self::Auth,
63+
AuthCA => Self::AuthCA,
6464
}
6565
}
6666
}
@@ -115,14 +115,14 @@ fn read_all<R: Read>(mut r: R) -> Result<Vec<u8>> {
115115
fn run() -> Result<()> {
116116
let cli: Cli = Cli::parse();
117117

118-
let ctx = Context::try_new().map_err(Error::NFC)?;
119-
let device = ctx.open().map_err(Error::NFC)?;
118+
let ctx = Context::try_new().map_err(Error::Nfc)?;
119+
let device = ctx.open().map_err(Error::Nfc)?;
120120
let initiator = Initiator::from(device);
121-
let target = initiator.select_dep_target(ctx).map_err(Error::NFC)?;
121+
let target = initiator.select_dep_target(ctx).map_err(Error::Nfc)?;
122122

123123
let nfc_card = NfcCard { target };
124124
let card = jpki::Card::new(Box::new(nfc_card));
125-
let jpki_ap = jpki::ap::JpkiAp::open((), Box::new(card)).map_err(Error::APDU)?;
125+
let jpki_ap = jpki::ap::JpkiAp::open((), Box::new(card)).map_err(Error::Apdu)?;
126126
match &cli.command {
127127
SubCommand::ReadCertificate { ty } => {
128128
let ty: jpki_ap::CertType = (*ty).into();
@@ -132,7 +132,7 @@ fn run() -> Result<()> {
132132
vec![]
133133
};
134134

135-
let certificate = jpki_ap.read_certificate((), ty, pin).map_err(Error::APDU)?;
135+
let certificate = jpki_ap.read_certificate((), ty, pin).map_err(Error::Apdu)?;
136136

137137
stdout().write_all(&certificate).map_err(Error::IO)?;
138138
}

cli/src/nfc.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ pub struct Initiator<'a> {
6363

6464
impl<'a> Initiator<'a> {
6565
pub fn select_dep_target(self, ctx: Context) -> Result<Target<'a>> {
66-
let reader = self.device.reader.clone();
67-
6866
Ok(Target::new(
6967
ctx.ctx
70-
.connect(&reader, ShareMode::Shared, Protocols::ANY)
68+
.connect(&self.device.reader, ShareMode::Shared, Protocols::ANY)
7169
.map_err(Error::PcscError)?,
7270
))
7371
}

src/jpki/ap/jpki.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ impl CertType {
4040

4141
/// Determines whether it is needed for fetching the certificate to unlock it with a PIN.
4242
pub fn is_pin_required(&self) -> bool {
43-
match self {
44-
Self::Sign => true,
45-
_ => false,
46-
}
43+
matches!(self, Self::Sign)
4744
}
4845
}
4946

@@ -110,7 +107,7 @@ where
110107
fn verify_pin(&self, ctx: Ctx, ef: [u8; 2], pin: Vec<u8>) -> Result<(), apdu::Error> {
111108
self.card
112109
.select_ef(ctx, ef.into())
113-
.and_then(|_| self.card.verify(ctx, pin.into()))
110+
.and_then(|_| self.card.verify(ctx, pin))
114111
}
115112

116113
fn read_certificate_size(&self, ctx: Ctx) -> Result<u16, apdu::Error> {

src/nfc/apdu/response.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::nfc::apdu::Error;
22

33
/// An response that was received from the card
4+
#[derive(Default)]
45
pub struct Response {
56
payload: Vec<u8>,
67
trailer: (u8, u8),
@@ -9,10 +10,7 @@ pub struct Response {
910
impl Response {
1011
/// Creates an empty response.
1112
pub fn new() -> Self {
12-
Self {
13-
payload: vec![],
14-
trailer: (0, 0),
15-
}
13+
Default::default()
1614
}
1715

1816
/// Parses a response from the octets.
@@ -31,10 +29,7 @@ impl Response {
3129

3230
/// Determines whether the response indicates success or not.
3331
pub fn is_ok(&self) -> bool {
34-
match self.trailer {
35-
(0x90, 0x00) | (0x91, 0x00) => true,
36-
_ => false,
37-
}
32+
matches!(self.trailer, (0x90, 0x00) | (0x91, 0x00))
3833
}
3934

4035
/// Converts the response to a result of octets.
@@ -49,10 +44,8 @@ impl Response {
4944
}
5045
}
5146

52-
impl Into<Error> for (u8, u8) {
53-
fn into(self) -> Error {
54-
let (sw1, sw2) = self;
55-
47+
impl From<(u8, u8)> for Error {
48+
fn from((sw1, sw2): (u8, u8)) -> Self {
5649
Error { sw1, sw2 }
5750
}
5851
}

0 commit comments

Comments
 (0)