summaryrefslogtreecommitdiffstats
path: root/src/rgw/rgw_bucket_encryption.h
blob: ba567bc71999923094fcb8162c987e79343f965f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp

#pragma once
#include <include/types.h>

class XMLObj;

class ApplyServerSideEncryptionByDefault
{
  std::string kmsMasterKeyID;
  std::string sseAlgorithm;

public:
  ApplyServerSideEncryptionByDefault() {};
  ApplyServerSideEncryptionByDefault(const std::string &algorithm,
     const std::string &key_id)
   : kmsMasterKeyID(key_id), sseAlgorithm(algorithm) {};

  const std::string& kms_master_key_id() const {
    return kmsMasterKeyID;
  }

  const std::string& sse_algorithm() const {
    return sseAlgorithm;
  }

  void encode(bufferlist& bl) const {
    ENCODE_START(1, 1, bl);
    encode(kmsMasterKeyID, bl);
    encode(sseAlgorithm, bl);
    ENCODE_FINISH(bl);
  }

  void decode(bufferlist::const_iterator& bl) {
    DECODE_START(1, bl);
    decode(kmsMasterKeyID, bl);
    decode(sseAlgorithm, bl);
    DECODE_FINISH(bl);
  }

  void decode_xml(XMLObj *obj);
  void dump_xml(Formatter *f) const;
};
WRITE_CLASS_ENCODER(ApplyServerSideEncryptionByDefault)

class ServerSideEncryptionConfiguration
{
protected:
  ApplyServerSideEncryptionByDefault applyServerSideEncryptionByDefault;
  bool bucketKeyEnabled;

public:
  ServerSideEncryptionConfiguration(): bucketKeyEnabled(false) {};
  ServerSideEncryptionConfiguration(const std::string &algorithm,
    const std::string &keyid="", bool enabled = false)
      : applyServerSideEncryptionByDefault(algorithm, keyid),
        bucketKeyEnabled(enabled) {}

  const std::string& kms_master_key_id() const {
    return applyServerSideEncryptionByDefault.kms_master_key_id();
  }

  const std::string& sse_algorithm() const {
    return applyServerSideEncryptionByDefault.sse_algorithm();
  }

  bool bucket_key_enabled() const {
    return bucketKeyEnabled;
  }

  void encode(bufferlist& bl) const {
    ENCODE_START(1, 1, bl);
    encode(applyServerSideEncryptionByDefault, bl);
    encode(bucketKeyEnabled, bl);
    ENCODE_FINISH(bl);
  }

  void decode(bufferlist::const_iterator& bl) {
    DECODE_START(1, bl);
    decode(applyServerSideEncryptionByDefault, bl);
    decode(bucketKeyEnabled, bl);
    DECODE_FINISH(bl);
  }

  void decode_xml(XMLObj *obj);
  void dump_xml(Formatter *f) const;
};
WRITE_CLASS_ENCODER(ServerSideEncryptionConfiguration)

class RGWBucketEncryptionConfig
{
protected:
  bool rule_exist;
  ServerSideEncryptionConfiguration rule;

public:
  RGWBucketEncryptionConfig(): rule_exist(false) {}
  RGWBucketEncryptionConfig(const std::string &algorithm,
    const std::string &keyid = "", bool enabled = false)
      : rule_exist(true), rule(algorithm, keyid, enabled) {}

  const std::string& kms_master_key_id() const {
    return rule.kms_master_key_id();
  }

  const std::string& sse_algorithm() const {
    return rule.sse_algorithm();
  }

  bool bucket_key_enabled() const {
    return rule.bucket_key_enabled();
  }

  bool has_rule() const {
    return rule_exist;
  }

  void encode(bufferlist& bl) const {
    ENCODE_START(1, 1, bl);
    encode(rule_exist, bl);
    if (rule_exist) {
      encode(rule, bl);
    }
    ENCODE_FINISH(bl);
  }

  void decode(bufferlist::const_iterator& bl) {
    DECODE_START(1, bl);
    decode(rule_exist, bl);
    if (rule_exist) {
      decode(rule, bl);
    }
    DECODE_FINISH(bl);
  }

  void decode_xml(XMLObj *obj);
  void dump_xml(Formatter *f) const;
  void dump(Formatter *f) const;
  static void generate_test_instances(std::list<RGWBucketEncryptionConfig*>& o);
};
WRITE_CLASS_ENCODER(RGWBucketEncryptionConfig)