github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/c-deps/libroach/ccl/testutils.h (about)

     1  // Copyright 2017 The Cockroach Authors.
     2  //
     3  // Licensed as a CockroachDB Enterprise file under the Cockroach Community
     4  // License (the "License"); you may not use this file except in compliance with
     5  // the License. You may obtain a copy of the License at
     6  //
     7  //     https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt
     8  
     9  #pragma once
    10  
    11  #include <rocksdb/env.h>
    12  #include <string>
    13  #include "ccl/storageccl/engineccl/enginepbccl/key_registry.pb.h"
    14  #include "key_manager.h"
    15  
    16  namespace enginepbccl = cockroach::ccl::storageccl::engineccl::enginepbccl;
    17  
    18  namespace testutils {
    19  
    20  // Generate the DBOptions.extra_options string for plaintext keys.
    21  std::string MakePlaintextExtraOptions();
    22  
    23  // MakeAES<size>Key creates a SecretKeyObject with a key of the specified size.
    24  // It needs an Env for the current time.
    25  enginepbccl::SecretKey* MakeAES128Key(rocksdb::Env* env);
    26  
    27  // WriteAES<size>KeyFile writes a AES key of the specified size to 'filename'
    28  // using 'env'.
    29  // The resulting filename can be used in the encryption options.
    30  rocksdb::Status WriteAES128KeyFile(rocksdb::Env* env, const std::string& filename);
    31  
    32  // MemKeyManager is a simple key manager useful for tests.
    33  // It holds a single key. ie: there is only an active key, no old keys.
    34  class MemKeyManager : public KeyManager {
    35   public:
    36    explicit MemKeyManager(enginepbccl::SecretKey* key) : key_(key) {}
    37    virtual ~MemKeyManager();
    38  
    39    virtual std::shared_ptr<enginepbccl::SecretKey> CurrentKey() override;
    40    virtual std::shared_ptr<enginepbccl::SecretKey> GetKey(const std::string& id) override;
    41  
    42    // Replace the key with the passed-in one. Takes ownership.
    43    void set_key(enginepbccl::SecretKey* key);
    44  
    45   private:
    46    std::unique_ptr<enginepbccl::SecretKey> key_;
    47  };
    48  
    49  }  // namespace testutils