diff options
Diffstat (limited to 'db/pem.go')
-rw-r--r-- | db/pem.go | 48 |
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 +} |