Files
go-proton-api/server/keys.go
2022-11-23 12:03:04 +01:00

38 lines
800 B
Go

package server
import (
"net/http"
"github.com/ProtonMail/go-proton-api"
"github.com/gin-gonic/gin"
)
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,
})
}
}