# CipherStash Client SDK

[![Crates.io Version](https://img.shields.io/crates/v/cipherstash-client?style=for-the-badge)](https://crates.io/crates/cipherstash-client)
[![docs.rs](https://img.shields.io/docsrs/cipherstash-client?style=for-the-badge)](https://docs.rs/cipherstash-client/)
[![Built by CipherStash](https://raw.githubusercontent.com/cipherstash/meta/refs/heads/main/csbadge.svg)](https://cipherstash.com)

 [Website](https://cipherstash.com) | [Docs](https://cipherstash.com/docs) | [Discussions](https://github.com/orgs/cipherstash/discussions)


The CipherStash SDK is the main way of interacting with CipherStash services.
It includes clients for talking to ZeroKMS, CipherStash Token Service (CTS) and the services used to power Audit.

It also contains all the indexing and encryption logic used in CipherStash products.

## Getting Started

To get started add the `cipherstash-client` dependency to your `Cargo.toml`

```toml
[dependencies]
cipherstash-client = "0.34.0"
```

### Creating a ZeroKMS Client

Use [`ZeroKMSBuilder`] to create a new [`ZeroKMS`] client. With this you can:

- Manage keysets, config and clients
- Encrypt and decrypt data

```no_run
use cipherstash_client::zerokms::ZeroKMSBuilder;

#[tokio::main]
async fn main() {
    let client = ZeroKMSBuilder::auto()
        .expect("failed to detect credentials")
        .build()
        .expect("failed to build client");

    let keyset = client.create_keyset("users", "A keyset used to encrypt my users' information")
        .await
        .expect("failed to create keyset");
}
```

### Creating a CTS Client

Use [`CtsClient`] to manage access keys and identity tokens:

```rust,no_run
use cipherstash_client::{CtsClient, Crn, WorkspaceId};
use cts_common::claims::Role;
use stack_auth::{AccessKey, AccessKeyStrategy};

#[tokio::main]
async fn main() {
    let workspace_crn: Crn = "crn:ap-southeast-2.aws:E4UMRN47WJNSMAKR".parse().unwrap();
    let key: AccessKey = "CSAKmyKeyId.myKeySecret".parse().unwrap();
    let strategy = AccessKeyStrategy::new(workspace_crn, key).unwrap();
    let client = CtsClient::new(strategy);

    let workspace_id = WorkspaceId::try_from("E4UMRN47WJNSMAKR").expect("Valid ID");
    let access_key = client.create_access_key("Test Access Key", workspace_id, Role::Admin)
        .await
        .expect("failed to create access key");
}
```
