/pkg/ttnpb/keys.pb.validate.go

https://github.com/TheThingsNetwork/lorawan-stack · Go · 376 lines · 273 code · 65 blank · 38 comment · 48 complexity · e6321d26a7e08f9be1d2f858b4603119 MD5 · raw file

  1. // Code generated by protoc-gen-fieldmask. DO NOT EDIT.
  2. package ttnpb
  3. import (
  4. "bytes"
  5. "errors"
  6. "fmt"
  7. "net"
  8. "net/mail"
  9. "net/url"
  10. "regexp"
  11. "strings"
  12. "time"
  13. "unicode/utf8"
  14. "github.com/gogo/protobuf/types"
  15. )
  16. // ensure the imports are used
  17. var (
  18. _ = bytes.MinRead
  19. _ = errors.New("")
  20. _ = fmt.Print
  21. _ = utf8.UTFMax
  22. _ = (*regexp.Regexp)(nil)
  23. _ = (*strings.Reader)(nil)
  24. _ = net.IPv4len
  25. _ = time.Duration(0)
  26. _ = (*url.URL)(nil)
  27. _ = (*mail.Address)(nil)
  28. _ = types.DynamicAny{}
  29. )
  30. // define the regex for a UUID once up-front
  31. var _keys_uuidPattern = regexp.MustCompile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
  32. // ValidateFields checks the field values on KeyEnvelope with the rules defined
  33. // in the proto definition for this message. If any rules are violated, an
  34. // error is returned.
  35. func (m *KeyEnvelope) ValidateFields(paths ...string) error {
  36. if m == nil {
  37. return nil
  38. }
  39. if len(paths) == 0 {
  40. paths = KeyEnvelopeFieldPathsNested
  41. }
  42. for name, subs := range _processPaths(append(paths[:0:0], paths...)) {
  43. _ = subs
  44. switch name {
  45. case "key":
  46. // no validation rules for Key
  47. case "kek_label":
  48. if utf8.RuneCountInString(m.GetKEKLabel()) > 2048 {
  49. return KeyEnvelopeValidationError{
  50. field: "kek_label",
  51. reason: "value length must be at most 2048 runes",
  52. }
  53. }
  54. case "encrypted_key":
  55. // no validation rules for EncryptedKey
  56. default:
  57. return KeyEnvelopeValidationError{
  58. field: name,
  59. reason: "invalid field path",
  60. }
  61. }
  62. }
  63. return nil
  64. }
  65. // KeyEnvelopeValidationError is the validation error returned by
  66. // KeyEnvelope.ValidateFields if the designated constraints aren't met.
  67. type KeyEnvelopeValidationError struct {
  68. field string
  69. reason string
  70. cause error
  71. key bool
  72. }
  73. // Field function returns field value.
  74. func (e KeyEnvelopeValidationError) Field() string { return e.field }
  75. // Reason function returns reason value.
  76. func (e KeyEnvelopeValidationError) Reason() string { return e.reason }
  77. // Cause function returns cause value.
  78. func (e KeyEnvelopeValidationError) Cause() error { return e.cause }
  79. // Key function returns key value.
  80. func (e KeyEnvelopeValidationError) Key() bool { return e.key }
  81. // ErrorName returns error name.
  82. func (e KeyEnvelopeValidationError) ErrorName() string { return "KeyEnvelopeValidationError" }
  83. // Error satisfies the builtin error interface
  84. func (e KeyEnvelopeValidationError) Error() string {
  85. cause := ""
  86. if e.cause != nil {
  87. cause = fmt.Sprintf(" | caused by: %v", e.cause)
  88. }
  89. key := ""
  90. if e.key {
  91. key = "key for "
  92. }
  93. return fmt.Sprintf(
  94. "invalid %sKeyEnvelope.%s: %s%s",
  95. key,
  96. e.field,
  97. e.reason,
  98. cause)
  99. }
  100. var _ error = KeyEnvelopeValidationError{}
  101. var _ interface {
  102. Field() string
  103. Reason() string
  104. Key() bool
  105. Cause() error
  106. ErrorName() string
  107. } = KeyEnvelopeValidationError{}
  108. // ValidateFields checks the field values on RootKeys with the rules defined in
  109. // the proto definition for this message. If any rules are violated, an error
  110. // is returned.
  111. func (m *RootKeys) ValidateFields(paths ...string) error {
  112. if m == nil {
  113. return nil
  114. }
  115. if len(paths) == 0 {
  116. paths = RootKeysFieldPathsNested
  117. }
  118. for name, subs := range _processPaths(append(paths[:0:0], paths...)) {
  119. _ = subs
  120. switch name {
  121. case "root_key_id":
  122. if utf8.RuneCountInString(m.GetRootKeyID()) > 2048 {
  123. return RootKeysValidationError{
  124. field: "root_key_id",
  125. reason: "value length must be at most 2048 runes",
  126. }
  127. }
  128. case "app_key":
  129. if v, ok := interface{}(m.GetAppKey()).(interface{ ValidateFields(...string) error }); ok {
  130. if err := v.ValidateFields(subs...); err != nil {
  131. return RootKeysValidationError{
  132. field: "app_key",
  133. reason: "embedded message failed validation",
  134. cause: err,
  135. }
  136. }
  137. }
  138. case "nwk_key":
  139. if v, ok := interface{}(m.GetNwkKey()).(interface{ ValidateFields(...string) error }); ok {
  140. if err := v.ValidateFields(subs...); err != nil {
  141. return RootKeysValidationError{
  142. field: "nwk_key",
  143. reason: "embedded message failed validation",
  144. cause: err,
  145. }
  146. }
  147. }
  148. default:
  149. return RootKeysValidationError{
  150. field: name,
  151. reason: "invalid field path",
  152. }
  153. }
  154. }
  155. return nil
  156. }
  157. // RootKeysValidationError is the validation error returned by
  158. // RootKeys.ValidateFields if the designated constraints aren't met.
  159. type RootKeysValidationError struct {
  160. field string
  161. reason string
  162. cause error
  163. key bool
  164. }
  165. // Field function returns field value.
  166. func (e RootKeysValidationError) Field() string { return e.field }
  167. // Reason function returns reason value.
  168. func (e RootKeysValidationError) Reason() string { return e.reason }
  169. // Cause function returns cause value.
  170. func (e RootKeysValidationError) Cause() error { return e.cause }
  171. // Key function returns key value.
  172. func (e RootKeysValidationError) Key() bool { return e.key }
  173. // ErrorName returns error name.
  174. func (e RootKeysValidationError) ErrorName() string { return "RootKeysValidationError" }
  175. // Error satisfies the builtin error interface
  176. func (e RootKeysValidationError) Error() string {
  177. cause := ""
  178. if e.cause != nil {
  179. cause = fmt.Sprintf(" | caused by: %v", e.cause)
  180. }
  181. key := ""
  182. if e.key {
  183. key = "key for "
  184. }
  185. return fmt.Sprintf(
  186. "invalid %sRootKeys.%s: %s%s",
  187. key,
  188. e.field,
  189. e.reason,
  190. cause)
  191. }
  192. var _ error = RootKeysValidationError{}
  193. var _ interface {
  194. Field() string
  195. Reason() string
  196. Key() bool
  197. Cause() error
  198. ErrorName() string
  199. } = RootKeysValidationError{}
  200. // ValidateFields checks the field values on SessionKeys with the rules defined
  201. // in the proto definition for this message. If any rules are violated, an
  202. // error is returned.
  203. func (m *SessionKeys) ValidateFields(paths ...string) error {
  204. if m == nil {
  205. return nil
  206. }
  207. if len(paths) == 0 {
  208. paths = SessionKeysFieldPathsNested
  209. }
  210. for name, subs := range _processPaths(append(paths[:0:0], paths...)) {
  211. _ = subs
  212. switch name {
  213. case "session_key_id":
  214. if len(m.GetSessionKeyID()) > 2048 {
  215. return SessionKeysValidationError{
  216. field: "session_key_id",
  217. reason: "value length must be at most 2048 bytes",
  218. }
  219. }
  220. case "f_nwk_s_int_key":
  221. if v, ok := interface{}(m.GetFNwkSIntKey()).(interface{ ValidateFields(...string) error }); ok {
  222. if err := v.ValidateFields(subs...); err != nil {
  223. return SessionKeysValidationError{
  224. field: "f_nwk_s_int_key",
  225. reason: "embedded message failed validation",
  226. cause: err,
  227. }
  228. }
  229. }
  230. case "s_nwk_s_int_key":
  231. if v, ok := interface{}(m.GetSNwkSIntKey()).(interface{ ValidateFields(...string) error }); ok {
  232. if err := v.ValidateFields(subs...); err != nil {
  233. return SessionKeysValidationError{
  234. field: "s_nwk_s_int_key",
  235. reason: "embedded message failed validation",
  236. cause: err,
  237. }
  238. }
  239. }
  240. case "nwk_s_enc_key":
  241. if v, ok := interface{}(m.GetNwkSEncKey()).(interface{ ValidateFields(...string) error }); ok {
  242. if err := v.ValidateFields(subs...); err != nil {
  243. return SessionKeysValidationError{
  244. field: "nwk_s_enc_key",
  245. reason: "embedded message failed validation",
  246. cause: err,
  247. }
  248. }
  249. }
  250. case "app_s_key":
  251. if v, ok := interface{}(m.GetAppSKey()).(interface{ ValidateFields(...string) error }); ok {
  252. if err := v.ValidateFields(subs...); err != nil {
  253. return SessionKeysValidationError{
  254. field: "app_s_key",
  255. reason: "embedded message failed validation",
  256. cause: err,
  257. }
  258. }
  259. }
  260. default:
  261. return SessionKeysValidationError{
  262. field: name,
  263. reason: "invalid field path",
  264. }
  265. }
  266. }
  267. return nil
  268. }
  269. // SessionKeysValidationError is the validation error returned by
  270. // SessionKeys.ValidateFields if the designated constraints aren't met.
  271. type SessionKeysValidationError struct {
  272. field string
  273. reason string
  274. cause error
  275. key bool
  276. }
  277. // Field function returns field value.
  278. func (e SessionKeysValidationError) Field() string { return e.field }
  279. // Reason function returns reason value.
  280. func (e SessionKeysValidationError) Reason() string { return e.reason }
  281. // Cause function returns cause value.
  282. func (e SessionKeysValidationError) Cause() error { return e.cause }
  283. // Key function returns key value.
  284. func (e SessionKeysValidationError) Key() bool { return e.key }
  285. // ErrorName returns error name.
  286. func (e SessionKeysValidationError) ErrorName() string { return "SessionKeysValidationError" }
  287. // Error satisfies the builtin error interface
  288. func (e SessionKeysValidationError) Error() string {
  289. cause := ""
  290. if e.cause != nil {
  291. cause = fmt.Sprintf(" | caused by: %v", e.cause)
  292. }
  293. key := ""
  294. if e.key {
  295. key = "key for "
  296. }
  297. return fmt.Sprintf(
  298. "invalid %sSessionKeys.%s: %s%s",
  299. key,
  300. e.field,
  301. e.reason,
  302. cause)
  303. }
  304. var _ error = SessionKeysValidationError{}
  305. var _ interface {
  306. Field() string
  307. Reason() string
  308. Key() bool
  309. Cause() error
  310. ErrorName() string
  311. } = SessionKeysValidationError{}