commit 01c6023638fd7a161fd23f1abdb842aad4508550
parent 18943a6fddf7dfcaf4a573af453fbe78f4661b43
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 27 Jan 2023 22:48:10 -0800
cleanup
Diffstat:
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
@@ -408,14 +408,18 @@ func getGCMKeyBytes(keyBytes []byte) (cipher.AEAD, int, error) {
func GetKeyFingerprint(pkey string) string {
if e := GetEntityFromPKey(pkey); e != nil {
- fp := strings.ToUpper(hex.EncodeToString(e.PrimaryKey.Fingerprint))
- return fmt.Sprintf("%s %s %s %s %s %s %s %s %s %s",
- fp[0:4], fp[4:8], fp[8:12], fp[12:16], fp[16:20],
- fp[20:24], fp[24:28], fp[28:32], fp[32:36], fp[36:40])
+ return FormatPgPFingerprint(e.PrimaryKey.Fingerprint)
}
return ""
}
+func FormatPgPFingerprint(fpBytes []byte) string {
+ fp := strings.ToUpper(hex.EncodeToString(fpBytes))
+ return fmt.Sprintf("%s %s %s %s %s %s %s %s %s %s",
+ fp[0:4], fp[4:8], fp[8:12], fp[12:16], fp[16:20],
+ fp[20:24], fp[24:28], fp[28:32], fp[32:36], fp[36:40])
+}
+
func PgpCheckClearSignMessage(pkey, msg string) bool {
keyring, err := openpgp.ReadArmoredKeyRing(strings.NewReader(pkey))
if err != nil {
diff --git a/pkg/web/handlers/api/v1/slashInterceptor.go b/pkg/web/handlers/api/v1/slashInterceptor.go
@@ -7,7 +7,6 @@ import (
dutils "dkforest/pkg/database/utils"
"dkforest/pkg/managers"
"dkforest/pkg/utils"
- "encoding/hex"
"errors"
"fmt"
"github.com/ProtonMail/go-crypto/openpgp/clearsign"
@@ -974,10 +973,7 @@ func handlePm0(c *Command, msg string) (handled bool) {
if b, _ := clearsign.Decode(by); b != nil {
if p, err := packet.Read(b.ArmoredSignature.Body); err == nil {
if sig, ok := p.(*packet.Signature); ok {
- fp := strings.ToUpper(hex.EncodeToString(sig.IssuerFingerprint))
- fpFmt := fmt.Sprintf("%s %s %s %s %s %s %s %s %s %s",
- fp[0:4], fp[4:8], fp[8:12], fp[12:16], fp[16:20],
- fp[20:24], fp[24:28], fp[28:32], fp[32:36], fp[36:40])
+ fp := utils.FormatPgPFingerprint(sig.IssuerFingerprint)
msg := fmt.Sprintf("<br />"+
"File: %s (%s)<br />"+
"Signature made: %s<br />"+
@@ -986,7 +982,7 @@ func handlePm0(c *Command, msg string) (handled bool) {
c.upload.OrigFileName,
humanize.Bytes(uint64(c.upload.FileSize)),
sig.CreationTime.Format(time.RFC1123),
- fpFmt,
+ fp,
utils.Ternary(sig.SignerUserId != nil, *sig.SignerUserId, "n/a"))
c.zeroMsg(msg)
c.err = ErrRedirect