2023-01-03 09:18:30 +00:00
|
|
|
// Copyright (C) 2019-2023 Nicola Murino
|
2022-07-17 18:16:00 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
// by the Free Software Foundation, version 3.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
2023-01-03 09:18:30 +00:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2022-07-17 18:16:00 +00:00
|
|
|
|
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
|
|
|
|
}
|