sse.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * MinIO Go Library for Amazon S3 Compatible Cloud Storage
  3. * Copyright 2020 MinIO, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package sse
  18. import "encoding/xml"
  19. // ApplySSEByDefault defines default encryption configuration, KMS or SSE. To activate
  20. // KMS, SSEAlgoritm needs to be set to "aws:kms"
  21. // Minio currently does not support Kms.
  22. type ApplySSEByDefault struct {
  23. KmsMasterKeyID string `xml:"KMSMasterKeyID,omitempty"`
  24. SSEAlgorithm string `xml:"SSEAlgorithm"`
  25. }
  26. // Rule layer encapsulates default encryption configuration
  27. type Rule struct {
  28. Apply ApplySSEByDefault `xml:"ApplyServerSideEncryptionByDefault"`
  29. }
  30. // Configuration is the default encryption configuration structure
  31. type Configuration struct {
  32. XMLName xml.Name `xml:"ServerSideEncryptionConfiguration"`
  33. Rules []Rule `xml:"Rule"`
  34. }
  35. // NewConfigurationSSES3 initializes a new SSE-S3 configuration
  36. func NewConfigurationSSES3() *Configuration {
  37. return &Configuration{
  38. Rules: []Rule{
  39. {
  40. Apply: ApplySSEByDefault{
  41. SSEAlgorithm: "AES256",
  42. },
  43. },
  44. },
  45. }
  46. }
  47. // NewConfigurationSSEKMS initializes a new SSE-KMS configuration
  48. func NewConfigurationSSEKMS(kmsMasterKey string) *Configuration {
  49. return &Configuration{
  50. Rules: []Rule{
  51. {
  52. Apply: ApplySSEByDefault{
  53. KmsMasterKeyID: kmsMasterKey,
  54. SSEAlgorithm: "aws:kms",
  55. },
  56. },
  57. },
  58. }
  59. }