sftpgo-mirror/kms/basesecret.go

86 lines
2.2 KiB
Go
Raw Normal View History

// Copyright (C) 2019-2022 Nicola Murino
//
// 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
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2020-11-30 20:46:34 +00:00
package kms
import (
sdkkms "github.com/sftpgo/sdk/kms"
)
2021-07-13 19:17:21 +00:00
// BaseSecret defines the base struct shared among all the secret providers
type BaseSecret struct {
Status sdkkms.SecretStatus `json:"status,omitempty"`
Payload string `json:"payload,omitempty"`
Key string `json:"key,omitempty"`
AdditionalData string `json:"additional_data,omitempty"`
// 1 means encrypted using a master key
Mode int `json:"mode,omitempty"`
2020-11-30 20:46:34 +00:00
}
// GetStatus returns the secret's status
func (s *BaseSecret) GetStatus() sdkkms.SecretStatus {
2020-11-30 20:46:34 +00:00
return s.Status
}
// 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
}
// 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
}
// GetMode returns the encryption mode
2021-07-13 19:17:21 +00:00
func (s *BaseSecret) GetMode() int {
return s.Mode
}
// 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
}
// 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
}
// 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
}
// SetStatus sets the secret's status
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
}