Documentation ¶
Overview ¶
Package kflib is a support library for the KeyFish tool.
Index ¶
- Variables
- func ConfirmPassphrase(prompt string) (string, error)
- func Edit[T any](ctx context.Context, value T) (T, error)
- func GenerateHashpass(db *kfdb.DB, rec *kfdb.Record, tag string) (string, error)
- func GenerateOTP(url *otpauth.URL, offset int) (string, error)
- func GetPassphrase(prompt string) (string, error)
- func HashedChars(length int, charset Charset, passphrase, seed, salt string) string
- func OpenDB(dbPath string) (*kfdb.Store, error)
- func OpenDBWithPassphrase(dbPath, passphrase string) (*kfdb.Store, error)
- func RandomChars(length int, charset Charset) string
- func RandomWords(numWords int, joiner string) string
- func SaveDB(s *kfdb.Store, dbPath string) error
- type Charset
- type DBWatcher
- type FindResult
- type FoundRecord
- type MatchQuality
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoChange is reported by Edit if the resulting value did not change. ErrNoChange = errors.New("input was not changed") // ErrUserReject is reported by Edit if the user rejected the changed file. ErrUserReject = errors.New("the user rejected the edits") )
Functions ¶
func ConfirmPassphrase ¶
ConfirmPassphrase prompts the user at the terminal for a passphrase with echo disabled, then prompts again for confirmation and reports an error if the two copies are not equal.
func Edit ¶
Edit invokes an editor with the specified object rendered as YAML. The editor is selected by the EDITOR environment variable. When the editor exits, the user is prompted to confirm any changes. If they do, the results are unmarshaled back into a new value, which is returned; otherwise an error is reported.
If the edit did not change the input, Edit returns (value, ErrNoChange). If the user rejected the changes, Edit returns (value, ErrUserReject).
func GenerateHashpass ¶ added in v0.1.1
GenerateHashpass hashpass password for the specified record in the given database. It reports an error if no hashpass secret is available. will be
func GenerateOTP ¶
GenerateOTP returns a TOTP code based on url. The time code is shifted by offset steps (based on the size of the window specified by url).
func GetPassphrase ¶
GetPassphrase prompts the user at the terminal for a passphrase with echo disabled. An empty passprase is permitted; the caller must check for that case if an empty passphrase is not wanted.
func HashedChars ¶ added in v0.1.1
HashedChars creates a new HKDF password of the given length using the specified character types. A minimum length of 8 is enforced.
The passphrase is a strong secret passphrase. The seed is not secret, but must be fixed for a given context. The salt is optional, if non-empty it is mixed in to the HKDF as additional context.
func OpenDBWithPassphrase ¶ added in v0.1.3
OpenDBWithPassphrase opens the specified database store using the provided access key passphrase instead of prompting at the terminal.
func RandomChars ¶
RandomChars creates a new randomly-generated password of the given length and using the specified character types. A minimum length of 8 is enforced.
func RandomWords ¶
RandomWords creates a new randomly-generated password comprising the specified number of wordlist entries. The words are separated by the specified joiner. A minimum of 3 words is enforced.
Types ¶
type Charset ¶
type Charset int
Charset is a bit mask specifying which letters to use in a character-based password. A Charset always includes letters.
const ( // Letters denotes the capital and lowercase ASCII English letters. Letters Charset = 0 // Digits denotes the set of ASCII decimal digits. Digits Charset = 1 // Symbols denotes a set of ASCII punctuation symbols. Symbols Charset = 2 // AllChars denotes a combination of letters, digits, and symbols. AllChars = Letters | Digits | Symbols )
type DBWatcher ¶
type DBWatcher struct {
// contains filtered or unexported fields
}
DBWatcher is a database connected with a file path watcher, that reloads the file when it is modified.
func NewDBWatcher ¶ added in v0.1.3
NewDBWatcher creates a watcher that automatically reloads the specified store from its original path when that path is modified.
type FindResult ¶
type FindResult struct { Tag string // the tag from the query, if present Index int // offset of the record in the database Record *kfdb.Record // the record matched by the label }
FindResult is the result of a successful call to FindRecord.
func FindRecord ¶
FindRecord finds the unique record matching the specified query. An exact match for a label is preferred; otherwise FindRecord will look for a full or partial match on host names, or other substrings in the title and notes. An error is reported if query matches no records, or more than 1. If all is true, all records are considered; otherwise archived records are skipped.
If the query begins with a tag (tag@label), the tag is removed and returned along with the result.
type FoundRecord ¶
type FoundRecord struct { Quality MatchQuality `json:"quality"` // how this record was matched Index int `json:"index"` // the index of the record in the database Record *kfdb.Record `json:"record"` // the record itself }
FoundRecord is a single record reported by FindRecords.
func FindRecords ¶
func FindRecords(recs []*kfdb.Record, query string) []FoundRecord
FindRecords finds candidate records matching the specified query. If the query begins with a tag (tag@label), the tag is removed. Results are returned in order of quality from highest to lowest, with ties broken by index.
func PickBest ¶ added in v0.2.0
func PickBest(found []FoundRecord) (FoundRecord, bool)
PickBest reports whether there is a unique "best" match in a slice of found records, and if so returns that specific record. The records must be ordered in decreasing order of match quality.
type MatchQuality ¶
type MatchQuality int
MatchQuality indicates how good a match a query is for a record.
const ( // MatchNone means the query does not match the record at all. MatchNone MatchQuality = iota // MatchLabel means the query matches the record's label. MatchLabel // MatchHost means the query is an exact host match for the record. MatchHost // MatchHostPartial means the query is a partial host match for the record. MatchHostPartial // MatchTitle means the query is a case-insensitive substring match for the // title or label of the record. MatchTitle // MatchDetail means the query is a case-insensitive substring match for the // label of one of the details of the record. MatchDetail // MatchSubstring means the query is a case-insensitive substring match for // one of the text fields or host entries of the record. MatchSubstring )
func MatchRecord ¶
func MatchRecord(query string, r *kfdb.Record) MatchQuality
MatchRecord reports how good a match query is for the specified record.