aboutsummaryrefslogtreecommitdiff
path: root/db/pem.go
diff options
context:
space:
mode:
authorKushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com>2021-10-30 00:28:51 -0300
committerFChannel <>2022-06-19 12:53:29 -0700
commit8040825daac4a5ba24e947c4c657d169d7763543 (patch)
tree667058707ab1c2b2af5dc01decda25cc7709f9df /db/pem.go
parentf76b8093b9ca69c7d4eca747d8c5d702d492e1fb (diff)
restructuring, part 3 of many
Diffstat (limited to 'db/pem.go')
-rw-r--r--db/pem.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/db/pem.go b/db/pem.go
new file mode 100644
index 0000000..d9bcee2
--- /dev/null
+++ b/db/pem.go
@@ -0,0 +1,48 @@
+package db
+
+import (
+ "os"
+ "strings"
+
+ "github.com/FChannel0/FChannel-Server/activitypub"
+)
+
+func GetActorPemFromDB(pemID string) (activitypub.PublicKeyPem, error) {
+ var pem activitypub.PublicKeyPem
+
+ query := `select id, owner, file from publickeypem where id=$1`
+
+ rows, err := db.Query(query, pemID)
+ if err != nil {
+ return pem, err
+ }
+
+ defer rows.Close()
+
+ rows.Next()
+ rows.Scan(&pem.Id, &pem.Owner, &pem.PublicKeyPem)
+ f, err := os.ReadFile(pem.PublicKeyPem)
+ if err != nil {
+ return pem, err
+ }
+
+ pem.PublicKeyPem = strings.ReplaceAll(string(f), "\r\n", `\n`)
+
+ return pem, nil
+}
+
+func GetActorPemFileFromDB(pemID string) (string, error) {
+ query := `select file from publickeypem where id=$1`
+ rows, err := db.Query(query, pemID)
+ if err != nil {
+ return "", err
+ }
+
+ defer rows.Close()
+
+ var file string
+ rows.Next()
+ rows.Scan(&file)
+
+ return file, nil
+}