001/*
002 * Copyright 2026 Revetware LLC.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.revetsec.webauthn;
018
019import com.google.errorprone.annotations.CheckReturnValue;
020import java.util.Objects;
021import org.jspecify.annotations.NonNull;
022
023/** One authoritative read result. No result grants a verified WebAuthn proof.
024 * @since 1.0.0 */
025@javax.annotation.concurrent.Immutable
026@CheckReturnValue
027public sealed interface WebAuthnStoreReadResult
028  permits WebAuthnStoreReadResult.Available, WebAuthnStoreReadResult.Fenced, WebAuthnStoreReadResult.Unavailable {
029 /** A complete versioned snapshot.
030  * @since 1.0.0 */
031 @javax.annotation.concurrent.Immutable
032 final class Available implements WebAuthnStoreReadResult {
033  private final @NonNull WebAuthnStoreSnapshot snapshot;
034  private Available(@NonNull WebAuthnStoreSnapshot snapshot) { this.snapshot = Objects.requireNonNull(snapshot); }
035  /** Wraps a complete snapshot.
036   * @param snapshot the complete read set
037   * @return the available result
038   * @since 1.0.0 */
039  public static WebAuthnStoreReadResult.@NonNull Available fromSnapshot(@NonNull WebAuthnStoreSnapshot snapshot) {
040   return new Available(snapshot);
041  }
042  /** Returns the complete snapshot.
043   * @return the read set
044   * @since 1.0.0 */
045  public @NonNull WebAuthnStoreSnapshot getSnapshot() { return this.snapshot; }
046  /** Redacts all observations. @since 1.0.0 */
047  @Override public @NonNull String toString() { return "Available{snapshot=<redacted>}"; }
048 }
049
050 /** The requested state incarnation is incompatible with current admission.
051  * @since 1.0.0 */
052 @javax.annotation.concurrent.Immutable
053 @CheckReturnValue
054 final class Fenced implements WebAuthnStoreReadResult {
055  private static final WebAuthnStoreReadResult.@NonNull Fenced INSTANCE = new Fenced();
056  private Fenced() { }
057  /** Returns the fixed fenced outcome.
058   * @return the fenced result
059   * @since 1.0.0 */
060  public static WebAuthnStoreReadResult.@NonNull Fenced get() { return INSTANCE; }
061  /** Returns a fixed description. @since 1.0.0 */
062  @Override public @NonNull String toString() { return "Fenced{}"; }
063 }
064
065 /** No authoritative read was available.
066  * @since 1.0.0 */
067 @javax.annotation.concurrent.Immutable
068 final class Unavailable implements WebAuthnStoreReadResult {
069  private static final WebAuthnStoreReadResult.@NonNull Unavailable INSTANCE = new Unavailable();
070  private Unavailable() { }
071  /** Returns the unavailable outcome.
072   * @return the unavailable result
073   * @since 1.0.0 */
074  public static WebAuthnStoreReadResult.@NonNull Unavailable get() { return INSTANCE; }
075  /** Returns a fixed description. @since 1.0.0 */
076  @Override public @NonNull String toString() { return "Unavailable{}"; }
077 }
078}