mirror of
https://github.com/go-i2p/i2pkeys.git
synced 2025-06-09 09:32:58 -04:00
Make LoadKeys() create new keys if the keyfile doesn't exist
This commit is contained in:
16
I2PAddr.go
16
I2PAddr.go
@ -87,8 +87,20 @@ func LoadKeys(r string) (I2PKeys, error) {
|
||||
return I2PKeys{}, err
|
||||
}
|
||||
if !exists {
|
||||
log.WithError(err).Error("File does not exist")
|
||||
return I2PKeys{}, os.ErrNotExist
|
||||
// File doesn't exist so we'll generate new keys
|
||||
log.WithError(err).Debug("File does not exist, attempting to generate new keys")
|
||||
k, err := NewDestination()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Error generating new keys")
|
||||
return I2PKeys{}, err
|
||||
}
|
||||
// Save the new keys to the file
|
||||
err = StoreKeys(*k, r)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Error saving new keys to file")
|
||||
return I2PKeys{}, err
|
||||
}
|
||||
return *k, nil
|
||||
}
|
||||
fi, err := os.Open(r)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user