(c *gin.Context)
| 27 | ) |
| 28 | |
| 29 | func genKeyPair(c *gin.Context) { |
| 30 | r := struct { |
| 31 | Password string `json:"password" form:"password"` |
| 32 | }{} |
| 33 | |
| 34 | if err := c.ShouldBind(&r); err != nil { |
| 35 | abortWithError(c, http.StatusBadRequest, err) |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | // save key to persistence |
| 40 | developer := getDeveloperID(c) |
| 41 | |
| 42 | p, err := model.AddNewPrivateKey(model.GetDB(c), developer) |
| 43 | if err != nil { |
| 44 | _ = c.Error(err) |
| 45 | abortWithError(c, http.StatusInternalServerError, ErrGenerateKeyPairFailed) |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | // set as main account |
| 50 | err = model.SetIfNoMainAccount(model.GetDB(c), developer, p.Account) |
| 51 | if err != nil { |
| 52 | _ = c.Error(err) |
| 53 | abortWithError(c, http.StatusInternalServerError, ErrSetMainAccountFailed) |
| 54 | return |
| 55 | } |
| 56 | |
| 57 | keyBytes, err := kms.EncodePrivateKey(p.Key, []byte(r.Password)) |
| 58 | if err != nil { |
| 59 | _ = c.Error(err) |
| 60 | abortWithError(c, http.StatusInternalServerError, ErrEncodePrivateKeyFailed) |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | responseWithData(c, http.StatusOK, gin.H{ |
| 65 | "account": p.Account, |
| 66 | "key": string(keyBytes), |
| 67 | }) |
| 68 | } |
| 69 | |
| 70 | func uploadKeyPair(c *gin.Context) { |
| 71 | r := struct { |
nothing calls this directly
no test coverage detected