Rust SDK

Detailed Rust SDK docs for Keeper Secrets Manager

Download and Installation

Requirements

Rust 1.87 or later is required to use this SDK. This minimum version ensures compatibility with Edition 2024 dependencies and recent security patches.

Adding as Package using Cargo

For more information, see https://crates.io/crates/keeper-secrets-manager-core

Source Code

Find the Rust source code in the GitHub repository

Using the SDK

Initialise

Using token only to generate a new config (for later usage) requires at least one read operation to bind the token and fully populate config.json

Parameter

Required

Description

Type

token

Yes

One Time Access Token

String

config

Yes

Storage Configuration

KeyValueStorage

Proxy Configuration

To route all SDK traffic through an HTTP or HTTPS proxy, set proxy_url on ClientOptions or use environment variables. The proxy applies to all SDK operations: API calls, file uploads, file downloads, thumbnail downloads, and caching requests.

Option
Description

ClientOptions.proxy_url

Set proxy programmatically. Takes precedence over environment variables.

HTTP_PROXY / HTTPS_PROXY

Standard proxy environment variables. Used when proxy_url is not set.

KSM_PROXY_URL

Used by caching_post_function when a proxy is needed for cache requests. Not read by make_caching_post_function. Configure the proxy on the reqwest::blocking::Client you pass to that factory instead.

ClientOptions.insecure_skip_verify

Set to true to disable TLS certificate verification. Not recommended outside testing.

KSM_SKIP_VERIFY

Environment variable alternative to insecure_skip_verify. Set to true to skip verification, false (default) to require it.

Retrieve Secrets

Parameter

Type

Required

Default

Description

uids

Vec<String>

Yes

Vec::new()

Record UIDs to fetch. Pass an empty vec to fetch all records the application has access to.

Returns

Type: Result<Vec<Record>, KSMRError>

All Keeper records, or records with the given UIDs

default - we will get all records which the token given has access to

Get Secrets with Options

Use get_secrets_with_options() to request additional data such as GraphSync linked records.

Parameter
Type
Required
Description

query_options

QueryOptions

Yes

Options for the request

QueryOptions Fields:

Field
Type
Description

records_filter

Vec<String>

Record UIDs to fetch. Empty vec fetches all records.

folders_filter

Vec<String>

Folder UIDs to filter by. Empty vec applies no folder filter.

request_links

Option<bool>

Set to true to include GraphSync linked records in the response. Linked records are available on Record.links.

Returns

Type: Result<Vec<Record>, KSMRError>

All records matching the query options.

Retrieve Values from Secret

Retrieve a password

This shortcut gets the password of a secret once that secret has been retrieved from Keeper Secrets Manager.

Retrieve Standard Fields

Parameter
Type
Required
Default
Description

field_type

&str

Yes

None

Field type to get

single

bool

Optional

false

Return only the first value

Returns

Type: Result<Value, KSMRError>

The field value as a JSON value. When single = true, returns the first value; otherwise returns an array.

Field types are based on the Keeper Record Type. For a detailed list of available fields based on the Keeper Record Type, see the record-type-info command in Keeper Commander.

Retrieve Custom Fields

Parameter
Type
Required
Default
Description

field_type

&str

Yes

-

Field type to get

single

bool

Optional

false

Return only the first value

Custom fields are any field that is not part of the record type definition but can be added by users.

Returns

Type: Result<Value, KSMRError>

The field value as a JSON value. When single = true, returns the first value; otherwise returns an array

Search Secrets by Title

Search for secrets using their title instead of UID. The SDK provides two methods:

  • get_secrets_by_title() - Returns all secrets matching the exact title

  • get_secret_by_title() - Returns the first secret matching the exact title

Response

Method
Return Type
Description

get_secrets_by_title()

Result<Vec<Record>, KSMRError>

All secrets matching the exact title

get_secret_by_title()

Result<Option<Record>, KSMRError>

First secret matching title, or None

Parameter
Type
Required
Description

record_title

&str

Yes

Exact title of the record to find

Title matching is case-sensitive and requires an exact match. For partial or case-insensitive searching, retrieve all secrets and filter client-side.

Retrieve Values using Keeper Notation

See Keeper Notation documentation to learn about Keeper Notation format and capabilities

Parameter
Type
Required
Default
Description

query

String

Yes

-

Keeper Notation query for getting a value from a specified field

Returns

Type: Result<serde_json::Value, KSMRError>

The value of the queried field as a JSON value. When the field contains a single value it resolves to a JSON string; multi-value fields resolve to a JSON array.

Retrieve a TOTP Code

Returns

Type: Result<TotpCode,KSMRError>

Parameter
Type
Required
Description

url

&str

Yes

TOTP Url

Update a Secret

Update Secret

The update_secret() method is the standard way to update records.

Parameter
Type
Required
Default
Description

record

Record

Yes

Record with updated field values

Response

Returns Result<(), KSMRError> - success or error

Password Rotation with Transactions

The update_secret_with_transaction() method enables password rotation workflows where you can test the new password before committing the change.

The rollback parameter follows its name: pass true to roll back the rotation, false to commit it. Pass false to finalize the new password.

Parameter
Type
Required
Description

record

Record

Yes

Record with updated field values

transaction_type

UpdateTransactionType

Yes

General or Rotation

record_uid

String

Yes

UID of the record to finalize transaction for

rollback

bool

Yes

false to commit, true to rollback

The update_secret_with_options() method provides fine-grained control over updates, including the ability to remove file links.

Parameter
Type
Required
Default
Description

record

Record

Yes

Record with updated field values

update_options

UpdateOptions

Yes

Configuration for advanced update behavior

UpdateOptions Fields:

Field
Type
Description

transaction_type

UpdateTransactionType

General or Rotation

links_to_remove

Vec<String>

UIDs of file attachments to remove

Set field values using the set_standard_field_value_mut or the set_custom_field_value_mut method.

Fields are found by type.

For a list of field types, see the Record Types documentation. Some fields have multiple values in these cases, the value can be set to a list.

Generate a Random Password

Parameter
Type
Required
Default
Description

password_options

PasswordOptions

Yes

Configuration for the password

special_characterset

String

Optional

"""!@#$%()+;<>=?[]{}^.,"""

Set of special characters to be included in the password

length

usize

Optional

32

Length of password

lowercase

i32

Optional

None

Count of lowercase characters in the password

uppercase

i32

Optional

None

Count of uppercase characters in the password

digits

i32

Optional

None

Count of digits in the password

special_characters

i32

Optional

None

Count of special characters in the password

By default, each count parameter specifies the minimum number of that character type. Pass a negative value to specify an exact count instead — for example, .lowercase(-8) produces exactly 8 lowercase characters. When all count parameters are negative or zero (exact mode), the length parameter is ignored and the total password length is derived from the sum of the absolute values.

Download a File

Parameter
Type
Required
Description

file_name

&str

Yes

Name, title, or UID of the file to download

path

&str

Yes

Path to download file

Returns

Type: Result<bool, KSMRError>

true if the file was found and saved to path; false if no file with that name, title, or UID exists on the record.

Download File by Title

Downloads a file attachment by record title and filename. The SDK searches all accessible records for one matching record_title, then retrieves the file named file_name from that record.

Parameter
Type
Required
Description

record_title

&str

Yes

Title of the record containing the file

file_name

&str

Yes

Name of the file attachment to download

Returns

Type: Result<Option<Vec<u8>>, KSMRError>

  • Ok(Some(bytes)) — decrypted file data as raw bytes

  • Ok(None) — no record with that title, or no file with that name was found

  • Err(...) — error during download or decryption

Download File Thumbnail

Some file attachments (especially images) have thumbnail previews. You can download these thumbnails separately from the full file.

Returns

Type: Result<Option<Vec<u8>>, KSMRError>

  • Ok(Some(bytes)) - Thumbnail data (typically JPEG)

  • Ok(None) - No thumbnail available for this file

  • Err(...) - Error downloading or decrypting thumbnail

Thumbnails are typically available for image files (PNG, JPEG, etc.). Document files and other non-image types usually do not have thumbnails.

Upload File

Upload File Parameters

Parameter
Type
Required
Default
Description

owner_record

Record

Yes

None

The record in which the file has to be uploaded

keeper_file

KeeperFileUpload

Yes

The file to be uploaded

File Parameters

Parameter
Type
Required
Default
Description

file_path

&str

Yes

Path to upload file

file_name

Option<&str>

Yes

Name of the file to be uploaded

file_title

Option<&str>

Yes

Title of the file to be uploaded

mime_type

Option<&str>

Yes

None

The type of data in the file. If none is provided, 'application/octet-stream' will be used

Returns

Type: Result<String, KSMRError>

The file UID of the attached file

Create a Secret

Prerequisites:

  • Shared folder UID

    • The shared folder must be accessible by the Secrets Manager Application

    • You and the Secrets Manager application must have edit permission

    • There must be at least one record in the shared folder

  • Created records and record fields must be formatted correctly

    • See the documentation for expected field formats for each record type

  • TOTP fields accept only URL generated outside of the KSM SDK

  • After record creation, you can upload file attachments using upload_file

Multi-value fields: To assign multiple values to a single field (e.g. two phone numbers, two security questions), pass a JSON array directly to RecordField::new_record_field. Single objects are still wrapped automatically; only pass an array when you have more than one entry.

Parameter
Type
Required
Description

parent_folder_uid

String

Yes

UID of the shared folder to create the record in

record_create_object

RecordCreate

Yes

Record definition. Type, title, and fields

RecordCreate fields:

Field
Type
Required
Default
Description

record_type

String

Yes

Record type (e.g. "login")

title

String

Yes

Title of the record

notes

Option<String>

No

None

Optional note on the record

fields

Vec<RecordField>

No

None

Standard fields

custom

Vec<RecordField>

No

None

Custom fields

Returns

Type: Result<String, KSMRError>

The record UID of the new record

Delete A Secret

The Rust KSM SDK can delete records in the Keeper Vault.

Parameter
Type
Required
Default
Description

record_uid

Vec<String>

Yes

None

The uid of the record to be deleted

Returns

Type: Result<String, KSMRError>

The server response string on success.

Caching

To protect against losing access to your secrets when network access is lost, the Rust SDK allows caching of secrets to the local machine in an encrypted file.

Setup and Configure Cache

The Rust SDK provides caching::make_caching_post_function(client) for disaster recovery caching. It stores the last successful API response to a local encrypted file and falls back to that data automatically when the server is unreachable. Build the reqwest::blocking::Client once outside any async context (it is safe to use inside tokio::task::spawn_blocking), then pass it to the factory. As long as there is network connectivity, the SDK always prefers a live response over cached data.

Cache Location:

  • Default: $KSM_CACHE_DIR/ksm_cache.bin

  • If KSM_CACHE_DIR not set, uses system temp directory

  • Override with environment variable: export KSM_CACHE_DIR=/path/to/cache

Custom Cache Implementations

For advanced use cases requiring custom cache management (e.g., preferring local cache over network, custom refresh intervals), you can implement your own caching logic using the KSMRCache as a starting point.

Folders

Folders have full CRUD support—create, read, update, and delete operations.

Read Folders

Downloads full folder hierarchy.

Returns

Type: Result<Vec<KeeperFolder>, KSMRError>

Create Folder

Requires CreateOptions and folder name to be provided. The folder UID parameter in CreateOptions is required—the UID of a shared folder, while sub-folder UID is optional, and if missing, a new regular folder is created directly under the parent (shared folder). There's no requirement for the sub-folder to be a direct descendant of the parent shared folder - it could be many levels deep.

Parameter
Type
Required
Default
Description

create_options

CreateOptions

Yes

None

The parent and sub-folder UIDs

folder_name

String

Yes

The folder name

folders

Vec<KeeperFolder>

No

None

List of folders to use in the search for parent and sub-folder from CreateOptions

Returns

Type: Result<String, KSMRError>

The UID of the newly created folder.

Update Folder

Updates the folder metadata—currently folder name only.

Parameter
Type
Required
Default
Description

folder_uid

String

Yes

The folder uid

folder_name

String

Yes

The new folder name

folders

Vec<KeeperFolder>

No

None

List of folders to use in the search for parent folder

Returns

Type: Result<String, KSMRError>

The server response string on success.

Delete Folders

Removes a list of folders. Use the force_delete flag to remove non-empty folders.

Any folders UIDs missing from the vault or not shared to the KSM Application will not result in error.

When using force_delete avoid sending parent with its children folder UIDs. Depending on the delete order you may get an error - ex. if parent force-deleted child first. There's no guarantee that list will always be processed in FIFO order.

Parameter
Type
Required
Default
Description

folder_uids

Vec<String>

Yes

The folder UID list

force_delete

bool

No

false

Set to true to delete non-empty folders. Default false returns an error if the folder contains records.

Returns

Type: Result<Vec<HashMap<String, Value>>, KSMRError>

A list of response entries for each deleted folder. On success the list is typically empty.

Last updated