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.
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 the caching module (caching_post_function) when proxy is needed for cache requests.
Retrieve Secrets
Parameter
Type
Required
Default
Description
uids
Vec<String>
Optional
None
Record UIDs to fetch
Response
Type: Vec<Record>
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.
query_options
QueryOptions
Yes
Options for the request
QueryOptions Fields:
request_links
Option<bool>
Set to true to include GraphSync linked records in the response. Linked records are available on Record.links.
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
field_type
String
Yes
None
Field type to get
single
boolean
Optional
False
Return only the first value
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
field_type
String
Yes
-
Field type to get
single
boolean
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.
Response
Type:
StringorVec<String>
the value or values of the field. It will be a single value only if the single=true option is passed.
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 titleget_secret_by_title()- Returns the first secret matching the exact title
Response
get_secrets_by_title()
Result<Vec<Record>>
All secrets matching the exact title
get_secret_by_title()
Result<Option<Record>>
First secret matching title, or None
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
query
String
Yes
-
Keeper Notation query for getting a value from a specified field
Returns
The value of the queried field
Type: String or Vec<String>
Retrieve a TOTP Code
Returns
Type:
Result<TotpCode,KSMRError>
url
String
Yes
TOTP Url
Update a Secret
Record update commands don't update local record data on success (esp. updated record revision) so any consecutive updates to an already updated record will fail due to revision mismatch. Make sure to reload all updated records after each update batch.
Update Secret
The update_secret() method is the standard way to update records.
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.
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
Remove File Links
The update_secret_with_options() method provides fine-grained control over updates, including the ability to remove file links.
record
Record
Yes
Record with updated field values
update_options
UpdateOptions
Yes
Configuration for advanced update behavior
UpdateOptions Fields:
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
password_options
PasswordOptions
Yes
Configuration for the password
charset
String
Optional
"""!@#$%()+;<>=?[]{}^.,"""
Set of special characters to be included in the password
length
i32
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
file_name
&str
Yes
Name of the file to be downloaded
path
&str
Yes
Path to download file
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.
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 bytesOk(None)— no record with that title, or no file with that name was foundErr(...)— 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 fileErr(...)- 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
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
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:
String
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
record_type
DefaultRecordType
Yes
None
Type of record to be created
title
String
Yes
The title of the created record
note
String
Yes
None
The note to be made in the created record
value
String
Yes
Value for the field
label
String
Yes
None
Label for the field
required
bool
Yes
false
Defines if the field is required
privacy_screen
bool
Yes
false
Defines if the field value should be hidden
Returns
Type:
String
The record UID of the new record
Delete A Secret
The Rust KSM SDK can delete records in the Keeper Vault.
record_uid
String
Yes
None
The uid of the record to be deleted
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 includes a default caching function caching_post_function which stores cached queries to a local file, serving as a disaster recovery function. As long as there's network connectivity, it always prefers network over cached data and will use cache only if the web vault is inaccessible.
Cache Location:
Default:
$KSM_CACHE_DIR/ksm_cache.binIf
KSM_CACHE_DIRnot set, uses system temp directoryOverride with environment variable:
export KSM_CACHE_DIR=/path/to/cache
The default caching function stores only the last successful request. For example, if the first request (R1) successfully retrieves UID1 and updates the cache, but a subsequent request (R2) for UID2 fails, the cache will not include UID2. As a result, any later operations involving UID2 will return an empty response if network is down, since it was never added to the cache.
Updating a record from cache (or creating new record) invalidates cached record data and consecutive updates of the same record will fail. Batch updates work as long as they modify different records. Always follow up cached record updates with a call to get_secrets() to refresh cache (and pull updated metadata from vault like the new record revision).
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 class as a starting point.
Folders
Folders have full CRUD support—create, read, update, and delete operations.
Read Folders
Downloads full folder hierarchy.
Returns
Type:
Vec<KeeperFolder>
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.
create_options
CreateOptions
Yes
None
The parent and sub-folder UIDs
folder_name
str
Yes
The folder name
folders
Vec<KeeperFolder>
No
None
List of folders to use in the search for parent and sub-folder from CreateOptions
Update Folder
Updates the folder metadata—currently folder name only.
folder_uid
str
Yes
The folder uid
folder_name
str
Yes
The new folder name
folders
Vec<KeeperFolder>
No
None
List of folders to use in the search for parent folder
Delete Folders
Removes a list of folders. Use the force_deletion 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_deletion 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.
folder_uids
Vec<String>
Yes
The folder UID list
force_deletion
boolean
No
false
Force deletion of non-empty folders
Last updated
Was this helpful?

