Skip to main content

SecretKey

Struct SecretKey 

pub struct SecretKey { /* private fields */ }
Expand description

A device-scoped client key, stored in secretkey.json within the profile directory.

The key material is zeroized on drop and hidden from debug output.

§Example

use cipherstash_client::zerokms::{SecretKey, KeyProvider};
use zerokms_protocol::ViturKeyMaterial;
use uuid::Uuid;

let key_material: ViturKeyMaterial = vec![/* key bytes */].into();
let secret_key = SecretKey::new(
    Uuid::new_v4(),
    key_material,
);

// SecretKey implements KeyProvider
let client_key = secret_key.client_key().await?;

Implementations§

§

impl SecretKey

pub fn new(client_id: Uuid, client_key: ViturKeyMaterial) -> Self

Create a new SecretKey from the given client ID and key material.

pub fn from_hex( client_id: String, client_key_encoded: String, ) -> Result<Self, KeyProviderError>

Create a SecretKey from string representations of the client ID and encoded key material.

Accepts the key material as either hex (the historical CS_CLIENT_KEY format) or standard padded base64 (the format used by secretkey.json on disk). Hex is tried first; base64 is a fallback for any input that doesn’t parse as hex.

Named from_hex for historical reasons — the function is now lenient. The name is preserved to avoid breaking callers.

§Errors

Returns KeyProviderError::InvalidKey if:

  • client_id is not a valid UUID
  • client_key_encoded is neither valid hex nor valid base64

pub fn from_env() -> Result<Option<Self>, KeyProviderError>

Load a SecretKey from the CS_CLIENT_ID and CS_CLIENT_KEY environment variables.

CS_CLIENT_KEY accepts either hex (the historical format) or the base64 value that appears in secretkey.json — see SecretKey::from_hex.

Returns Ok(None) if neither or only one variable is set, allowing callers to fall back to another source. Returns Err if both variables are present but the values are invalid (bad UUID or bad encoding).

§Example
use cipherstash_client::zerokms::SecretKey;

let key = SecretKey::from_env().expect("invalid key material in env");
// key is Option<SecretKey> — None means "not configured via env"

Trait Implementations§

§

impl Debug for SecretKey

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for SecretKey

§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Drop for SecretKey

§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
§

impl KeyProvider for SecretKey

Implement KeyProvider for SecretKey to allow it to be used directly as a key source when initializing with a super::ZeroKMSBuilder.

§

async fn client_key(&self) -> Result<ClientKey, KeyProviderError>

Load a ClientKey from this provider.
§

impl OpaqueDebug for SecretKey

§

impl ProfileData for SecretKey

Available on non-WebAssembly only.

Implement ProfileData for SecretKey to enable loading/saving from the profile directory.

§

const FILENAME: &'static str = "secretkey.json"

The filename used when saving/loading this type (e.g. "secretkey.json").
§

const MODE: Option<u32>

Unix file permissions for this file. None uses the default umask. Sensitive files should return Some(0o600).
§

impl Serialize for SecretKey

§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Zeroize for SecretKey

§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AuthStrategyBounds for T
where T: Send + Sync + 'static,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: Rng + ?Sized, Self: FakeBase<U>,

Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: Rng + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more