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.password; 017 018import org.jspecify.annotations.NonNull; 019 020import javax.annotation.concurrent.ThreadSafe; 021 022import static java.util.Objects.requireNonNull; 023 024/** Thread-safe application source of coherent pepper-key snapshots. Implementations must be 025 * bounded and must not log key material. The hasher calls this on the caller thread, never from 026 * its builder or a library worker thread. 027 * @since 1.0.0 */ 028@FunctionalInterface 029@ThreadSafe 030public interface PasswordPepperSource { 031 /** Supplies the complete snapshot for one operation. 032 * @return available or unavailable, never {@code null} 033 * @since 1.0.0 */ 034 @NonNull PasswordPepperSnapshotResult snapshotResult(); 035 036 /** Supplies a constant snapshot until the application replaces its hasher configuration. 037 * @param snapshot immutable keys 038 * @return fixed source 039 * @since 1.0.0 */ 040 static @NonNull PasswordPepperSource fromSnapshot(@NonNull PasswordPepperSnapshot snapshot) { 041 PasswordPepperSnapshot accepted = requireNonNull(snapshot); 042 return () -> PasswordPepperSnapshotResult.available(accepted); 043 } 044}