mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-02 07:07:26 -04:00
Allow one-time copy of TOTP codes
This commit is contained in:
+5
-1
@@ -14,6 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CopyArgument copies a field from an entry to the clipboard.
|
// CopyArgument copies a field from an entry to the clipboard.
|
||||||
|
// If field is -1, it will not continuously update the clipboard (one-time copy).
|
||||||
func CopyArgument(targetLocation string, field int) error {
|
func CopyArgument(targetLocation string, field int) error {
|
||||||
// ensure targetLocation exists and is a file
|
// ensure targetLocation exists and is a file
|
||||||
_, err := back.TargetIsFile(targetLocation, true)
|
_, err := back.TargetIsFile(targetLocation, true)
|
||||||
@@ -35,7 +36,7 @@ func CopyArgument(targetLocation string, field int) error {
|
|||||||
return errors.New("field is empty")
|
return errors.New("field is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
if field != 2 {
|
if field != 2 && field != -1 {
|
||||||
copySubject = decryptedEntry[field]
|
copySubject = decryptedEntry[field]
|
||||||
} else { // TOTP mode
|
} else { // TOTP mode
|
||||||
var secret string // stores secret for TOTP generation
|
var secret string // stores secret for TOTP generation
|
||||||
@@ -60,6 +61,9 @@ func CopyArgument(targetLocation string, field int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if field == -1 {
|
||||||
|
return nil // return early (for interactive clients)
|
||||||
|
}
|
||||||
// sleep until next 30-second interval
|
// sleep until next 30-second interval
|
||||||
time.Sleep(time.Duration(30-(currentTime.Second()%30)) * time.Second)
|
time.Sleep(time.Duration(30-(currentTime.Second()%30)) * time.Second)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user