Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions cpp/src/parquet/encryption/external/third_party/dbpa_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//TODO: figure out the licensing.

#pragma once

#include <cstdint>
#include <cstddef>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include "span.hpp"
#include "enums.h"

#ifndef DBPS_EXPORT
#define DBPS_EXPORT
#endif

// TODO: this file was copied from
// https://github.com/protegrity/DataBatchProtectionService
// we need to find a better way to share it between repos.
// https://github.com/protegrity/arrow/issues/110

namespace dbps::external {

template <typename T>
using span = tcb::span<T>;

/*
* DataBatchProtectionAgentInterface, EncryptionResult and DecryptionResult implementation contracts:
* - While handle to EncryptionResult/DecryptionResult exists, ciphertext()/plaintext() is guaranteed to return valid data
* - Read operations are not destructive. Multiple calls return the same data
* - Destructor must dispose of internal memory (either by delegation or cleanup)
* - No throwing exceptions. Errors reported via success() flag and error methods.
* - Library users must check size() to ensure the actual size of the returned payload.
*/

class DBPS_EXPORT EncryptionResult {
public:
virtual span<const uint8_t> ciphertext() const = 0;

// Allows a larger backing buffer than the exact ciphertext size.
// Library users must check size() to ensure the actual size of the returned payload.
virtual std::size_t size() const = 0;

// Success flag; false indicates an error.
virtual bool success() const = 0;

// Error details (valid when success() == false).
virtual const std::string& error_message() const = 0;
virtual const std::map<std::string, std::string>& error_fields() const = 0;

virtual ~EncryptionResult() = default;
};

class DBPS_EXPORT DecryptionResult {
public:
virtual span<const uint8_t> plaintext() const = 0;

// Allows a larger backing buffer than the exact plaintext size.
// Library users must check size() to ensure the actual size of the returned payload.
virtual std::size_t size() const = 0;

// Success flag; false indicates an error.
virtual bool success() const = 0;

// Error details (valid when success() == false).
virtual const std::string& error_message() const = 0;
virtual const std::map<std::string, std::string>& error_fields() const = 0;

virtual ~DecryptionResult() = default;
};

class DBPS_EXPORT DataBatchProtectionAgentInterface {
public:
DataBatchProtectionAgentInterface() = default;

// user_id is not stored as a member; it is expected to be embedded into app_context
// (e.g., as a serialized map/JSON field).
virtual void init(
std::string column_name,
std::map<std::string, std::string> connection_config,
std::string app_context,
std::string column_key_id,
Type::type data_type,
CompressionCodec::type compression_type)
{
column_name_ = std::move(column_name);
connection_config_ = std::move(connection_config);
app_context_ = std::move(app_context);
column_key_id_ = std::move(column_key_id);
data_type_ = data_type;
compression_type_ = compression_type;
}

virtual std::unique_ptr<EncryptionResult> Encrypt(
span<const uint8_t> plaintext) = 0;

virtual std::unique_ptr<DecryptionResult> Decrypt(
span<const uint8_t> ciphertext) = 0;

virtual ~DataBatchProtectionAgentInterface() = default;

private:
std::string column_name_;
std::map<std::string, std::string> connection_config_;
std::string app_context_; // includes user_id

std::string column_key_id_;
Type::type data_type_;
CompressionCodec::type compression_type_;
};
}
58 changes: 58 additions & 0 deletions cpp/src/parquet/encryption/external/third_party/enums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//TODO: figure out the licensing.

#pragma once

// TODO: this file was copied from
// https://github.com/protegrity/DataBatchProtectionService
// we need to find a better way to share it between repos.
// https://github.com/protegrity/arrow/issues/110

namespace dbps::external {

// Captures the data type of the data batch elements.
// Intentionally similar to parquet::Type to ease mapping and for compatibility with a known enum.
struct Type {
enum type {
BOOLEAN = 0,
INT32 = 1,
INT64 = 2,
INT96 = 3,
FLOAT = 4,
DOUBLE = 5,
BYTE_ARRAY = 6,
FIXED_LEN_BYTE_ARRAY = 7
};
};

// Intentionally similar to arrow::CompressionCodec
struct CompressionCodec {
enum type {
UNCOMPRESSED = 0,
SNAPPY = 1,
GZIP = 2,
LZO = 3,
BROTLI = 4,
LZ4 = 5,
ZSTD = 6,
LZ4_RAW = 7
};
};

// Format for data values
struct Format {
enum type {
JSON = 0,
CSV = 1,
RAW_C_DATA = 2
};
};

// Encoding applied to the data when serialized to send over the wire
struct Encoding {
enum type {
UTF8 = 0,
BASE64 = 1
};
};

}
Loading
Loading