v1.0.0: lint: remove io/utils
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
7588000af4
commit
15b9d0c2e3
1 changed files with 53 additions and 22 deletions
|
|
@ -4,7 +4,6 @@ import (
|
|||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -19,21 +18,51 @@ func InitLoginBiscuit() error {
|
|||
if _, err := os.Stat(filePrivateKey); os.IsNotExist(err) {
|
||||
rng := rand.Reader
|
||||
PublicKey, PrivateKey, _ = ed25519.GenerateKey(rng)
|
||||
if err := ioutil.WriteFile(filePrivateKey, PrivateKey, 0600); err != nil {
|
||||
|
||||
if file, err := os.Create(filePrivateKey); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer file.Close()
|
||||
|
||||
if _, err = io.WriteString(file, string(PrivateKey)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := file.Chmod(0600); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := ioutil.WriteFile(filePublicKey, PublicKey, 0600); err != nil {
|
||||
if file, err := os.Create(filePublicKey); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer file.Close()
|
||||
|
||||
if _, err = io.WriteString(file, string(PublicKey)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := file.Chmod(0600); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
PrivateKey, err = ioutil.ReadFile(filePrivateKey)
|
||||
if err != nil {
|
||||
if file, err := os.Open(filePrivateKey); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer file.Close()
|
||||
|
||||
PrivateKey, err = io.ReadAll(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
PublicKey, err = ioutil.ReadFile(filePublicKey)
|
||||
if err != nil {
|
||||
if file, err := os.Open(filePublicKey); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer file.Close()
|
||||
|
||||
PublicKey, err = io.ReadAll(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
@ -54,23 +83,25 @@ func InitGlobalBiscuit() error {
|
|||
break
|
||||
}
|
||||
}
|
||||
file, err := os.Open(filePrivateKey)
|
||||
if err != nil {
|
||||
if file, err := os.Open(filePrivateKey); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer file.Close()
|
||||
|
||||
PrivateKey, err = io.ReadAll(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
defer file.Close()
|
||||
PrivateKey, err = io.ReadAll(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file, err = os.Open(filePublicKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
PublicKey, err = io.ReadAll(file)
|
||||
if err != nil {
|
||||
if file, err := os.Open(filePublicKey); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer file.Close()
|
||||
|
||||
PublicKey, err = io.ReadAll(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue