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.oauth;
018
019import com.google.errorprone.annotations.CheckReturnValue;
020import java.time.Duration;
021import javax.annotation.concurrent.ThreadSafe;
022import org.jspecify.annotations.NonNull;
023import static java.util.Objects.requireNonNull;
024
025/**
026 * Supplies one immutable key and header snapshot per assertion POST. Implementations must be thread-safe,
027 * cooperate with the remaining budget and interruption, and return promptly. Execution is on the calling thread.
028 * No key lookup occurs at client construction or on a cached token result.
029 * @author <a href="https://www.revetkn.com">Mark Allen</a>
030 * @since 1.0.0
031 */
032@ThreadSafe
033public interface ClientAssertionKeyProvider {
034        /**
035         * Selects the key for one outgoing assertion.
036         * @param remainingBudget the positive time left in the original operation
037         * @return one immutable signer and identifier snapshot
038         * @since 1.0.0
039         */
040        @NonNull ClientAssertionSigningKey getSigningKey(@NonNull Duration remainingBudget);
041
042        /**
043         * Uses one fixed immutable key snapshot.
044         * @param key the snapshot
045         * @return a thread-safe fixed provider
046         * @since 1.0.0
047         */
048        @CheckReturnValue
049        static @NonNull ClientAssertionKeyProvider fromKey(@NonNull ClientAssertionSigningKey key) {
050                requireNonNull(key);
051                return remainingBudget -> { requireNonNull(remainingBudget); return key; };
052        }
053}