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; 018 019import org.jspecify.annotations.NonNull; 020import javax.annotation.concurrent.Immutable; 021import static java.util.Objects.requireNonNull; 022 023/** 024 * The outcome of opening sealed application state. Every opening failure has the same rejected outcome. 025 * <p> 026 * Applications receive these outcomes from the corresponding operation; they cannot construct them. 027 * Value accessors exist only on the variant that owns a value. Diagnostic text contains no input or result data. 028 * A later release may add variants; consuming switches should include a rejecting default branch. 029 * 030 * @author <a href="https://www.revetkn.com">Mark Allen</a> 031 * @since 1.0.0 032 */ 033@Immutable 034public abstract sealed class StateUnsealResult permits StateUnsealResult.Succeeded, StateUnsealResult.Rejected { 035 StateUnsealResult() { } 036 037 static @NonNull StateUnsealResult fromValue(@NonNull String value) { 038 return new Succeeded(requireNonNull(value)); 039 } 040 041 static @NonNull StateUnsealResult fromRejection() { 042 return new Rejected(); 043 } 044 045 /** 046 * Returns the outcome kind with all values redacted. 047 * @return redacted description 048 * @since 1.0.0 049 */ 050 @Override 051 public final @NonNull String toString() { 052 return "StateUnsealResult{outcome=" + getClass().getSimpleName() + ", data=<redacted>}"; 053 } 054 055 /** 056 * The state authenticated for the context and its lifetime has not ended. 057 * @author <a href="https://www.revetkn.com">Mark Allen</a> 058 * @since 1.0.0 059 */ 060 @Immutable 061 public static final class Succeeded extends StateUnsealResult { 062 private final @NonNull String value; 063 private Succeeded(@NonNull String value) { this.value = value; } 064 065 /** 066 * Returns the authenticated plaintext; it may contain application secrets. 067 * @return value 068 * @since 1.0.0 069 */ 070 public @NonNull String getValue() { return this.value; } 071 } 072 073 /** 074 * The state could not be opened. No failure step or plaintext is exposed. 075 * @author <a href="https://www.revetkn.com">Mark Allen</a> 076 * @since 1.0.0 077 */ 078 @Immutable 079 public static final class Rejected extends StateUnsealResult { 080 private Rejected() { } 081 } 082}