You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error.go 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package asymkey
  5. import "fmt"
  6. // ErrKeyUnableVerify represents a "KeyUnableVerify" kind of error.
  7. type ErrKeyUnableVerify struct {
  8. Result string
  9. }
  10. // IsErrKeyUnableVerify checks if an error is a ErrKeyUnableVerify.
  11. func IsErrKeyUnableVerify(err error) bool {
  12. _, ok := err.(ErrKeyUnableVerify)
  13. return ok
  14. }
  15. func (err ErrKeyUnableVerify) Error() string {
  16. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  17. }
  18. // ErrKeyNotExist represents a "KeyNotExist" kind of error.
  19. type ErrKeyNotExist struct {
  20. ID int64
  21. }
  22. // IsErrKeyNotExist checks if an error is a ErrKeyNotExist.
  23. func IsErrKeyNotExist(err error) bool {
  24. _, ok := err.(ErrKeyNotExist)
  25. return ok
  26. }
  27. func (err ErrKeyNotExist) Error() string {
  28. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  29. }
  30. // ErrKeyAlreadyExist represents a "KeyAlreadyExist" kind of error.
  31. type ErrKeyAlreadyExist struct {
  32. OwnerID int64
  33. Fingerprint string
  34. Content string
  35. }
  36. // IsErrKeyAlreadyExist checks if an error is a ErrKeyAlreadyExist.
  37. func IsErrKeyAlreadyExist(err error) bool {
  38. _, ok := err.(ErrKeyAlreadyExist)
  39. return ok
  40. }
  41. func (err ErrKeyAlreadyExist) Error() string {
  42. return fmt.Sprintf("public key already exists [owner_id: %d, finger_print: %s, content: %s]",
  43. err.OwnerID, err.Fingerprint, err.Content)
  44. }
  45. // ErrKeyNameAlreadyUsed represents a "KeyNameAlreadyUsed" kind of error.
  46. type ErrKeyNameAlreadyUsed struct {
  47. OwnerID int64
  48. Name string
  49. }
  50. // IsErrKeyNameAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  51. func IsErrKeyNameAlreadyUsed(err error) bool {
  52. _, ok := err.(ErrKeyNameAlreadyUsed)
  53. return ok
  54. }
  55. func (err ErrKeyNameAlreadyUsed) Error() string {
  56. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  57. }
  58. // ErrGPGNoEmailFound represents a "ErrGPGNoEmailFound" kind of error.
  59. type ErrGPGNoEmailFound struct {
  60. FailedEmails []string
  61. ID string
  62. }
  63. // IsErrGPGNoEmailFound checks if an error is a ErrGPGNoEmailFound.
  64. func IsErrGPGNoEmailFound(err error) bool {
  65. _, ok := err.(ErrGPGNoEmailFound)
  66. return ok
  67. }
  68. func (err ErrGPGNoEmailFound) Error() string {
  69. return fmt.Sprintf("none of the emails attached to the GPG key could be found: %v", err.FailedEmails)
  70. }
  71. // ErrGPGInvalidTokenSignature represents a "ErrGPGInvalidTokenSignature" kind of error.
  72. type ErrGPGInvalidTokenSignature struct {
  73. Wrapped error
  74. ID string
  75. }
  76. // IsErrGPGInvalidTokenSignature checks if an error is a ErrGPGInvalidTokenSignature.
  77. func IsErrGPGInvalidTokenSignature(err error) bool {
  78. _, ok := err.(ErrGPGInvalidTokenSignature)
  79. return ok
  80. }
  81. func (err ErrGPGInvalidTokenSignature) Error() string {
  82. return "the provided signature does not sign the token with the provided key"
  83. }
  84. // ErrGPGKeyParsing represents a "ErrGPGKeyParsing" kind of error.
  85. type ErrGPGKeyParsing struct {
  86. ParseError error
  87. }
  88. // IsErrGPGKeyParsing checks if an error is a ErrGPGKeyParsing.
  89. func IsErrGPGKeyParsing(err error) bool {
  90. _, ok := err.(ErrGPGKeyParsing)
  91. return ok
  92. }
  93. func (err ErrGPGKeyParsing) Error() string {
  94. return fmt.Sprintf("failed to parse gpg key %s", err.ParseError.Error())
  95. }
  96. // ErrGPGKeyNotExist represents a "GPGKeyNotExist" kind of error.
  97. type ErrGPGKeyNotExist struct {
  98. ID int64
  99. }
  100. // IsErrGPGKeyNotExist checks if an error is a ErrGPGKeyNotExist.
  101. func IsErrGPGKeyNotExist(err error) bool {
  102. _, ok := err.(ErrGPGKeyNotExist)
  103. return ok
  104. }
  105. func (err ErrGPGKeyNotExist) Error() string {
  106. return fmt.Sprintf("public gpg key does not exist [id: %d]", err.ID)
  107. }
  108. // ErrGPGKeyImportNotExist represents a "GPGKeyImportNotExist" kind of error.
  109. type ErrGPGKeyImportNotExist struct {
  110. ID string
  111. }
  112. // IsErrGPGKeyImportNotExist checks if an error is a ErrGPGKeyImportNotExist.
  113. func IsErrGPGKeyImportNotExist(err error) bool {
  114. _, ok := err.(ErrGPGKeyImportNotExist)
  115. return ok
  116. }
  117. func (err ErrGPGKeyImportNotExist) Error() string {
  118. return fmt.Sprintf("public gpg key import does not exist [id: %s]", err.ID)
  119. }
  120. // ErrGPGKeyIDAlreadyUsed represents a "GPGKeyIDAlreadyUsed" kind of error.
  121. type ErrGPGKeyIDAlreadyUsed struct {
  122. KeyID string
  123. }
  124. // IsErrGPGKeyIDAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  125. func IsErrGPGKeyIDAlreadyUsed(err error) bool {
  126. _, ok := err.(ErrGPGKeyIDAlreadyUsed)
  127. return ok
  128. }
  129. func (err ErrGPGKeyIDAlreadyUsed) Error() string {
  130. return fmt.Sprintf("public key already exists [key_id: %s]", err.KeyID)
  131. }
  132. // ErrGPGKeyAccessDenied represents a "GPGKeyAccessDenied" kind of Error.
  133. type ErrGPGKeyAccessDenied struct {
  134. UserID int64
  135. KeyID int64
  136. }
  137. // IsErrGPGKeyAccessDenied checks if an error is a ErrGPGKeyAccessDenied.
  138. func IsErrGPGKeyAccessDenied(err error) bool {
  139. _, ok := err.(ErrGPGKeyAccessDenied)
  140. return ok
  141. }
  142. // Error pretty-prints an error of type ErrGPGKeyAccessDenied.
  143. func (err ErrGPGKeyAccessDenied) Error() string {
  144. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d]",
  145. err.UserID, err.KeyID)
  146. }
  147. // ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
  148. type ErrKeyAccessDenied struct {
  149. UserID int64
  150. KeyID int64
  151. Note string
  152. }
  153. // IsErrKeyAccessDenied checks if an error is a ErrKeyAccessDenied.
  154. func IsErrKeyAccessDenied(err error) bool {
  155. _, ok := err.(ErrKeyAccessDenied)
  156. return ok
  157. }
  158. func (err ErrKeyAccessDenied) Error() string {
  159. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  160. err.UserID, err.KeyID, err.Note)
  161. }
  162. // ErrDeployKeyNotExist represents a "DeployKeyNotExist" kind of error.
  163. type ErrDeployKeyNotExist struct {
  164. ID int64
  165. KeyID int64
  166. RepoID int64
  167. }
  168. // IsErrDeployKeyNotExist checks if an error is a ErrDeployKeyNotExist.
  169. func IsErrDeployKeyNotExist(err error) bool {
  170. _, ok := err.(ErrDeployKeyNotExist)
  171. return ok
  172. }
  173. func (err ErrDeployKeyNotExist) Error() string {
  174. return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
  175. }
  176. // ErrDeployKeyAlreadyExist represents a "DeployKeyAlreadyExist" kind of error.
  177. type ErrDeployKeyAlreadyExist struct {
  178. KeyID int64
  179. RepoID int64
  180. }
  181. // IsErrDeployKeyAlreadyExist checks if an error is a ErrDeployKeyAlreadyExist.
  182. func IsErrDeployKeyAlreadyExist(err error) bool {
  183. _, ok := err.(ErrDeployKeyAlreadyExist)
  184. return ok
  185. }
  186. func (err ErrDeployKeyAlreadyExist) Error() string {
  187. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  188. }
  189. // ErrDeployKeyNameAlreadyUsed represents a "DeployKeyNameAlreadyUsed" kind of error.
  190. type ErrDeployKeyNameAlreadyUsed struct {
  191. RepoID int64
  192. Name string
  193. }
  194. // IsErrDeployKeyNameAlreadyUsed checks if an error is a ErrDeployKeyNameAlreadyUsed.
  195. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  196. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  197. return ok
  198. }
  199. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  200. return fmt.Sprintf("public key with name already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  201. }