safeincloud

package module
v0.0.0-...-6dc3176 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2017 License: MIT Imports: 7 Imported by: 0

README

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

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

Documentation

Overview

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.

Example
package main

import (
	"fmt"

	"github.com/eduncan911/safeincloud"
)

func main() {

	// using SafeInCloud is a simple 1 liner.
	db, err := safeincloud.ParseFile("testdata/safeincloud.xml")

	// all errors are wrapped with full stack trace
	if err != nil {
		fmt.Printf("%+v", err)
		return
	}

	// use the returned safeincloud.Database struct as you like.
	fields, deleted, templates, stars := 0, 0, 0, 0
	for _, c := range db.Cards {
		fields = fields + len(c.Fields)
		if c.Deleted {
			deleted++
		}
		if c.Template {
			templates++
		}
		if c.Star {
			stars++
		}
	}
	fmt.Println("Total Cards:", len(db.Cards), "Fields:", fields, "Labels:", len(db.Labels))
	fmt.Println("Deleted:", deleted, "Template:", templates, "Stars:", stars)
}
Output:

Total Cards: 19 Fields: 61 Labels: 7
Deleted: 1 Template: 8 Stars: 2

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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.

Example
package main

import (
	"fmt"

	"github.com/eduncan911/safeincloud"
)

func main() {

	// using SafeInCloud is a simple 1 liner.
	db, err := safeincloud.ParseFile("testdata/safeincloud.xml")
	if err != nil {
		fmt.Printf("%+v", err)
		return
	}

	// iterate and pull out data
	var files []safeincloud.File
	var images []safeincloud.Image
	for _, c := range db.Cards {
		if len(c.Files) != 0 {
			for _, f := range c.Files {
				files = append(files, f)
			}
		}
		if len(c.Images) != 0 {
			for _, i := range c.Images {
				images = append(images, i)
			}
		}
	}
	fmt.Println("Total Files:", len(files), "Images:", len(images))
}
Output:

Total Files: 1 Images: 1

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.

Jump to

Keyboard shortcuts

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