File: keys.go

package info (click to toggle)
golang-github-henrybear327-go-proton-api 1.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,088 kB
  • sloc: sh: 55; makefile: 26
file content (37 lines) | stat: -rw-r--r-- 802 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package server

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/henrybear327/go-proton-api"
)

func (s *Server) handleGetKeys() gin.HandlerFunc {
	return func(c *gin.Context) {
		if pubKeys, err := s.b.GetPublicKeys(c.Query("Email")); err == nil && len(pubKeys) > 0 {
			c.JSON(http.StatusOK, gin.H{
				"Keys":          pubKeys,
				"RecipientType": proton.RecipientTypeInternal,
			})
		} else {
			c.JSON(http.StatusOK, gin.H{
				"RecipientType": proton.RecipientTypeExternal,
			})
		}
	}
}

func (s *Server) handleGetKeySalts() gin.HandlerFunc {
	return func(c *gin.Context) {
		salts, err := s.b.GetKeySalts(c.GetString("UserID"))
		if err != nil {
			c.AbortWithStatus(http.StatusInternalServerError)
			return
		}

		c.JSON(http.StatusOK, gin.H{
			"KeySalts": salts,
		})
	}
}