Documentation
¶
Index ¶
- Variables
- type Collection
- func (c *Collection) DeleteSecret(name string) (Secret, error)
- func (c *Collection) Deserialize(data []byte) error
- func (c *Collection) GenerateCode(name string) (string, error)
- func (c *Collection) GenerateCodeWithTime(name string, time time.Time) (string, error)
- func (c *Collection) GetSecret(name string) (Secret, error)
- func (c *Collection) GetSecrets() []Secret
- func (c *Collection) RenameSecret(oldName, newName string) (Secret, error)
- func (c *Collection) Save() error
- func (c *Collection) Serialize() ([]byte, error)
- func (c *Collection) SetFilename(filename string) string
- func (c *Collection) SetWriter(writer io.Writer)
- func (c *Collection) UpdateSecret(name, value string) (Secret, error)
- type CollectionInterface
- type Secret
Constants ¶
This section is empty.
Variables ¶
var ErrNoFilename = errors.New("no save target")
var ErrSecretNameEmpty = errors.New("secret name empty")
var ErrSecretNotFound = errors.New("secret not found")
var ErrSecretValueEmpty = errors.New("secret value empty")
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection struct { // Secrets is a map of secrets using the secret name as the key Secrets map[string]Secret // contains filtered or unexported fields }
Collection is a struct that holds TOTP data
func NewCollection ¶
func NewCollection() *Collection
NewCollection creates a new, blank Collection instance
func NewCollectionWithData ¶
func NewCollectionWithData(data []byte) (*Collection, error)
NewCollectionWithData creates a new Collection instance with data from a byte slice
func NewCollectionWithFile ¶
func NewCollectionWithFile(filename string) (c *Collection, err error)
NewCollectionWithFile creates a new Collection instance with data from a file. If the file open fails, a new Collection instance is returned along with the file open error, which guarantees a usable but empty collection is returned.
Returning data to be used along with an error is bad design but changing this would be a breaking API change.
func NewCollectionWithReader ¶
func NewCollectionWithReader(reader io.Reader) (*Collection, error)
NewCollectionWithReader creates a new collection from a Reader interface
func (*Collection) DeleteSecret ¶
func (c *Collection) DeleteSecret(name string) (Secret, error)
DeleteSecret deletes an entry by name
func (*Collection) Deserialize ¶
func (c *Collection) Deserialize(data []byte) error
Deserialize unmarshals a byte array into a Collection struct
func (*Collection) GenerateCode ¶
func (c *Collection) GenerateCode(name string) (string, error)
GenerateCode creates a TOTP code with the named secret's value
func (*Collection) GenerateCodeWithTime ¶
GenerateCodeWithTime creates a TOTP code with the named secret's value
func (*Collection) GetSecret ¶
func (c *Collection) GetSecret(name string) (Secret, error)
GetSecret returns a secret with the name argument
func (*Collection) GetSecrets ¶
func (c *Collection) GetSecrets() []Secret
GetSecrets returns a slice containing all the secrets
func (*Collection) RenameSecret ¶
func (c *Collection) RenameSecret(oldName, newName string) (Secret, error)
RenameSecret renames a secret
func (*Collection) Save ¶
func (c *Collection) Save() error
Save serializes (marshals) the Collections struct and writes it to a file
func (*Collection) Serialize ¶
func (c *Collection) Serialize() ([]byte, error)
Serialize marshals the Collection struct into a byte array
func (*Collection) SetFilename ¶
func (c *Collection) SetFilename(filename string) string
SetFilename sets the filename for the Save method
func (*Collection) SetWriter ¶
func (c *Collection) SetWriter(writer io.Writer)
SetWriter sets the writer for the Save method
func (*Collection) UpdateSecret ¶
func (c *Collection) UpdateSecret(name, value string) (Secret, error)
UpdateSecret updates (if it exists) or adds a new entry with the name and value given
type CollectionInterface ¶
type CollectionInterface interface { DeleteSecret(string) (Secret, error) GetSecret(string) (Secret, error) GetSecrets() []Secret Save() error SetFilename(string) string UpdateSecret(string, string) (Secret, error) }
CollectionInterface is used for DI when needed
type Secret ¶
type Secret struct { // DateAdded is the date a secret was added to the collection DateAdded time.Time // DateModified is the date a secret was last modified DateModified time.Time // Name is the name of the secret used for retrieval Name string // Value is the secret (seed) value Value string }
Secret is a struct containing data necessary for working with secrets, namely, the name of the secret name and the secret value