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/** An active factor generation; this value contains no TOTP secret. 026 * @since 1.0.0 */ 027@Immutable 028public final class TotpFactor { 029 private final @NonNull String credentialNamespace; 030 private final @NonNull String recoveryEpoch; 031 private final @NonNull String accountId; 032 private final @NonNull String factorId; 033 private final @NonNull Instant enrolledAt; 034 035 TotpFactor(@NonNull String credentialNamespace, @NonNull String recoveryEpoch, @NonNull String accountId, @NonNull String factorId, @NonNull Instant enrolledAt) { 036 this.credentialNamespace = requireNonNull(credentialNamespace); 037 this.recoveryEpoch = requireNonNull(recoveryEpoch); 038 this.accountId = requireNonNull(accountId); 039 this.factorId = requireNonNull(factorId); 040 this.enrolledAt = requireNonNull(enrolledAt); 041 } 042 043 /** The application credential namespace. 044 * @return credentialNamespace 045 * @since 1.0.0 */ 046 public @NonNull String getCredentialNamespace() { return this.credentialNamespace; } 047 048 /** The recovery epoch in which this factor is authoritative. 049 * @return recoveryEpoch 050 * @since 1.0.0 */ 051 public @NonNull String getRecoveryEpoch() { return this.recoveryEpoch; } 052 053 /** The application-approved account identifier. 054 * @return accountId 055 * @since 1.0.0 */ 056 public @NonNull String getAccountId() { return this.accountId; } 057 058 /** The active factor generation identifier. 059 * @return factorId 060 * @since 1.0.0 */ 061 public @NonNull String getFactorId() { return this.factorId; } 062 063 /** The confirmed enrollment instant. 064 * @return enrolledAt 065 * @since 1.0.0 */ 066 public @NonNull Instant getEnrolledAt() { return this.enrolledAt; } 067 068 /** Redacts all account, operation and secret data. 069 * @return a fixed description 070 * @since 1.0.0 */ 071 @Override public @NonNull String toString() { return "TotpFactor{<redacted>}"; } 072}