// Initialize : setup a connection to the Enpass database. Call this before doing anything.
Initialize : setup a connection to the Enpass database. Call this before doing anything.
// Initialize : setup a connection to the Enpass database . Call this before doing anything .
func (v *Vault) Initialize(databasePath string, keyfilePath string, password string) error {
	if databasePath == "" {
		return errors.New("empty v path provided")
	}
	if password == "" {
		return errors.New("empty v password provided")
	}
	v.databaseFilename = filepath.Join(databasePath, vaultFileName)
	v.vaultInfoFilename = filepath.Join(databasePath, vaultInfoFileName)
	v.Logger.Debug("checking provided v paths")
	if err := v.checkPaths(); err != nil {
		return errors.Wrap(err, "invalid v path provided")
	}
	v.Logger.Debug("loading vault info")
	var err error
	v.vaultInfo, err = v.loadVaultInfo()
	if err != nil {
		return errors.Wrap(err, "could not load vault info")
	}
	v.Logger.
		WithField("db_path", vaultFileName).
		WithField("info_path", vaultInfoFileName).
		Debug("initialized paths")
	if keyfilePath == "" && v.vaultInfo.HasKeyfile == 1 {
		return errors.New("you should specify a keyfile")
	}
	if keyfilePath != "" && v.vaultInfo.HasKeyfile == 0 {
		return errors.New("you are specifying an unnecessary keyfile")
	}
	v.Logger.Debug("generating master password")
	masterPassword, err := v.generateMasterPassword([]byte(password), keyfilePath)
	if err != nil {
		return errors.Wrap(err, "could not generate v unlock key")
	}
	v.Logger.Debug("extracting salt from database")
	keySalt, err := v.extractSalt()
	if err != nil {
		return errors.Wrap(err, "could not get master password salt")
	}
	v.Logger.Debug("deriving decryption key")
	fullKey, err := v.deriveKey(masterPassword, keySalt)
	if err != nil {
		return errors.Wrap(err, "could not derive master key from master password")
	}
	v.Logger.Debug("opening encrypted database")
	if err := v.openEncryptedDatabase(v.databaseFilename, fullKey); err != nil {
		return errors.Wrap(err, "could not open encrypted database")
	}
	return nil
}
func ( v * Vault ) Initialize ( databasePath string , keyfilePath string , password string ) error { if databasePath == " " { return errors . New ( " " ) } if password == " " { return errors . New ( " " ) } v . databaseFilename = filepath . Join ( databasePath , vaultFileName ) v . vaultInfoFilename = filepath . Join ( databasePath , vaultInfoFileName ) v . Logger . Debug ( " " ) if err := v . checkPaths ( ) ; err != nil { return errors . Wrap ( err , " " ) } v . Logger . Debug ( " " ) var err error v . vaultInfo , err = v . loadVaultInfo ( ) if err != nil { return errors . Wrap ( err , " " ) } v . Logger . WithField ( " " , vaultFileName ) . WithField ( " " , vaultInfoFileName ) . Debug ( " " ) if keyfilePath == " " && v . vaultInfo . HasKeyfile == 1 { return errors . New ( " " ) } if keyfilePath != " " && v . vaultInfo . HasKeyfile == 0 { return errors . New ( " " ) } v . Logger . Debug ( " " ) masterPassword , err := v . generateMasterPassword ( [ ] byte ( password ) , keyfilePath ) if err != nil { return errors . Wrap ( err , " " ) } v . Logger . Debug ( " " ) keySalt , err := v . extractSalt ( ) if err != nil { return errors . Wrap ( err , " " ) } v . Logger . Debug ( " " ) fullKey , err := v . deriveKey ( masterPassword , keySalt ) if err != nil { return errors . Wrap ( err , " " ) } v . Logger . Debug ( " " ) if err := v . openEncryptedDatabase ( v . databaseFilename , fullKey ) ; err != nil { return errors . Wrap ( err , " " ) } return nil }
Initialize : setup a connection to the Enpass database.
Initialize : setup a connection to the Enpass database .