Google Cloud Storage C++ Client  1.32.1
A C++ Client Library for Google Cloud Storage
well_known_headers.cc
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "google/cloud/storage/well_known_headers.h"
16 #include "google/cloud/storage/internal/openssl_util.h"
17 #include "google/cloud/storage/internal/sha256_hash.h"
18 #include <algorithm>
19 #include <iomanip>
20 #include <iostream>
21 
22 namespace google {
23 namespace cloud {
24 namespace storage {
25 inline namespace STORAGE_CLIENT_NS {
26 std::ostream& operator<<(std::ostream& os, CustomHeader const& rhs) {
27  if (!rhs.has_value()) {
28  return os;
29  }
30  return os << rhs.custom_header_name() << ": " << rhs.value();
31 }
32 
34  return EncryptionKeyData{"AES256", internal::Base64Encode(key),
35  internal::Base64Encode(internal::Sha256Hash(key))};
36 }
37 
39  auto binary_key = internal::Base64Decode(key).value();
40  return EncryptionKeyData{
41  "AES256", key, internal::Base64Encode(internal::Sha256Hash(binary_key))};
42 }
43 
44 EncryptionKey EncryptionKey::FromBinaryKey(std::string const& key) {
46 }
47 
48 EncryptionKey EncryptionKey::FromBase64Key(std::string const& key) {
50 }
51 
52 std::ostream& operator<<(std::ostream& os, EncryptionKey const& rhs) {
53  char const* prefix = EncryptionKey::prefix();
54  if (rhs.has_value()) {
55  return os << prefix << "algorithm: " << rhs.value().algorithm << "\n"
56  << prefix << "key: " << rhs.value().key << "\n"
57  << prefix << "key-sha256: " << rhs.value().sha256;
58  }
59  return os << prefix << "*: <not set>";
60 }
61 
64 }
65 
68 }
69 
70 std::ostream& operator<<(std::ostream& os, SourceEncryptionKey const& rhs) {
71  char const* prefix = SourceEncryptionKey::prefix();
72  if (rhs.has_value()) {
73  return os << prefix << "algorithm: " << rhs.value().algorithm << "\n"
74  << prefix << "key: " << rhs.value().key << "\n"
75  << prefix << "key-sha256: " << rhs.value().sha256;
76  }
77  return os << prefix << "*: <not set>";
78 }
79 
80 } // namespace STORAGE_CLIENT_NS
81 } // namespace storage
82 } // namespace cloud
83 } // namespace google