Skip to content

Commit 061076d

Browse files
committed
Merge PR #162
2 parents 196304e + cbbcecb commit 061076d

File tree

388 files changed

+32514
-31944
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

388 files changed

+32514
-31944
lines changed

.github/workflows/android.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v4
12-
- name: set up JDK
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
with:
14+
ref: ${{ github.event.workflow_run.head_branch }}
15+
16+
- name: Set up JDK
1317
uses: actions/setup-java@v4
1418
with:
1519
distribution: 'temurin'
1620
java-version: '17'
1721

22+
- name: Verify code format
23+
run: ./gradlew spotlessCheck
24+
1825
- name: Build with Gradle
1926
run: NO_GPG_SIGN=true ./gradlew --stacktrace check test build javadocJar publishToMavenLocal
2027

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: spotless
5+
name: reformat Java
6+
language: script
7+
entry: scripts/spotless.py
8+
always_run: true

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id 'com.android.library'
33
id 'project-convention-spotbugs'
44
id 'project-convention-logging'
5+
id 'project-convention-spotless'
56
}
67

78
android {

android/src/androidTest/java/com/yubico/yubikit/android/ExampleInstrumentedTest.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,25 @@
1616

1717
package com.yubico.yubikit.android;
1818

19-
import android.content.Context;
19+
import static org.junit.Assert.assertEquals;
2020

21-
import androidx.test.platform.app.InstrumentationRegistry;
21+
import android.content.Context;
2222
import androidx.test.ext.junit.runners.AndroidJUnit4;
23-
23+
import androidx.test.platform.app.InstrumentationRegistry;
2424
import org.junit.Test;
2525
import org.junit.runner.RunWith;
2626

27-
import static org.junit.Assert.assertEquals;
28-
2927
/**
3028
* Instrumented test, which will execute on an Android device.
3129
*
3230
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
3331
*/
3432
@RunWith(AndroidJUnit4.class)
3533
public class ExampleInstrumentedTest {
36-
@Test
37-
public void useAppContext() {
38-
// Context of the app under test.
39-
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
40-
assertEquals("com.yubico.yubikit.android.test", appContext.getPackageName());
41-
}
42-
}
34+
@Test
35+
public void useAppContext() {
36+
// Context of the app under test.
37+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
38+
assertEquals("com.yubico.yubikit.android.test", appContext.getPackageName());
39+
}
40+
}

android/src/main/java/com/yubico/yubikit/android/YubiKitManager.java

Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import android.app.Activity;
2020
import android.content.Context;
21-
2221
import com.yubico.yubikit.android.transport.nfc.NfcConfiguration;
2322
import com.yubico.yubikit.android.transport.nfc.NfcNotAvailable;
2423
import com.yubico.yubikit.android.transport.nfc.NfcYubiKeyDevice;
@@ -27,96 +26,100 @@
2726
import com.yubico.yubikit.android.transport.usb.UsbYubiKeyDevice;
2827
import com.yubico.yubikit.android.transport.usb.UsbYubiKeyManager;
2928
import com.yubico.yubikit.core.util.Callback;
30-
3129
import javax.annotation.Nullable;
3230

3331
/**
34-
* Starting point for YubiKey device discovery over both USB and NFC.
35-
* Use this class to listen for YubiKeys and get a {@link com.yubico.yubikit.core.YubiKeyDevice} reference.
32+
* Starting point for YubiKey device discovery over both USB and NFC. Use this class to listen for
33+
* YubiKeys and get a {@link com.yubico.yubikit.core.YubiKeyDevice} reference.
3634
*/
3735
public final class YubiKitManager {
38-
private final UsbYubiKeyManager usbYubiKeyManager;
39-
@Nullable
40-
private final NfcYubiKeyManager nfcYubiKeyManager;
36+
private final UsbYubiKeyManager usbYubiKeyManager;
37+
@Nullable private final NfcYubiKeyManager nfcYubiKeyManager;
4138

42-
@Nullable
43-
private static NfcYubiKeyManager buildNfcDeviceManager(Context context) {
44-
try {
45-
return new NfcYubiKeyManager(context, null);
46-
} catch (NfcNotAvailable e) {
47-
return null;
48-
}
39+
@Nullable
40+
private static NfcYubiKeyManager buildNfcDeviceManager(Context context) {
41+
try {
42+
return new NfcYubiKeyManager(context, null);
43+
} catch (NfcNotAvailable e) {
44+
return null;
4945
}
46+
}
5047

51-
/**
52-
* Initialize instance of {@link YubiKitManager}
53-
*
54-
* @param context application context
55-
*/
56-
public YubiKitManager(Context context) {
57-
this(new UsbYubiKeyManager(context.getApplicationContext()), buildNfcDeviceManager(context.getApplicationContext()));
58-
}
48+
/**
49+
* Initialize instance of {@link YubiKitManager}
50+
*
51+
* @param context application context
52+
*/
53+
public YubiKitManager(Context context) {
54+
this(
55+
new UsbYubiKeyManager(context.getApplicationContext()),
56+
buildNfcDeviceManager(context.getApplicationContext()));
57+
}
5958

60-
/**
61-
* Initialize an instance of {@link YubiKitManager}, providing the USB and NFC YubiKey managers to use for device discovery.
62-
*
63-
* @param usbYubiKeyManager UsbYubiKeyManager instance to use for USB communication
64-
* @param nfcYubiKeyManager NfcYubiKeyManager instance to use for NFC communication
65-
*/
66-
public YubiKitManager(UsbYubiKeyManager usbYubiKeyManager, @Nullable NfcYubiKeyManager nfcYubiKeyManager) {
67-
this.usbYubiKeyManager = usbYubiKeyManager;
68-
this.nfcYubiKeyManager = nfcYubiKeyManager;
69-
}
59+
/**
60+
* Initialize an instance of {@link YubiKitManager}, providing the USB and NFC YubiKey managers to
61+
* use for device discovery.
62+
*
63+
* @param usbYubiKeyManager UsbYubiKeyManager instance to use for USB communication
64+
* @param nfcYubiKeyManager NfcYubiKeyManager instance to use for NFC communication
65+
*/
66+
public YubiKitManager(
67+
UsbYubiKeyManager usbYubiKeyManager, @Nullable NfcYubiKeyManager nfcYubiKeyManager) {
68+
this.usbYubiKeyManager = usbYubiKeyManager;
69+
this.nfcYubiKeyManager = nfcYubiKeyManager;
70+
}
7071

72+
/**
73+
* Subscribe on changes that happen via USB and detect if there any Yubikeys got connected
74+
*
75+
* <p>This registers broadcast receivers, to unsubscribe from receiver use {@link
76+
* YubiKitManager#stopUsbDiscovery()}
77+
*
78+
* @param usbConfiguration additional configurations on how USB discovery should be handled
79+
* @param listener listener that is going to be invoked upon successful discovery of key session
80+
* or failure to detect any session (lack of permissions)
81+
*/
82+
public void startUsbDiscovery(
83+
final UsbConfiguration usbConfiguration, Callback<? super UsbYubiKeyDevice> listener) {
84+
usbYubiKeyManager.enable(usbConfiguration, listener);
85+
}
7186

72-
/**
73-
* Subscribe on changes that happen via USB and detect if there any Yubikeys got connected
74-
* <p>
75-
* This registers broadcast receivers, to unsubscribe from receiver use {@link YubiKitManager#stopUsbDiscovery()}
76-
*
77-
* @param usbConfiguration additional configurations on how USB discovery should be handled
78-
* @param listener listener that is going to be invoked upon successful discovery of key session
79-
* or failure to detect any session (lack of permissions)
80-
*/
81-
public void startUsbDiscovery(final UsbConfiguration usbConfiguration, Callback<? super UsbYubiKeyDevice> listener) {
82-
usbYubiKeyManager.enable(usbConfiguration, listener);
87+
/**
88+
* Subscribe on changes that happen via NFC and detect if there any Yubikeys tags got passed
89+
*
90+
* <p>This registers broadcast receivers and blocks Ndef tags to be passed to activity, to
91+
* unsubscribe use {@link YubiKitManager#stopNfcDiscovery(Activity)}
92+
*
93+
* @param nfcConfiguration additional configurations on how NFC discovery should be handled
94+
* @param listener listener that is going to be invoked upon successful discovery of YubiKeys or
95+
* failure to detect any device (setting if off or no nfc adapter on device)
96+
* @param activity active (not finished) activity required for nfc foreground dispatch
97+
* @throws NfcNotAvailable in case if NFC not available on android device
98+
*/
99+
public void startNfcDiscovery(
100+
final NfcConfiguration nfcConfiguration,
101+
Activity activity,
102+
Callback<? super NfcYubiKeyDevice> listener)
103+
throws NfcNotAvailable {
104+
if (nfcYubiKeyManager == null) {
105+
throw new NfcNotAvailable("NFC is not available on this device", false);
83106
}
107+
nfcYubiKeyManager.enable(activity, nfcConfiguration, listener);
108+
}
84109

85-
/**
86-
* Subscribe on changes that happen via NFC and detect if there any Yubikeys tags got passed
87-
* <p>
88-
* This registers broadcast receivers and blocks Ndef tags to be passed to activity,
89-
* to unsubscribe use {@link YubiKitManager#stopNfcDiscovery(Activity)}
90-
*
91-
* @param nfcConfiguration additional configurations on how NFC discovery should be handled
92-
* @param listener listener that is going to be invoked upon successful discovery of YubiKeys
93-
* or failure to detect any device (setting if off or no nfc adapter on device)
94-
* @param activity active (not finished) activity required for nfc foreground dispatch
95-
* @throws NfcNotAvailable in case if NFC not available on android device
96-
*/
97-
public void startNfcDiscovery(final NfcConfiguration nfcConfiguration, Activity activity, Callback<? super NfcYubiKeyDevice> listener)
98-
throws NfcNotAvailable {
99-
if (nfcYubiKeyManager == null) {
100-
throw new NfcNotAvailable("NFC is not available on this device", false);
101-
}
102-
nfcYubiKeyManager.enable(activity, nfcConfiguration, listener);
103-
}
104-
105-
/**
106-
* Unsubscribe from changes that happen via USB
107-
*/
108-
public void stopUsbDiscovery() {
109-
usbYubiKeyManager.disable();
110-
}
110+
/** Unsubscribe from changes that happen via USB */
111+
public void stopUsbDiscovery() {
112+
usbYubiKeyManager.disable();
113+
}
111114

112-
/**
113-
* Unsubscribe from changes that happen via NFC
114-
*
115-
* @param activity active (not finished) activity required for nfc foreground dispatch
116-
*/
117-
public void stopNfcDiscovery(Activity activity) {
118-
if (nfcYubiKeyManager != null) {
119-
nfcYubiKeyManager.disable(activity);
120-
}
115+
/**
116+
* Unsubscribe from changes that happen via NFC
117+
*
118+
* @param activity active (not finished) activity required for nfc foreground dispatch
119+
*/
120+
public void stopNfcDiscovery(Activity activity) {
121+
if (nfcYubiKeyManager != null) {
122+
nfcYubiKeyManager.disable(activity);
121123
}
124+
}
122125
}

android/src/main/java/com/yubico/yubikit/android/internal/Base64CodecImpl.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,23 @@
2020

2121
public class Base64CodecImpl implements com.yubico.yubikit.core.internal.codec.Base64Codec {
2222

23-
@Override
24-
public String toUrlSafeString(byte[] data) {
25-
return Base64.encodeToString(data, Base64.NO_WRAP | Base64.NO_PADDING | Base64.URL_SAFE);
26-
}
27-
28-
@Override
29-
public String toString(byte[] data) {
30-
return Base64.encodeToString(data, Base64.NO_WRAP | Base64.NO_PADDING);
31-
}
32-
33-
@Override
34-
public byte[] fromUrlSafeString(String data) {
35-
return Base64.decode(data, Base64.NO_WRAP | Base64.NO_PADDING | Base64.URL_SAFE);
36-
}
37-
38-
@Override
39-
public byte[] fromString(String data) {
40-
return Base64.decode(data, Base64.NO_WRAP | Base64.NO_PADDING);
41-
}
23+
@Override
24+
public String toUrlSafeString(byte[] data) {
25+
return Base64.encodeToString(data, Base64.NO_WRAP | Base64.NO_PADDING | Base64.URL_SAFE);
26+
}
27+
28+
@Override
29+
public String toString(byte[] data) {
30+
return Base64.encodeToString(data, Base64.NO_WRAP | Base64.NO_PADDING);
31+
}
32+
33+
@Override
34+
public byte[] fromUrlSafeString(String data) {
35+
return Base64.decode(data, Base64.NO_WRAP | Base64.NO_PADDING | Base64.URL_SAFE);
36+
}
37+
38+
@Override
39+
public byte[] fromString(String data) {
40+
return Base64.decode(data, Base64.NO_WRAP | Base64.NO_PADDING);
41+
}
4242
}
43-

android/src/main/java/com/yubico/yubikit/android/internal/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
@PackageNonnullByDefault
1818
package com.yubico.yubikit.android.internal;
1919

20-
import com.yubico.yubikit.core.PackageNonnullByDefault;
20+
import com.yubico.yubikit.core.PackageNonnullByDefault;

android/src/main/java/com/yubico/yubikit/android/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
@PackageNonnullByDefault
1717
package com.yubico.yubikit.android;
1818

19-
import com.yubico.yubikit.core.PackageNonnullByDefault;
19+
import com.yubico.yubikit.core.PackageNonnullByDefault;

0 commit comments

Comments
 (0)