safeincloud
Package safeincloud parses SafeInCloud's exported XML for use in GoLang.
It was originally intended to be used to help convert from SafeInCloud to another password manager such as my SafeInCloud-to-LastPass converter:
https://github.com/eduncan911/sic2lp
Convert to SafeInCloud
If you need this package to convert to SafeInCloud, open an Issue asking and I'll see what I can do. Currently, it needs some additional code for marshaling to enable attachments. Just that work was out of scope for me at this time.
Usage
This is a GoLang library package intended for import.
$ go get github.com/eduncan911/safeincloud
This package is setup for simple one-liners:
db, err := safeincloud.ParseFile("/path/to/exported/safeincloud.xml")
if err != nil {
panic(err)
}
for _, c := range db.Cards {
// do what you like with the Card
}
Examples
For several more examples, see the GoDocs with embedded examples:
https://godoc.org/github.com/eduncan911/safeincloud
Release Notes
1.0.0
- Initial release.
Table of Contents
Imported Packages
Index
Examples
Package files
database.go doc.go file.go parser.go
type Card
type Card struct {
XMLName xml.Name `xml:"card"`
ID string `xml:"id,attr"`
Title string `xml:"title,attr"`
Color string `xml:"color,attr"`
Symbol string `xml:"symbol,attr"`
Notes string `xml:"notes"`
Deleted bool `xml:"deleted,attr"`
Star bool `xml:"star,attr"`
Template bool `xml:"template,attr"`
Fields []Field `xml:"field"`
Images []Image `xml:"image"`
Files []File `xml:"file"`
// LabelIDs can be rogue in SafeInCloud, meaning there could be a
// number that doesn't exist as an actual label. So, we'll just
// store labels in Database.Labels instead for mapping.
LabelIDs []int `xml:"label_id"`
}
Card represents a global Card in the database.
type Database
type Database struct {
XMLName xml.Name `xml:"database"`
Cards []Card `xml:"card"`
Labels []Label `xml:"label"`
}
Database represents an SafeInCloud export.
This struct is not intended encompass an entire SafeInCloud export. It may not parse back into a functional SafeInCloud XML format. Instead, it is a subset of most the valuable fields and is intended to be used to convert to a new password manager.
Card history is also not captured with this version.
func ParseFile
func ParseFile(filenameAndPath string) (*Database, error)
ParseFile takes a filenameAndPath and returns a Database struct.
func ParseReader
func ParseReader(r io.Reader) (*Database, error)
ParseReader takes an io.Reader and returns a Database struct.
type Field
type Field struct {
XMLName xml.Name `xml:"field"`
Name string `xml:"name,attr"`
FieldType string `xml:"type,attr"`
Value string `xml:",chardata"`
}
Field represents a Card.Field.
type File
type File struct {
XMLName xml.Name `xml:"file"`
// Name is the file name as uploaded into SafeInCloud.
Name string `xml:"name,attr"`
// Value is the byte slice of the file's contents.
Value []byte
}
File represents a Card.File.
TODO: To make this library useful for creating SafeInCloud XML for importing into SIC, a MarshalXML() will need to be created to zlib compress and base64 encode the results. At the time of this writing, the library is only Unmarshalling to be used to move from SafeInCloud to something else.
func (*File) MarshalXML
func (f *File) MarshalXML(e *xml.Encoder, start xml.StartElement) error
MarshalXML is NOT IMPLEMENTED.
TODO: To make this library useful for creating SafeInCloud XML for importing into SIC, a MarshalXML() will need to be created to zlib compress and base64 encode the results. At the time of this writing, the library is only Unmarshalling to be used to move from SafeInCloud to something else.
func (*File) UnmarshalXML
func (f *File) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML will base64 decode and zlib decompress the file attachments to store in the File.Value []byte slice.
type Image
type Image struct {
XMLName xml.Name `xml:"image"`
// Value is Base64 encoded.
Value []byte `xml:",chardata"`
}
Image represents a Card.Image.
type Label
type Label struct {
XMLName xml.Name `xml:"label"`
ID int `xml:"id,attr"`
Name string `xml:"name,attr"`
}
Label represents a global Label in the database.
Generated by godoc2ghmd