aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-18 21:44:09 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-18 21:44:09 +0200
commit4fbfd1286c60f1041f706355addddf3edb9ed81f (patch)
tree7a6665f5493ff54dfcfcafaff71c2f6c93ed167f
parent1f6f9ea5c7e59ee711892a800562b57b3c105a7a (diff)
...
-rw-r--r--file.go11
-rw-r--r--gen.go5
2 files changed, 10 insertions, 6 deletions
diff --git a/file.go b/file.go
index c0d60ea..6bff903 100644
--- a/file.go
+++ b/file.go
@@ -21,18 +21,21 @@ type File struct {
const (
commentHdr = "untrusted comment:"
verifyWith = "verify with"
- pubKey = "%s public key"
- secKey = "%s secret key"
sigFrom = "signature from %s"
)
+var (
+ ErrCommentSize = errors.New("comment line to long")
+ ErrUntrustedComment = errors.New("expected untrusted comment")
+)
+
func checkComment(comment string) error {
// compatibility with original version
if len(comment) > 1024 {
- return errors.New("comment line to long")
+ return ErrCommentSize
}
if !strings.HasPrefix(comment, commentHdr) {
- return errors.New("expected untrusted comment")
+ return ErrUntrustedComment
}
return nil
}
diff --git a/gen.go b/gen.go
index da93282..40367de 100644
--- a/gen.go
+++ b/gen.go
@@ -4,6 +4,7 @@ import (
"crypto/rand"
"crypto/sha512"
"encoding/binary"
+ "fmt"
"golang.org/x/crypto/ed25519"
)
@@ -56,7 +57,7 @@ func Generate(pubkeyfile, seckeyfile, comment string, rounds int) error {
}
sfile := File{
- Comment: comment + " secret key",
+ Comment: fmt.Sprintf("%s secret key", comment),
RawKey: sb64,
}
if err := sfile.WriteFile(seckeyfile, SecMode); err != nil {
@@ -68,7 +69,7 @@ func Generate(pubkeyfile, seckeyfile, comment string, rounds int) error {
return err
}
pfile := File{
- Comment: comment + " public key",
+ Comment: fmt.Sprintf("%s public key", comment),
RawKey: pb64,
}
if err := pfile.WriteFile(pubkeyfile, PubMode); err != nil {