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 */
016package com.revetsec.saml;
017
018import org.jspecify.annotations.NonNull;
019import javax.annotation.concurrent.Immutable;
020
021/**
022 * The outcome of sealing SAML logout continuity fields. Only {@link Succeeded} carries a
023 * storage value. Size and provider failures expose no reference, plaintext or provider details.
024 * A later release may add variants; consumers should reject unknown outcomes.
025 *
026 * @since 1.0.0
027 */
028@Immutable
029public sealed interface SamlSessionReferenceSealResult permits SamlSessionReferenceSealResult.Succeeded,
030        SamlSessionReferenceSealResult.TooLarge, SamlSessionReferenceSealResult.Unavailable {
031    /**
032     * A reference sealed for the requested application context and expiry.
033     *
034     * @since 1.0.0
035     */
036    @Immutable
037    final class Succeeded implements SamlSessionReferenceSealResult {
038        private final @NonNull String sealedForm;
039        Succeeded(@NonNull String sealedForm) { this.sealedForm = sealedForm; }
040        /**
041         * Returns the sealed continuity reference, which contains personal data when opened.
042         *
043         * @return opaque sealed storage form
044         * @since 1.0.0
045         */
046        public @NonNull String getSealedForm() { return sealedForm; }
047        /**
048         * Redacts the sealed value.
049         * @return redacted outcome
050         * @since 1.0.0
051         */
052        @Override public @NonNull String toString() { return "SamlSessionReferenceSealResult.Succeeded{<redacted>}"; }
053    }
054
055    /**
056     * The complete reference cannot fit the sealer's configured output limit. No encryption
057     * was attempted. Use trusted server-side storage or decline session creation if logout
058     * continuity is required; do not truncate the reference.
059     *
060     * @since 1.0.0
061     */
062    @Immutable
063    enum TooLarge implements SamlSessionReferenceSealResult {
064        /** The fixed size-refusal outcome. */
065        INSTANCE;
066        /**
067         * Returns the fixed outcome without reference data.
068         * @return fixed outcome description
069         * @since 1.0.0
070         */
071        @Override public @NonNull String toString() { return "SamlSessionReferenceSealResult.TooLarge"; }
072    }
073
074    /**
075     * The cryptographic provider could not produce a sealed value. No value is available
076     * to persist or return to the browser.
077     *
078     * @since 1.0.0
079     */
080    @Immutable
081    enum Unavailable implements SamlSessionReferenceSealResult {
082        /** The fixed provider-unavailable outcome. */
083        INSTANCE;
084        /**
085         * Returns the fixed outcome without provider or reference data.
086         * @return fixed outcome description
087         * @since 1.0.0
088         */
089        @Override public @NonNull String toString() { return "SamlSessionReferenceSealResult.Unavailable"; }
090    }
091}