ResidentKeyRequirement.java

1
// Copyright (c) 2021, 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.Optional;
30
import java.util.stream.Stream;
31
import lombok.AllArgsConstructor;
32
import lombok.Getter;
33
import lombok.NonNull;
34
35
/**
36
 * This enumeration's values describe the Relying Party's requirements for client-side discoverable
37
 * credentials, also known as <i>passkeys</i> (formerly known as resident credentials or resident
38
 * keys).
39
 *
40
 * @see <a
41
 *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-residentKeyRequirement">§5.4.6.
42
 *     Resident Key Requirement Enumeration (enum ResidentKeyRequirement)</a>
43
 * @see <a
44
 *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-credential">Client-side
45
 *     discoverable Credential</a>
46
 * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a
47
 *     href="https://passkeys.dev">passkeys.dev</a> reference
48
 */
49
@AllArgsConstructor
50
public enum ResidentKeyRequirement {
51
52
  /**
53
   * The client and authenticator will try to create a server-side credential if possible, and a
54
   * discoverable credential (passkey) otherwise.
55
   *
56
   * @see <a
57
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-residentKeyRequirement">§5.4.6.
58
   *     Resident Key Requirement Enumeration (enum ResidentKeyRequirement)</a>
59
   * @see <a
60
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-credential">Client-side
61
   *     discoverable Credential</a>
62
   * @see <a
63
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#server-side-credential">Server-side
64
   *     Credential</a>
65
   * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a
66
   *     href="https://passkeys.dev">passkeys.dev</a> reference
67
   */
68
  DISCOURAGED("discouraged"),
69
70
  /**
71
   * The client and authenticator will try to create a discoverable credential (passkey) if
72
   * possible, and a server-side credential otherwise.
73
   *
74
   * @see <a
75
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-residentKeyRequirement">§5.4.6.
76
   *     Resident Key Requirement Enumeration (enum ResidentKeyRequirement)</a>
77
   * @see <a
78
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-credential">Client-side
79
   *     discoverable Credential</a>
80
   * @see <a
81
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#server-side-credential">Server-side
82
   *     Credential</a>
83
   * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a
84
   *     href="https://passkeys.dev">passkeys.dev</a> reference
85
   */
86
  PREFERRED("preferred"),
87
88
  /**
89
   * The client and authenticator will try to create a discoverable credential (passkey), and fail
90
   * the registration if that is not possible.
91
   *
92
   * @see <a
93
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-residentKeyRequirement">§5.4.6.
94
   *     Resident Key Requirement Enumeration (enum ResidentKeyRequirement)</a>
95
   * @see <a
96
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-credential">Client-side
97
   *     discoverable Credential</a>
98
   * @see <a
99
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#server-side-credential">Server-side
100
   *     Credential</a>
101
   * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a
102
   *     href="https://passkeys.dev">passkeys.dev</a> reference
103
   */
104
  REQUIRED("required");
105
106
  @JsonValue @Getter @NonNull private final String value;
107
108
  /**
109
   * Attempt to parse a string as a {@link ResidentKeyRequirement}.
110
   *
111
   * @param value a {@link String} equal to the {@link #getValue() value} of a constant in {@link
112
   *     ResidentKeyRequirement}
113
   * @return The {@link ResidentKeyRequirement} instance whose {@link #getValue() value} equals
114
   *     <code>value</code>, if any.
115
   * @see <a
116
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-residentKeyRequirement">§5.4.6.
117
   *     Resident Key Requirement Enumeration (enum ResidentKeyRequirement)</a>
118
   */
119 1 1. fromValue : negated conditional → KILLED
  public static Optional<ResidentKeyRequirement> fromValue(@NonNull String value) {
120 3 1. fromValue : replaced return value with Optional.empty for com/yubico/webauthn/data/ResidentKeyRequirement::fromValue → KILLED
2. lambda$fromValue$0 : replaced boolean return with true for com/yubico/webauthn/data/ResidentKeyRequirement::lambda$fromValue$0 → KILLED
3. lambda$fromValue$0 : replaced boolean return with false for com/yubico/webauthn/data/ResidentKeyRequirement::lambda$fromValue$0 → KILLED
    return Stream.of(values()).filter(v -> v.value.equals(value)).findAny();
121
  }
122
123
  @JsonCreator
124 1 1. fromJsonString : negated conditional → KILLED
  private static ResidentKeyRequirement fromJsonString(@NonNull String value) {
125 1 1. fromJsonString : replaced return value with null for com/yubico/webauthn/data/ResidentKeyRequirement::fromJsonString → KILLED
    return fromValue(value)
126
        .orElseThrow(
127
            () ->
128 1 1. lambda$fromJsonString$1 : replaced return value with null for com/yubico/webauthn/data/ResidentKeyRequirement::lambda$fromJsonString$1 → KILLED
                new IllegalArgumentException(
129
                    String.format(
130
                        "Unknown %s value: %s",
131
                        ResidentKeyRequirement.class.getSimpleName(), value)));
132
  }
133
}

Mutations

119

1.1
Location : fromValue
Killed by : com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest.newResidentKeyOverridesOld(com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest)
negated conditional → KILLED

120

1.1
Location : fromValue
Killed by : com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest.newResidentKeyOverridesOld(com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest)
replaced return value with Optional.empty for com/yubico/webauthn/data/ResidentKeyRequirement::fromValue → KILLED

2.2
Location : lambda$fromValue$0
Killed by : com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest.newResidentKeyOverridesOld(com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest)
replaced boolean return with true for com/yubico/webauthn/data/ResidentKeyRequirement::lambda$fromValue$0 → KILLED

3.3
Location : lambda$fromValue$0
Killed by : com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest.newResidentKeyOverridesOld(com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest)
replaced boolean return with false for com/yubico/webauthn/data/ResidentKeyRequirement::lambda$fromValue$0 → KILLED

124

1.1
Location : fromJsonString
Killed by : com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest.newResidentKeyOverridesOld(com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest)
negated conditional → KILLED

125

1.1
Location : fromJsonString
Killed by : com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest.newResidentKeyOverridesOld(com.yubico.webauthn.data.AuthenticatorSelectionCriteriaTest)
replaced return value with null for com/yubico/webauthn/data/ResidentKeyRequirement::fromJsonString → KILLED

128

1.1
Location : lambda$fromJsonString$1
Killed by : com.yubico.webauthn.data.EnumsSpec
replaced return value with null for com/yubico/webauthn/data/ResidentKeyRequirement::lambda$fromJsonString$1 → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.0