Documentation
¶
Index ¶
- Constants
- func GenerateEncryptionKey() (string, error)
- func NormalizeBackupCode(input string) string
- func ValidateBackupCodeFormat(code string) error
- type BackupCode
- type BackupCodeEncryption
- type BackupCodeGenerator
- func (g *BackupCodeGenerator) ConsumeBackupCode(ctx context.Context, userID int32, codeToConsume string, updatedBy string) (bool, error)
- func (g *BackupCodeGenerator) GenerateAndStoreBackupCodes(ctx context.Context, userID int32, updatedBy string) ([]string, error)
- func (g *BackupCodeGenerator) GenerateBackupCodes() ([]string, error)
- func (g *BackupCodeGenerator) GetBackupCodes(ctx context.Context, userID int32) ([]BackupCode, error)
- func (g *BackupCodeGenerator) GetBackupCodesCount(ctx context.Context, userID int32) (int, error)
- func (g *BackupCodeGenerator) GetBackupCodesGeneratedAt(ctx context.Context, userID int32) (string, error)
- func (g *BackupCodeGenerator) GetBackupCodesReadStatus(ctx context.Context, userID int32) (bool, error)
- func (g *BackupCodeGenerator) UpdateBackupCodes(ctx context.Context, userID int32, codes []BackupCode, updatedBy string) error
- type EncryptionError
- type Metadata
Constants ¶
const ( // BackupCodeCount is the number of backup codes to generate BackupCodeCount = 10 // BackupCodePartLength is the length of each part of the backup code (before and after hyphen) BackupCodePartLength = 5 )
Variables ¶
This section is empty.
Functions ¶
func GenerateEncryptionKey ¶
GenerateEncryptionKey generates a new 256-bit encryption key for backup codes
func NormalizeBackupCode ¶
NormalizeBackupCode normalizes user input by removing spaces and converting to expected format
func ValidateBackupCodeFormat ¶
ValidateBackupCodeFormat validates that a backup code matches the expected format
Types ¶
type BackupCode ¶
type BackupCode struct {
Code string `json:"code"`
}
BackupCode represents a single backup code
type BackupCodeEncryption ¶
type BackupCodeEncryption struct {
// contains filtered or unexported fields
}
BackupCodeEncryption handles encryption and decryption of backup codes
func NewBackupCodeEncryption ¶
func NewBackupCodeEncryption() (*BackupCodeEncryption, error)
NewBackupCodeEncryption creates a new backup code encryption instance
type BackupCodeGenerator ¶
type BackupCodeGenerator struct {
// contains filtered or unexported fields
}
BackupCodeGenerator handles the generation of backup codes
func NewBackupCodeGenerator ¶
func NewBackupCodeGenerator(db models.ServiceInterface) *BackupCodeGenerator
NewBackupCodeGenerator creates a new backup code generator
func (*BackupCodeGenerator) ConsumeBackupCode ¶
func (g *BackupCodeGenerator) ConsumeBackupCode(ctx context.Context, userID int32, codeToConsume string, updatedBy string) (bool, error)
ConsumeBackupCode removes a backup code from the array and updates the count
func (*BackupCodeGenerator) GenerateAndStoreBackupCodes ¶
func (g *BackupCodeGenerator) GenerateAndStoreBackupCodes( ctx context.Context, userID int32, updatedBy string, ) ([]string, error)
GenerateAndStoreBackupCodes generates backup codes and stores them in the database
func (*BackupCodeGenerator) GenerateBackupCodes ¶
func (g *BackupCodeGenerator) GenerateBackupCodes() ([]string, error)
GenerateBackupCodes generates 10 unique backup codes in the format 'abcde-12345'
func (*BackupCodeGenerator) GetBackupCodes ¶
func (g *BackupCodeGenerator) GetBackupCodes(ctx context.Context, userID int32) ([]BackupCode, error)
GetBackupCodes retrieves and decrypts backup codes for a user
func (*BackupCodeGenerator) GetBackupCodesCount ¶
GetBackupCodesCount returns the number of remaining backup codes without decryption
func (*BackupCodeGenerator) GetBackupCodesGeneratedAt ¶
func (g *BackupCodeGenerator) GetBackupCodesGeneratedAt(ctx context.Context, userID int32) (string, error)
GetBackupCodesGeneratedAt returns when backup codes were generated without decryption
func (*BackupCodeGenerator) GetBackupCodesReadStatus ¶
func (g *BackupCodeGenerator) GetBackupCodesReadStatus(ctx context.Context, userID int32) (bool, error)
GetBackupCodesReadStatus returns whether the user has seen their backup codes
func (*BackupCodeGenerator) UpdateBackupCodes ¶
func (g *BackupCodeGenerator) UpdateBackupCodes( ctx context.Context, userID int32, codes []BackupCode, updatedBy string, ) error
UpdateBackupCodes stores updated backup codes (used when codes are consumed)
type EncryptionError ¶
EncryptionError represents an error during encryption/decryption
func (*EncryptionError) Error ¶
func (e *EncryptionError) Error() string
func (*EncryptionError) Unwrap ¶
func (e *EncryptionError) Unwrap() error