remove useless identity package

This commit is contained in:
Lilian Jónsdóttir 2024-05-29 13:06:27 -07:00
parent 89006797fa
commit 5c660f013b
2 changed files with 0 additions and 71 deletions

View file

@ -8,7 +8,6 @@ import (
"filippo.io/age"
"git.burning.moe/celediel/agedit/pkg/decrypt"
"git.burning.moe/celediel/agedit/pkg/encrypt"
"git.burning.moe/celediel/agedit/pkg/identity"
"git.burning.moe/celediel/agedit/pkg/tmpfile"
)
@ -142,30 +141,3 @@ func TestMultipleIdentities(t *testing.T) {
})
}
}
// TestNewIdentity creats a new identity, writes it to file, then re-reads it back from the file.
func TestNewIdentity(t *testing.T) {
for range 1000 {
outfile := generator.GenerateFullPath()
id, err := identity.NewIdentity()
if err != nil {
t.Fatal(err)
}
err = identity.WriteIdentityToFile(id, outfile)
if err != nil {
t.Fatal(err)
}
other_identity, err := identity.ReadIdentityFromFile(outfile)
if err != nil {
t.Fatal(err)
}
if id.Recipient().String() != other_identity.Recipient().String() && id.String() != other_identity.String() {
t.Fatal("Identities don't match!", id.Recipient(), "!=", id.Recipient())
}
os.Remove(outfile)
}
}

View file

@ -1,43 +0,0 @@
package identity
import (
"io/fs"
"os"
"filippo.io/age"
)
// NewIdentity generates a new Age identity
func NewIdentity() (*age.X25519Identity, error) {
id, err := age.GenerateX25519Identity()
if err != nil {
return nil, err
}
return id, nil
}
// ReadIdentityFromFile reads the identity from the supplied filename
func ReadIdentityFromFile(filename string) (*age.X25519Identity, error) {
bytes, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
id, err := age.ParseX25519Identity(string(bytes))
if err != nil {
return nil, err
}
return id, nil
}
// WriteIdentityToFile writes the supplied identity to the supplied filename
func WriteIdentityToFile(id *age.X25519Identity, filename string) error {
err := os.WriteFile(filename, []byte(id.String()), fs.FileMode(0600))
if err != nil {
return err
}
return nil
}