Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

eduncan911/safeincloud

Repository files navigation

GoDoc Build Status Coverage Status Go Report Card MIT License

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

database.go doc.go file.go parser.go

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 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(filenameAndPath string) (*Database, error)

ParseFile takes a filenameAndPath and returns a Database struct.

func ParseReader(r io.Reader) (*Database, error)

ParseReader takes an io.Reader and returns a Database struct.

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 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 (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 (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 struct {
    XMLName xml.Name `xml:"image"`
    // Value is Base64 encoded.
    Value []byte `xml:",chardata"`
}

Image represents a Card.Image.

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