basesecret.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (C) 2019-2022 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. package kms
  15. import (
  16. sdkkms "github.com/sftpgo/sdk/kms"
  17. )
  18. // BaseSecret defines the base struct shared among all the secret providers
  19. type BaseSecret struct {
  20. Status sdkkms.SecretStatus `json:"status,omitempty"`
  21. Payload string `json:"payload,omitempty"`
  22. Key string `json:"key,omitempty"`
  23. AdditionalData string `json:"additional_data,omitempty"`
  24. // 1 means encrypted using a master key
  25. Mode int `json:"mode,omitempty"`
  26. }
  27. // GetStatus returns the secret's status
  28. func (s *BaseSecret) GetStatus() sdkkms.SecretStatus {
  29. return s.Status
  30. }
  31. // GetPayload returns the secret's payload
  32. func (s *BaseSecret) GetPayload() string {
  33. return s.Payload
  34. }
  35. // GetKey returns the secret's key
  36. func (s *BaseSecret) GetKey() string {
  37. return s.Key
  38. }
  39. // GetMode returns the encryption mode
  40. func (s *BaseSecret) GetMode() int {
  41. return s.Mode
  42. }
  43. // GetAdditionalData returns the secret's additional data
  44. func (s *BaseSecret) GetAdditionalData() string {
  45. return s.AdditionalData
  46. }
  47. // SetKey sets the secret's key
  48. func (s *BaseSecret) SetKey(value string) {
  49. s.Key = value
  50. }
  51. // SetAdditionalData sets the secret's additional data
  52. func (s *BaseSecret) SetAdditionalData(value string) {
  53. s.AdditionalData = value
  54. }
  55. // SetStatus sets the secret's status
  56. func (s *BaseSecret) SetStatus(value sdkkms.SecretStatus) {
  57. s.Status = value
  58. }
  59. func (s *BaseSecret) isEmpty() bool {
  60. if s.Status != "" {
  61. return false
  62. }
  63. if s.Payload != "" {
  64. return false
  65. }
  66. if s.Key != "" {
  67. return false
  68. }
  69. if s.AdditionalData != "" {
  70. return false
  71. }
  72. return true
  73. }