1 | // Copyright (c) 2018, Yubico AB | |
2 | // All rights reserved. | |
3 | // | |
4 | // Redistribution and use in source and binary forms, with or without | |
5 | // modification, are permitted provided that the following conditions are met: | |
6 | // | |
7 | // 1. Redistributions of source code must retain the above copyright notice, this | |
8 | // list of conditions and the following disclaimer. | |
9 | // | |
10 | // 2. Redistributions in binary form must reproduce the above copyright notice, | |
11 | // this list of conditions and the following disclaimer in the documentation | |
12 | // and/or other materials provided with the distribution. | |
13 | // | |
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
18 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
19 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
20 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
21 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
22 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | ||
25 | package com.yubico.webauthn.data; | |
26 | ||
27 | import com.fasterxml.jackson.annotation.JsonCreator; | |
28 | import com.fasterxml.jackson.annotation.JsonValue; | |
29 | import java.util.stream.Stream; | |
30 | import lombok.AccessLevel; | |
31 | import lombok.AllArgsConstructor; | |
32 | import lombok.NonNull; | |
33 | import lombok.Value; | |
34 | ||
35 | /** | |
36 | * Authenticators may communicate with Clients using a variety of transports. This enumeration | |
37 | * defines a hint as to how Clients might communicate with a particular Authenticator in order to | |
38 | * obtain an assertion for a specific credential. Note that these hints represent the Relying | |
39 | * Party's best belief as to how an Authenticator may be reached. A Relying Party may obtain a list | |
40 | * of transports hints from some attestation statement formats or via some out-of-band mechanism; it | |
41 | * is outside the scope of this specification to define that mechanism. | |
42 | * | |
43 | * <p>Authenticators may implement various transports for communicating with clients. This | |
44 | * enumeration defines hints as to how clients might communicate with a particular authenticator in | |
45 | * order to obtain an assertion for a specific credential. Note that these hints represent the | |
46 | * WebAuthn Relying Party's best belief as to how an authenticator may be reached. A Relying Party | |
47 | * may obtain a list of transports hints from some attestation statement formats or via some | |
48 | * out-of-band mechanism; it is outside the scope of the Web Authentication specification to define | |
49 | * that mechanism. | |
50 | * | |
51 | * @see <a | |
52 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enumdef-authenticatortransport">§5.10.4. | |
53 | * Authenticator Transport Enumeration (enum AuthenticatorTransport)</a> | |
54 | */ | |
55 | @Value | |
56 | @AllArgsConstructor(access = AccessLevel.PRIVATE) | |
57 | public class AuthenticatorTransport implements Comparable<AuthenticatorTransport> { | |
58 | ||
59 | @JsonValue @NonNull private final String id; | |
60 | ||
61 | /** | |
62 | * Indicates the respective authenticator can be contacted over removable USB. | |
63 | * | |
64 | * @see <a | |
65 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dom-authenticatortransport-usb">5.8.4. | |
66 | * Authenticator Transport Enumeration (enum AuthenticatorTransport)</a> | |
67 | */ | |
68 | public static final AuthenticatorTransport USB = new AuthenticatorTransport("usb"); | |
69 | ||
70 | /** | |
71 | * Indicates the respective authenticator can be contacted over Near Field Communication (NFC). | |
72 | * | |
73 | * @see <a | |
74 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dom-authenticatortransport-nfc">5.8.4. | |
75 | * Authenticator Transport Enumeration (enum AuthenticatorTransport)</a> | |
76 | */ | |
77 | public static final AuthenticatorTransport NFC = new AuthenticatorTransport("nfc"); | |
78 | ||
79 | /** | |
80 | * Indicates the respective authenticator can be contacted over Bluetooth Smart (Bluetooth Low | |
81 | * Energy / BLE). | |
82 | * | |
83 | * @see <a | |
84 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dom-authenticatortransport-ble">5.8.4. | |
85 | * Authenticator Transport Enumeration (enum AuthenticatorTransport)</a> | |
86 | */ | |
87 | public static final AuthenticatorTransport BLE = new AuthenticatorTransport("ble"); | |
88 | ||
89 | /** | |
90 | * Indicates the respective authenticator can be contacted using a combination of (often separate) | |
91 | * data-transport and proximity mechanisms. This supports, for example, authentication on a | |
92 | * desktop computer using a smartphone. | |
93 | * | |
94 | * @deprecated EXPERIMENTAL: This feature is from a not yet mature standard; it could change as | |
95 | * the standard matures. | |
96 | * @see <a href="https://w3c.github.io/webauthn/#dom-authenticatortransport-hybrid">5.8.4. | |
97 | * Authenticator Transport Enumeration (enum AuthenticatorTransport)</a> | |
98 | */ | |
99 | @Deprecated | |
100 | public static final AuthenticatorTransport HYBRID = new AuthenticatorTransport("hybrid"); | |
101 | ||
102 | /** | |
103 | * Indicates the respective authenticator is contacted using a client device-specific transport. | |
104 | * These authenticators are not removable from the client device. | |
105 | * | |
106 | * @see <a | |
107 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dom-authenticatortransport-internal">5.8.4. | |
108 | * Authenticator Transport Enumeration (enum AuthenticatorTransport)</a> | |
109 | */ | |
110 | public static final AuthenticatorTransport INTERNAL = new AuthenticatorTransport("internal"); | |
111 | ||
112 | /** | |
113 | * @return An array containing all predefined values of {@link AuthenticatorTransport} known by | |
114 | * this implementation. | |
115 | */ | |
116 | public static AuthenticatorTransport[] values() { | |
117 |
1
1. values : replaced return value with null for com/yubico/webauthn/data/AuthenticatorTransport::values → KILLED |
return new AuthenticatorTransport[] {USB, NFC, BLE, HYBRID, INTERNAL}; |
118 | } | |
119 | ||
120 | /** | |
121 | * @return If <code>id</code> is the same as that of any of {@link #USB}, {@link #NFC}, {@link | |
122 | * #BLE}, {@link #HYBRID} or {@link #INTERNAL}, returns that constant instance. Otherwise | |
123 | * returns a new instance containing <code>id</code>. | |
124 | * @see #valueOf(String) | |
125 | */ | |
126 | @JsonCreator | |
127 |
1
1. of : negated conditional → KILLED |
public static AuthenticatorTransport of(@NonNull String id) { |
128 |
1
1. of : replaced return value with null for com/yubico/webauthn/data/AuthenticatorTransport::of → KILLED |
return Stream.of(values()) |
129 |
2
1. lambda$of$0 : replaced boolean return with false for com/yubico/webauthn/data/AuthenticatorTransport::lambda$of$0 → KILLED 2. lambda$of$0 : replaced boolean return with true for com/yubico/webauthn/data/AuthenticatorTransport::lambda$of$0 → KILLED |
.filter(v -> v.getId().equals(id)) |
130 | .findAny() | |
131 |
1
1. lambda$of$1 : replaced return value with null for com/yubico/webauthn/data/AuthenticatorTransport::lambda$of$1 → KILLED |
.orElseGet(() -> new AuthenticatorTransport(id)); |
132 | } | |
133 | ||
134 | /** | |
135 | * @return If <code>name</code> equals <code>"USB"</code>, <code>"NFC"</code>, <code>"BLE"</code>, | |
136 | * <code>"HYBRID"</code> or <code>"INTERNAL"</code>, returns the constant by that name. | |
137 | * @throws IllegalArgumentException if <code>name</code> is anything else. | |
138 | * @see #of(String) | |
139 | */ | |
140 | public static AuthenticatorTransport valueOf(String name) { | |
141 | switch (name) { | |
142 | case "USB": | |
143 |
1
1. valueOf : replaced return value with null for com/yubico/webauthn/data/AuthenticatorTransport::valueOf → KILLED |
return USB; |
144 | case "NFC": | |
145 |
1
1. valueOf : replaced return value with null for com/yubico/webauthn/data/AuthenticatorTransport::valueOf → KILLED |
return NFC; |
146 | case "BLE": | |
147 |
1
1. valueOf : replaced return value with null for com/yubico/webauthn/data/AuthenticatorTransport::valueOf → KILLED |
return BLE; |
148 | case "HYBRID": | |
149 |
1
1. valueOf : replaced return value with null for com/yubico/webauthn/data/AuthenticatorTransport::valueOf → KILLED |
return HYBRID; |
150 | case "INTERNAL": | |
151 |
1
1. valueOf : replaced return value with null for com/yubico/webauthn/data/AuthenticatorTransport::valueOf → KILLED |
return INTERNAL; |
152 | default: | |
153 | throw new IllegalArgumentException( | |
154 | "No constant com.yubico.webauthn.data.AuthenticatorTransport." + name); | |
155 | } | |
156 | } | |
157 | ||
158 | @Override | |
159 | public int compareTo(AuthenticatorTransport other) { | |
160 |
1
1. compareTo : replaced int return with 0 for com/yubico/webauthn/data/AuthenticatorTransport::compareTo → KILLED |
return id.compareTo(other.id); |
161 | } | |
162 | } | |
Mutations | ||
117 |
1.1 |
|
127 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 2.2 |
|
131 |
1.1 |
|
143 |
1.1 |
|
145 |
1.1 |
|
147 |
1.1 |
|
149 |
1.1 |
|
151 |
1.1 |
|
160 |
1.1 |