PublicKeyCredentialType.java

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.Optional;
30
import java.util.stream.Stream;
31
import lombok.AllArgsConstructor;
32
import lombok.Getter;
33
import lombok.NonNull;
34
35
/**
36
 * Defines the valid credential types.
37
 *
38
 * <p>It is an extensions point; values may be added to it in the future, as more credential types
39
 * are defined. The values of this enumeration are used for versioning the Authentication Assertion
40
 * and attestation structures according to the type of the authenticator.
41
 *
42
 * <p>Currently one credential type is defined, namely {@link #PUBLIC_KEY}.
43
 *
44
 * @see <a
45
 *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enumdef-publickeycredentialtype">§5.10.2.
46
 *     Credential Type Enumeration (enum PublicKeyCredentialType)</a>
47
 */
48
@AllArgsConstructor
49
public enum PublicKeyCredentialType {
50
  PUBLIC_KEY("public-key");
51
52
  @JsonValue @Getter @NonNull private final String id;
53
54
  /**
55
   * Attempt to parse a string as a {@link PublicKeyCredentialType}.
56
   *
57
   * @param id a {@link String} equal to the {@link #getId() id} of a constant in {@link
58
   *     PublicKeyCredentialType}
59
   * @return The {@link AuthenticatorAttachment} instance whose {@link #getId() id} equals <code>id
60
   *     </code>, if any.
61
   * @see <a
62
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enumdef-publickeycredentialtype">§5.10.2.
63
   *     Credential Type Enumeration (enum PublicKeyCredentialType)</a>
64
   */
65 1 1. fromId : negated conditional → KILLED
  public static Optional<PublicKeyCredentialType> fromId(@NonNull String id) {
66 3 1. fromId : replaced return value with Optional.empty for com/yubico/webauthn/data/PublicKeyCredentialType::fromId → KILLED
2. lambda$fromId$0 : replaced boolean return with true for com/yubico/webauthn/data/PublicKeyCredentialType::lambda$fromId$0 → KILLED
3. lambda$fromId$0 : replaced boolean return with false for com/yubico/webauthn/data/PublicKeyCredentialType::lambda$fromId$0 → KILLED
    return Stream.of(values()).filter(v -> v.id.equals(id)).findAny();
67
  }
68
69
  @JsonCreator
70 1 1. fromJsonString : negated conditional → KILLED
  private static PublicKeyCredentialType fromJsonString(@NonNull String id) {
71 1 1. fromJsonString : replaced return value with null for com/yubico/webauthn/data/PublicKeyCredentialType::fromJsonString → KILLED
    return fromId(id)
72
        .orElseThrow(
73
            () ->
74 1 1. lambda$fromJsonString$1 : replaced return value with null for com/yubico/webauthn/data/PublicKeyCredentialType::lambda$fromJsonString$1 → KILLED
                new IllegalArgumentException(
75
                    String.format(
76
                        "Unknown %s value: %s",
77
                        PublicKeyCredentialType.class.getSimpleName(), id)));
78
  }
79
}

Mutations

65

1.1
Location : fromId
Killed by : com.yubico.webauthn.data.EnumsSpec
negated conditional → KILLED

66

1.1
Location : fromId
Killed by : com.yubico.webauthn.data.ExtensionsSpec
replaced return value with Optional.empty for com/yubico/webauthn/data/PublicKeyCredentialType::fromId → KILLED

2.2
Location : lambda$fromId$0
Killed by : com.yubico.webauthn.data.EnumsSpec
replaced boolean return with true for com/yubico/webauthn/data/PublicKeyCredentialType::lambda$fromId$0 → KILLED

3.3
Location : lambda$fromId$0
Killed by : com.yubico.webauthn.data.ExtensionsSpec
replaced boolean return with false for com/yubico/webauthn/data/PublicKeyCredentialType::lambda$fromId$0 → KILLED

70

1.1
Location : fromJsonString
Killed by : com.yubico.webauthn.data.EnumsSpec
negated conditional → KILLED

71

1.1
Location : fromJsonString
Killed by : com.yubico.webauthn.data.ExtensionsSpec
replaced return value with null for com/yubico/webauthn/data/PublicKeyCredentialType::fromJsonString → KILLED

74

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

Active mutators

Tests examined


Report generated by PIT 1.15.0