Esempio n. 1
0
func openDb(t *testing.T) *sqlite_db.Db {
	conn, err := sqlite.Open(":memory:")
	if err != nil {
		t.Fatalf("Error opening database: %v", err)
	}
	db := sqlite_db.New(conn)
	err = db.Do(func(conn *sqlite.Conn) error {
		return sqlite_setup.SetUpTables(conn)
	})
	if err != nil {
		t.Fatalf("Error creating tables: %v", err)
	}
	return db
}
Esempio n. 2
0
func main() {
	flag.Parse()
	if fDb == "" || fName == "" || fPassword == "" {
		fmt.Println("Need to specify -db, -name, and -password flag.")
		flag.Usage()
		return
	}
	conn, err := sqlite.Open(fDb)
	if err != nil {
		fmt.Printf("Unable to open database - %s\n", fDb)
		return
	}
	dbase := sqlite_db.New(conn)
	defer dbase.Close()
	err = dbase.Do(func(conn *sqlite.Conn) error {
		return sqlite_setup.SetUpTables(conn)
	})
	if err != nil {
		fmt.Printf("Unable to create tables - %v\n", err)
		return
	}
	store := for_sqlite.New(dbase)
	var user vsafe.User
	if fMasterName == "" {
		err = user.Init(fName, fPassword)
	} else {
		var master vsafe.User
		if err = store.UserByName(nil, fMasterName, &master); err != nil {
			fmt.Printf("Error retrieving master user - %v\n", err)
			return
		}
		var key *vsafe.Key
		if key, err = master.VerifyPassword(fMasterPassword); err != nil {
			fmt.Printf("Error verifying master password - %v\n", err)
			return
		}
		err = user.InitWithKey(fName, fPassword, key)
	}
	if err != nil {
		fmt.Printf("Error initializing user - %v\n", err)
		return
	}
	if err = store.AddUser(nil, &user); err != nil {
		fmt.Printf("Error storing user in database - %v\n", err)
		return
	}
}