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.totp; 018 019import org.jspecify.annotations.NonNull; 020import javax.annotation.concurrent.Immutable; 021import java.time.Instant; 022 023import static java.util.Objects.requireNonNull; 024 025/** A persisted pending enrollment whose secret is released only after a confirmed write. 026 * @since 1.0.0 */ 027@Immutable 028public final class TotpEnrollment { 029 private final @NonNull String enrollmentId; 030 private final @NonNull String factorId; 031 private final @NonNull Instant expiresAt; 032 private final @NonNull String provisioningUri; 033 private final @NonNull String manualEntryKey; 034 private final @NonNull String recoveryEpoch; 035 036 TotpEnrollment(@NonNull String enrollmentId, @NonNull String factorId, @NonNull Instant expiresAt, @NonNull String provisioningUri, @NonNull String manualEntryKey, @NonNull String recoveryEpoch) { 037 this.enrollmentId = requireNonNull(enrollmentId); 038 this.factorId = requireNonNull(factorId); 039 this.expiresAt = requireNonNull(expiresAt); 040 this.provisioningUri = requireNonNull(provisioningUri); 041 this.manualEntryKey = requireNonNull(manualEntryKey); 042 this.recoveryEpoch = requireNonNull(recoveryEpoch); 043 } 044 045 /** The pending enrollment identifier. 046 * @return enrollmentId 047 * @since 1.0.0 */ 048 public @NonNull String getEnrollmentId() { return this.enrollmentId; } 049 050 /** The candidate factor generation activated by confirmation. 051 * @return factorId 052 * @since 1.0.0 */ 053 public @NonNull String getFactorId() { return this.factorId; } 054 055 /** The pending enrollment expiry. 056 * @return expiresAt 057 * @since 1.0.0 */ 058 public @NonNull Instant getExpiresAt() { return this.expiresAt; } 059 060 /** The secret-bearing otpauth URI for an authenticator application. 061 * @return provisioningUri 062 * @since 1.0.0 */ 063 public @NonNull String getProvisioningUri() { return this.provisioningUri; } 064 065 /** The secret-bearing Base32 key for manual authenticator setup. 066 * @return manualEntryKey 067 * @since 1.0.0 */ 068 public @NonNull String getManualEntryKey() { return this.manualEntryKey; } 069 070 /** The admitted recovery epoch. 071 * @return recoveryEpoch 072 * @since 1.0.0 */ 073 public @NonNull String getRecoveryEpoch() { return this.recoveryEpoch; } 074 075 /** Redacts all account, operation and secret data. 076 * @return a fixed description 077 * @since 1.0.0 */ 078 @Override public @NonNull String toString() { return "TotpEnrollment{<redacted>}"; } 079}