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.servlet.javax;
017
018import com.google.errorprone.annotations.CheckReturnValue;
019import org.jspecify.annotations.NonNull;
020
021import javax.annotation.concurrent.Immutable;
022
023import static java.util.Objects.requireNonNull;
024
025/** Outcome of a bounded raw WebAuthn completion-body read. The application handles every branch
026 * before passing the bytes to core with its application-held ceremony ID and browser binding.
027 * @since 1.0.0
028 */
029@Immutable
030public sealed interface ServletWebAuthnBodyResult permits ServletWebAuthnBodyResult.Read,
031        ServletWebAuthnBodyResult.Rejected, ServletWebAuthnBodyResult.Unavailable {
032    /** The original raw JSON body, which may contain personal data.
033     * @since 1.0.0
034     */
035    @Immutable final class Read implements ServletWebAuthnBodyResult {
036        private final byte @NonNull [] body;
037        Read(byte @NonNull [] body) { this.body = requireNonNull(body).clone(); }
038
039        /** Returns a defensive copy of the original body.
040         * @return unchanged bytes, which may contain personal data
041         * @since 1.0.0
042         */
043        @CheckReturnValue public byte @NonNull [] getBodyWithPersonalData() { return this.body.clone(); }
044        @Override public @NonNull String toString() { return "ServletWebAuthnBodyResult.Read{<redacted>}"; }
045    }
046
047    /** Method, media type or body size was rejected without retaining body bytes.
048     * @since 1.0.0
049     */
050    @Immutable final class Rejected implements ServletWebAuthnBodyResult {
051        static final @NonNull Rejected INSTANCE = new Rejected();
052        private Rejected() { }
053        @Override public @NonNull String toString() { return "ServletWebAuthnBodyResult.Rejected"; }
054    }
055
056    /** Input could not be read; the application chooses transport failure handling.
057     * @since 1.0.0
058     */
059    @Immutable final class Unavailable implements ServletWebAuthnBodyResult {
060        static final @NonNull Unavailable INSTANCE = new Unavailable();
061        private Unavailable() { }
062        @Override public @NonNull String toString() { return "ServletWebAuthnBodyResult.Unavailable"; }
063    }
064}