2020-11-30 20:46:34 +00:00
|
|
|
package kms
|
|
|
|
|
2022-01-06 09:11:47 +00:00
|
|
|
import (
|
2022-01-06 10:54:43 +00:00
|
|
|
sdkkms "github.com/sftpgo/sdk/kms"
|
2022-01-06 09:11:47 +00:00
|
|
|
)
|
|
|
|
|
2021-07-13 19:17:21 +00:00
|
|
|
// BaseSecret defines the base struct shared among all the secret providers
|
|
|
|
type BaseSecret struct {
|
2022-01-06 09:11:47 +00:00
|
|
|
Status sdkkms.SecretStatus `json:"status,omitempty"`
|
|
|
|
Payload string `json:"payload,omitempty"`
|
|
|
|
Key string `json:"key,omitempty"`
|
|
|
|
AdditionalData string `json:"additional_data,omitempty"`
|
2020-12-01 21:18:16 +00:00
|
|
|
// 1 means encrypted using a master key
|
|
|
|
Mode int `json:"mode,omitempty"`
|
2020-11-30 20:46:34 +00:00
|
|
|
}
|
|
|
|
|
2021-11-27 16:04:13 +00:00
|
|
|
// GetStatus returns the secret's status
|
2022-01-06 09:11:47 +00:00
|
|
|
func (s *BaseSecret) GetStatus() sdkkms.SecretStatus {
|
2020-11-30 20:46:34 +00:00
|
|
|
return s.Status
|
|
|
|
}
|
|
|
|
|
2021-11-27 16:04:13 +00:00
|
|
|
// GetPayload returns the secret's payload
|
2021-07-13 19:17:21 +00:00
|
|
|
func (s *BaseSecret) GetPayload() string {
|
2020-11-30 20:46:34 +00:00
|
|
|
return s.Payload
|
|
|
|
}
|
|
|
|
|
2021-11-27 16:04:13 +00:00
|
|
|
// GetKey returns the secret's key
|
2021-07-13 19:17:21 +00:00
|
|
|
func (s *BaseSecret) GetKey() string {
|
2020-11-30 20:46:34 +00:00
|
|
|
return s.Key
|
|
|
|
}
|
|
|
|
|
2021-11-27 16:04:13 +00:00
|
|
|
// GetMode returns the encryption mode
|
2021-07-13 19:17:21 +00:00
|
|
|
func (s *BaseSecret) GetMode() int {
|
2020-12-01 21:18:16 +00:00
|
|
|
return s.Mode
|
|
|
|
}
|
|
|
|
|
2021-11-27 16:04:13 +00:00
|
|
|
// GetAdditionalData returns the secret's additional data
|
2021-07-13 19:17:21 +00:00
|
|
|
func (s *BaseSecret) GetAdditionalData() string {
|
2020-11-30 20:46:34 +00:00
|
|
|
return s.AdditionalData
|
|
|
|
}
|
|
|
|
|
2021-11-27 16:04:13 +00:00
|
|
|
// SetKey sets the secret's key
|
2021-07-13 19:17:21 +00:00
|
|
|
func (s *BaseSecret) SetKey(value string) {
|
2020-11-30 20:46:34 +00:00
|
|
|
s.Key = value
|
|
|
|
}
|
|
|
|
|
2021-11-27 16:04:13 +00:00
|
|
|
// SetAdditionalData sets the secret's additional data
|
2021-07-13 19:17:21 +00:00
|
|
|
func (s *BaseSecret) SetAdditionalData(value string) {
|
2020-11-30 20:46:34 +00:00
|
|
|
s.AdditionalData = value
|
|
|
|
}
|
|
|
|
|
2021-11-27 16:04:13 +00:00
|
|
|
// SetStatus sets the secret's status
|
2022-01-06 09:11:47 +00:00
|
|
|
func (s *BaseSecret) SetStatus(value sdkkms.SecretStatus) {
|
2020-11-30 20:46:34 +00:00
|
|
|
s.Status = value
|
|
|
|
}
|
|
|
|
|
2021-07-13 19:17:21 +00:00
|
|
|
func (s *BaseSecret) isEmpty() bool {
|
2020-11-30 20:46:34 +00:00
|
|
|
if s.Status != "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if s.Payload != "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if s.Key != "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if s.AdditionalData != "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|