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;
020
021import javax.annotation.concurrent.NotThreadSafe;
022
023/**
024 * Thrown when a sealed value cannot be opened.
025 * <p>
026 * Every failure to open a sealed value throws this one exception, with the same fixed message, no cause and nothing
027 * suppressed: a value that was tampered with, truncated, malformed, sealed for a different context, sealed under a
028 * key that is not configured, or expired. The exception deliberately does not say which, so it cannot help anyone
029 * probe the sealer.
030 * <p>
031 * Its category is {@link ErrorCategory#VALIDATION_FAILURE}, and it is never transient: retrying with the same
032 * sealed value always fails the same way.
033 *
034 * @author <a href="https://www.revetkn.com">Mark Allen</a>
035 * @since 1.0.0
036 */
037@NotThreadSafe
038public final class InvalidSealedStateException extends RevetsecException {
039        /**
040         * The serialized form's version.
041         */
042        private static final long serialVersionUID = 1L;
043
044        private static final String MESSAGE = "Sealed state is invalid.";
045
046        /**
047         * Returns a new instance for any failure to open a sealed value. Only Revetsec's sealer calls this.
048         *
049         * @return a new instance, with the fixed message and no cause
050         */
051        @NonNull
052        static InvalidSealedStateException fromAnyFailure() {
053                return new InvalidSealedStateException();
054        }
055
056        private InvalidSealedStateException() {
057                super(ErrorCategory.VALIDATION_FAILURE, false, MESSAGE, null);
058        }
059}