model

package
v0.0.0-...-283a974 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package model defines the internal credential data model used across all adapters.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyCredential     = errors.New("credential is empty")
	ErrMissingID           = errors.New("credential ID is required")
	ErrMissingTitle        = errors.New("credential title is required")
	ErrMissingPassword     = errors.New("password is required for basic-auth credential")
	ErrMissingTOTPSecret   = errors.New("TOTP secret is required")
	ErrInvalidTOTPSecret   = errors.New("TOTP secret must be valid base32")
	ErrInvalidTOTPDigits   = errors.New("TOTP digits must be 6 or 8")
	ErrInvalidTOTPPeriod   = errors.New("TOTP period must be positive")
	ErrInvalidTOTPAlgo     = errors.New("TOTP algorithm must be SHA1, SHA256, or SHA512")
	ErrMissingSSHKey       = errors.New("SSH private key is required")
	ErrInvalidSSHKeyFormat = errors.New("SSH private key must be PEM-encoded")
	ErrMissingCardNumber   = errors.New("credit card number is required")
	ErrInvalidCardMonth    = errors.New("credit card expiry month must be 1-12")
	ErrInvalidCardYear     = errors.New("credit card expiry year must be 4 digits")
)

Validation errors.

Functions

func ValidateAll

func ValidateAll(creds []Credential) []error

ValidateAll validates a slice of credentials and returns all errors.

func ValidateCreditCard

func ValidateCreditCard(cc *CreditCardData) error

ValidateCreditCard validates credit card data.

func ValidateSSHKey

func ValidateSSHKey(k *SSHKeyData) error

ValidateSSHKey validates SSH key data.

func ValidateTOTP

func ValidateTOTP(t *TOTPData) error

ValidateTOTP validates TOTP data.

Types

type Attachment

type Attachment struct {
	// Name is the filename of the attachment.
	Name string

	// Data is the binary content.
	Data []byte

	// MimeType is the MIME type of the attachment.
	MimeType string
}

Attachment represents a binary attachment to a credential.

type Credential

type Credential struct {
	// ID is a unique identifier for the credential.
	ID string

	// Type indicates what kind of credential this is.
	Type CredentialType

	// Title is the display name for the credential.
	Title string

	// Username for authentication credentials.
	Username string

	// Password for basic auth credentials.
	Password string

	// URL is the associated website or service URL.
	URL string

	// Notes contains additional text notes.
	Notes string

	// TOTP contains TOTP configuration if Type == TypeTOTP.
	TOTP *TOTPData

	// SSHKey contains SSH key data if Type == TypeSSHKey.
	SSHKey *SSHKeyData

	// CreditCard contains credit card data if Type == TypeCreditCard.
	CreditCard *CreditCardData

	// CustomFields stores additional key-value pairs.
	CustomFields map[string]string

	// Tags for categorization.
	Tags []string

	// FolderPath represents the hierarchical location, "/" separated.
	// Example: "Work/Servers"
	FolderPath string

	// Created is when the credential was first created.
	Created time.Time

	// Modified is when the credential was last modified.
	Modified time.Time

	// Attachments contains binary attachments.
	Attachments []Attachment
}

Credential represents a normalized credential that can be converted to CXF format. It serves as the intermediate representation between source formats and CXF output.

func (*Credential) Clone

func (c *Credential) Clone() *Credential

Clone creates a deep copy of the credential.

func (*Credential) IsEmpty

func (c *Credential) IsEmpty() bool

IsEmpty returns true if the credential has no meaningful data.

func (*Credential) Sanitize

func (c *Credential) Sanitize()

Sanitize removes leading/trailing whitespace from string fields.

func (*Credential) Validate

func (c *Credential) Validate() error

Validate validates the credential based on its type.

type CredentialType

type CredentialType int

CredentialType represents the type of credential being stored.

const (
	// TypeBasicAuth represents a basic username/password credential.
	TypeBasicAuth CredentialType = iota
	// TypeTOTP represents a Time-based One-Time Password credential.
	TypeTOTP
	// TypeSSHKey represents an SSH key credential.
	TypeSSHKey
	// TypeNote represents a secure note credential.
	TypeNote
	// TypeCreditCard represents a credit card credential.
	TypeCreditCard
	// TypeIdentity represents an identity/personal info credential.
	TypeIdentity
	// TypeAPIKey represents an API key credential.
	TypeAPIKey
	// TypeWiFi represents a WiFi network credential.
	TypeWiFi
)

func ParseCredentialType

func ParseCredentialType(s string) (CredentialType, error)

ParseCredentialType parses a string into a CredentialType.

func (CredentialType) String

func (t CredentialType) String() string

String returns the string representation of the CredentialType.

type CreditCardData

type CreditCardData struct {
	// Number is the card number.
	Number string

	// Holder is the cardholder name.
	Holder string

	// ExpiryMonth is the expiration month (1-12).
	ExpiryMonth int

	// ExpiryYear is the expiration year (4-digit).
	ExpiryYear int

	// CVV is the card verification value.
	CVV string

	// PIN is the card PIN.
	PIN string

	// Brand is the card brand (Visa, Mastercard, etc.).
	Brand string
}

CreditCardData contains credit card information.

type SSHKeyData

type SSHKeyData struct {
	// PrivateKey is the PEM-encoded private key.
	PrivateKey string

	// PublicKey is the OpenSSH-format public key.
	PublicKey string

	// Fingerprint is the SHA256 fingerprint of the public key.
	Fingerprint string

	// KeyType is the algorithm (ed25519, rsa, ecdsa).
	KeyType SSHKeyType

	// Comment is the key comment (often user@host).
	Comment string

	// Encrypted indicates if the private key is password-protected.
	Encrypted bool
}

SSHKeyData contains SSH key information.

func NewSSHKeyData

func NewSSHKeyData(privateKey string, keyType SSHKeyType) *SSHKeyData

NewSSHKeyData creates an SSHKeyData with the given private key.

type SSHKeyType

type SSHKeyType string

SSHKeyType represents the type of SSH key.

const (
	// SSHKeyTypeEd25519 is an Ed25519 key.
	SSHKeyTypeEd25519 SSHKeyType = "ed25519"
	// SSHKeyTypeRSA is an RSA key.
	SSHKeyTypeRSA SSHKeyType = "rsa"
	// SSHKeyTypeECDSA is an ECDSA key.
	SSHKeyTypeECDSA SSHKeyType = "ecdsa"
	// SSHKeyTypeDSA is a DSA key (deprecated).
	SSHKeyTypeDSA SSHKeyType = "dsa"
)

type TOTPAlgorithm

type TOTPAlgorithm string

TOTPAlgorithm represents the hash algorithm used for TOTP.

const (
	// TOTPAlgorithmSHA1 is the SHA1 algorithm (default).
	TOTPAlgorithmSHA1 TOTPAlgorithm = "SHA1"
	// TOTPAlgorithmSHA256 is the SHA256 algorithm.
	TOTPAlgorithmSHA256 TOTPAlgorithm = "SHA256"
	// TOTPAlgorithmSHA512 is the SHA512 algorithm.
	TOTPAlgorithmSHA512 TOTPAlgorithm = "SHA512"
)

func (TOTPAlgorithm) String

func (a TOTPAlgorithm) String() string

String returns the lowercase string representation for CXF compatibility.

type TOTPData

type TOTPData struct {
	// Secret is the base32-encoded TOTP secret.
	Secret string

	// Algorithm is the hash algorithm (SHA1, SHA256, SHA512).
	Algorithm TOTPAlgorithm

	// Digits is the number of digits in the code (typically 6 or 8).
	Digits int

	// Period is the time step in seconds (typically 30).
	Period int

	// Issuer is the service that issued the TOTP.
	Issuer string

	// AccountName is the account identifier for the TOTP.
	AccountName string
}

TOTPData contains Time-based One-Time Password configuration.

func NewTOTPData

func NewTOTPData(secret string) *TOTPData

NewTOTPData creates a TOTPData with default values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL