parser

package
v0.0.0-...-00a43c6 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unparse

func Unparse(d *Document, key [32]byte) ([]byte, error)

Types

type Association

type Association struct {
	Window            string
	KeystrokeSequence string
}

type AutoType

type AutoType struct {
	Enabled                 wrappers.Bool
	DataTransferObfuscation int
	Association             *Association `xml:",omitempty"`
}

type Binary

type Binary struct {
	XMLName  xml.Name `xml:"Binary"`
	ID       int      `xml:"ID,attr"`
	Chardata string   `xml:",chardata"`
}

type BinaryReference

type BinaryReference struct {
	Key       string
	Reference BinaryReferenceValue `xml:"Value"`
}

type BinaryReferenceValue

type BinaryReferenceValue struct {
	ID int `xml:"Ref,attr"`
}

type CustomData

type CustomData struct {
	Inner string `xml:",innerxml"`
}

type DeletedObject

type DeletedObject struct {
	UUID         string
	DeletionTime time.Time
}

type Document

type Document struct {
	XMLName xml.Name `xml:"KeePassFile"`
	Meta    Meta
	Root    Root
}

func NewDocument

func NewDocument() *Document

func Parse

func Parse(b []byte, innerRandomStreamKey [32]byte) (*Document, error)

func (*Document) FindPath

func (d *Document) FindPath(uuid string) ([]string, bool)

FindPath returns the path to an item with the given UUID if it exists, and a bool indicating wether the UUID was found.

func (*Document) GetBinary

func (d *Document) GetBinary(id int) ([]byte, error)

func (*Document) GetItem

func (d *Document) GetItem(path []string) (Item, error)

GetItem returns a group or an item specified by a path of UUIDs. The document is traversed, at each level choosing the group with UUID at the current index, until the end of the path is reached. The last UUID may be that of an item. For an empty path the function will return the top-level groups (which is just one group for most KeePass files)

func (*Document) UpdateEntry

func (d *Document) UpdateEntry(newEntry Entry) bool

type Entry

type Entry struct {
	XMLName         xml.Name `xml:"Entry"`
	UUID            string
	IconID          int
	ForegroundColor string
	BackgroundColor string
	OverrideURL     string
	Tags            string
	Times           Times
	Strings         []String          `xml:"String"`
	BinaryRefs      []BinaryReference `xml:"Binary"`
	AutoType        AutoType
	// History must be pointer to slice in order for omitempty to work for nested elements
	History *[]Entry `xml:"History>Entry,omitempty"`
}

func (Entry) CopyMeta

func (e Entry) CopyMeta() Item

func (*Entry) DeleteField

func (e *Entry) DeleteField(key string) bool

UpdateField deletes the field with the given key, if it exists Returns true if a change was made, false otherwise

func (*Entry) Get

func (e *Entry) Get(key string) (wrappers.Value, error)

func (Entry) GetUUID

func (e Entry) GetUUID() string

func (*Entry) TryGet

func (e *Entry) TryGet(key, fallback string) string

TryGet returns the value for the given key if it exists, fallback otherwise

func (*Entry) UpdateField

func (e *Entry) UpdateField(key, value string) bool

UpdateField updates the field with the given key to the given value, if it exists Returns true if a change was made, false otherwise

type Group

type Group struct {
	XMLName                 xml.Name `xml:"Group"`
	UUID                    string
	Name                    string
	Notes                   string
	IconID                  int
	Times                   Times
	IsExpanded              wrappers.Bool
	DefaultAutoTypeSequence string
	EnableAutoType          wrappers.Bool
	EnableSearching         wrappers.Bool
	LastTopVisibleEntry     string
	Entries                 []Entry `xml:"Entry"`
	Groups                  []Group `xml:"Group"`
}

func (Group) CopyMeta

func (g Group) CopyMeta() Item

func (*Group) Get

func (g *Group) Get(uuid string) (Item, error)

func (Group) GetUUID

func (g Group) GetUUID() string

func (*Group) UpdateEntry

func (g *Group) UpdateEntry(newEntry Entry) bool

type Item

type Item interface {
	GetUUID() string
	// Performs a 'shallow copy', only copying metadata such as name, UUID, etc. but not subgroups, entries, history etc.
	CopyMeta() Item
}

type MemoryProtection

type MemoryProtection struct {
	XMLName         xml.Name `xml:"MemoryProtection"`
	ProtectTitle    wrappers.Bool
	ProtectUserName wrappers.Bool
	ProtectPassword wrappers.Bool
	ProtectURL      wrappers.Bool
	ProtectNotes    wrappers.Bool
}

type Meta

type Meta struct {
	XMLName                    xml.Name `xml:"Meta"`
	Generator                  string
	HeaderHash                 string
	DatabaseName               string
	DatabaseNameChanged        time.Time
	DatabaseDescription        string
	DatabaseDescriptionChanged time.Time
	DefaultUserName            string
	DefaultUserNameChanged     time.Time
	MaintenanceHistoryDays     int
	Color                      string
	MasterKeyChanged           time.Time
	MasterKeyChangeRec         int
	MasterKeyChangeForce       int
	MemoryProtection           MemoryProtection
	RecycleBinEnabled          wrappers.Bool
	RecycleBinUUID             string
	RecycleBinChanged          time.Time
	EntryTemplatesGroup        string
	EntryTemplatesGroupChanged time.Time
	HistoryMaxItems            int
	HistoryMaxSize             int
	LastSelectedGroup          string
	LastTopVisibleGroup        string
	Binaries                   []Binary `xml:"Binaries>Binary"`
	CustomData                 CustomData
}

type PathNotFound

type PathNotFound error

type Root

type Root struct {
	XMLName        xml.Name        `xml:"Root"`
	Groups         []Group         `xml:"Group"`
	DeletedObjects []DeletedObject `xml:"DeletedObjects>DeletedObject"`
}

type String

type String struct {
	XMLName xml.Name `xml:"String"`
	Key     string
	Value   wrappers.Value
}

type Times

type Times struct {
	CreationTime         time.Time
	LastModificationTime time.Time
	LastAccessTime       time.Time
	ExpiryTime           time.Time
	Expires              wrappers.Bool
	UsageCount           int
	LocationChanged      time.Time
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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