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.totp; 018 019import org.jspecify.annotations.NonNull; 020import com.google.errorprone.annotations.CheckReturnValue; 021import javax.annotation.concurrent.Immutable; 022 023import static java.util.Objects.requireNonNull; 024 025/** Application-approved cancellation of an exact browser-bound pending enrollment. 026 * @since 1.0.0 */ 027@Immutable 028public abstract sealed class TotpEnrollmentCancellationResult permits 029 TotpEnrollmentCancellationResult.Succeeded, TotpEnrollmentCancellationResult.Rejected, TotpEnrollmentCancellationResult.Unavailable, TotpEnrollmentCancellationResult.Indeterminate, TotpEnrollmentCancellationResult.ReconciliationRequired { 030 private static final @NonNull Succeeded SUCCEEDED = new Succeeded(); 031 private static final @NonNull Indeterminate INDETERMINATE = new Indeterminate(); 032 private static final @NonNull ReconciliationRequired RECONCILIATION_REQUIRED = new ReconciliationRequired(); 033 034 TotpEnrollmentCancellationResult() { } 035 static @NonNull TotpEnrollmentCancellationResult succeeded() { 036 return SUCCEEDED; 037 } 038 static @NonNull TotpEnrollmentCancellationResult rejected(@NonNull TotpRejectionReason reason) { 039 return new Rejected(reason); 040 } 041 static @NonNull TotpEnrollmentCancellationResult unavailable(@NonNull TotpUnavailableReason reason) { 042 return new Unavailable(reason); 043 } 044 static @NonNull TotpEnrollmentCancellationResult indeterminate() { 045 return INDETERMINATE; 046 } 047 @CheckReturnValue 048 static @NonNull TotpEnrollmentCancellationResult reconciliationRequired() { 049 return RECONCILIATION_REQUIRED; 050 } 051 static @NonNull TotpEnrollmentCancellationResult unavailable() { 052 return unavailable(TotpUnavailableReason.DEPENDENCY_UNAVAILABLE); 053 } 054 055 /** Redacts all account, binding and secret data. 056 * @return a fixed description 057 * @since 1.0.0 */ 058 @Override public final @NonNull String toString() { return "TotpEnrollmentCancellationResult{<redacted>}"; } 059 060 /** The requested transition was definitely committed under current admission. 061 * @since 1.0.0 */ 062 @Immutable 063 public static final class Succeeded extends TotpEnrollmentCancellationResult { 064 private Succeeded() { } 065 } 066 067 /** Fixed input, policy or generation rejection; no proof is released. 068 * @since 1.0.0 */ 069 @Immutable 070 public static final class Rejected extends TotpEnrollmentCancellationResult { 071 private final @NonNull TotpRejectionReason reason; 072 private Rejected(@NonNull TotpRejectionReason reason) { 073 this.reason = requireNonNull(reason); 074 } 075 /** Returns the reason. 076 * @return reason 077 * @since 1.0.0 */ 078 public @NonNull TotpRejectionReason getReason() { return this.reason; } 079 } 080 081 /** Infrastructure or recovery admission was unavailable; no success is established. 082 * @since 1.0.0 */ 083 @Immutable 084 public static final class Unavailable extends TotpEnrollmentCancellationResult { 085 private final @NonNull TotpUnavailableReason reason; 086 private Unavailable(@NonNull TotpUnavailableReason reason) { 087 this.reason = requireNonNull(reason); 088 } 089 /** Returns the reason. 090 * @return reason 091 * @since 1.0.0 */ 092 public @NonNull TotpUnavailableReason getReason() { return this.reason; } 093 } 094 095 /** A write may have occurred; reconcile management state and never infer authentication success. 096 * @since 1.0.0 */ 097 @Immutable 098 public static final class Indeterminate extends TotpEnrollmentCancellationResult { 099 private Indeterminate() { } 100 } 101 102 /** The requested transition is known committed, but normal output could not be admitted. 103 * No proof, secret or operation detail is released. 104 * @since 1.0.0 */ 105 @Immutable 106 public static final class ReconciliationRequired extends TotpEnrollmentCancellationResult { 107 private ReconciliationRequired() { } 108 } 109}