Skip to main content

KeyClient

Struct KeyClient 

Source
pub struct KeyClient { /* private fields */ }
Expand description

Calls KeyService.

Keys and the operations made with them.

An key::Purpose::EncryptDecrypt key encrypts with AES-256-GCM-SIV. Its ciphertext names the key version that made it but not the key: Decrypt names the key, and a ciphertext decrypts only under the key and the encryption context it was made with. A signing key signs with ECDSA over P-256 and SHA-256 (ASN.1 DER signatures) or with Ed25519; its public keys are read with GetPublicKey.

Implementations§

Source§

impl KeyClient

Source

pub fn new(client: &Client) -> Self

Returns a client of KeyService that sends its calls through client.

Source

pub fn service(&self) -> &Service

The endpoint the client sends its calls to, which also serves the operations its methods answer with.

Source

pub fn with_options(&self, options: CallOptions) -> Self

The same client, whose calls are sent as options says instead of as the Client’s settings do, such as a mutation that must not be sent twice: .with_options(CallOptions::new().max_attempts(1)). See CallOptions.

Source

pub async fn get_key(&self, request: GetKeyRequest) -> Result<Key, Error>

Returns a key, deleted or not. Needs kms.key.get on the project.

Source

pub async fn list_keys( &self, request: ListKeysRequest, ) -> Result<ListKeysResponse, Error>

Lists a project’s keys in a region, ordered by name. Deleted ones are listed only when show_deleted is set, so a page may hold fewer keys than page_size and still be followed by another. Needs kms.key.list on the project.

Source

pub fn all_keys(&self, request: ListKeysRequest) -> Pages<Key>

Returns everything list_keys lists from request’s page on, fetching the next page as the stream reaches it. A page that fails ends the stream with its error.

Source

pub async fn create_key(&self, request: CreateKeyRequest) -> Result<Key, Error>

Creates a key, key::State::Enabled, with its first version as the primary. The platform assigns its id, which its name returns; an id is never used again. Needs kms.key.create on the project.

Source

pub async fn update_key(&self, request: UpdateKeyRequest) -> Result<Key, Error>

Enables or disables a key, or changes its tags: state and tags are the fields it changes. A disabled key refuses every operation but GetPublicKey with CONFLICT until it is enabled again. Setting the state or the tags the key has already succeeds and changes nothing. A deleted key can’t be changed: undelete it first. A key the platform manages (platform_managed) is refused with FORBIDDEN, even when the request would change nothing. Needs kms.key.update on the project.

Source

pub async fn delete_key(&self, request: DeleteKeyRequest) -> Result<Key, Error>

Deletes a key: it becomes key::State::Deleted at once, refuses every operation but GetPublicKey, and its material is destroyed at purge_time, after destroy_delay. Until then UndeleteKey restores it, disabled. After it, nothing it encrypted can ever be decrypted again. Deleting a deleted key succeeds and changes nothing. A key the platform manages is refused with FORBIDDEN, deleted or not. Needs kms.key.delete on the project.

Source

pub async fn undelete_key( &self, request: UndeleteKeyRequest, ) -> Result<Key, Error>

Restores a deleted key whose material isn’t destroyed yet: it becomes key::State::Disabled, to be enabled with UpdateKey. Refused with CONFLICT for a key that isn’t deleted, or whose purge_time has passed, and with FORBIDDEN for a key the platform manages. Needs kms.key.undelete on the project, which kms.key.delete doesn’t include.

Source

pub async fn rotate_key(&self, request: RotateKeyRequest) -> Result<Key, Error>

Adds a new version to a key and makes it the primary: new ciphertexts and signatures use it, and every earlier version still decrypts and its public key stays readable. Refused with CONFLICT for a key that isn’t enabled, and with FORBIDDEN for a key the platform manages. Needs kms.key.rotate on the project.

Source

pub async fn retire_encryption_context( &self, request: RetireEncryptionContextRequest, ) -> Result<Key, Error>

Retires an encryption context on a key the platform manages, for good: from then on every zone refuses Encrypt, Decrypt and GenerateDataKey under exactly that context, and the making, renewal and use of a grant constrained to it, each with FORBIDDEN. A ciphertext made under it, wherever a copy of it is kept, never decrypts again. Only the platform retires a context: the storage service retires a deleted volume’s volume context. Retiring a context already retired succeeds and changes nothing. Refused with FORBIDDEN for a key the platform doesn’t manage and for anyone but a platform service agent, and with BAD_REQUEST for an empty context. Needs kms.key.retire_context on the project, which no customer role holds.

Source

pub async fn encrypt( &self, request: EncryptRequest, ) -> Result<EncryptResponse, Error>

Encrypts up to 64 KiB with an key::Purpose::EncryptDecrypt key’s primary version, bound to the encryption context. For more data, encrypt it yourself with a data key from GenerateDataKey. Refused with CONFLICT for a key that isn’t enabled, with BAD_REQUEST for a signing key, and with FORBIDDEN under a context retired on the key. Needs kms.key.encrypt on the project.

Source

pub async fn decrypt( &self, request: DecryptRequest, ) -> Result<DecryptResponse, Error>

Decrypts a ciphertext Encrypt or GenerateDataKey made with this key, given the same encryption context. Refused with BAD_REQUEST for a ciphertext that doesn’t decrypt under this key and context, with CONFLICT for a key that isn’t enabled, and with FORBIDDEN under a context retired on the key, whatever the ciphertext. Needs kms.key.decrypt on the project.

Source

pub async fn generate_data_key( &self, request: GenerateDataKeyRequest, ) -> Result<GenerateDataKeyResponse, Error>

Returns a new random 256-bit data key, in plaintext and encrypted under an key::Purpose::EncryptDecrypt key’s primary version with the encryption context. Encrypt your data with the plaintext, keep only the ciphertext beside it, and recover the data key with Decrypt when you need it. Refused with FORBIDDEN under a context retired on the key. Needs kms.key.generate_data_key on the project.

Source

pub async fn sign(&self, request: SignRequest) -> Result<SignResponse, Error>

Signs up to 64 KiB with a signing key’s primary version, or the version key_version names. ECDSA hashes the data with SHA-256 itself: send the data, not a digest. Refused with CONFLICT for a key that isn’t enabled, and with BAD_REQUEST for an key::Purpose::EncryptDecrypt key. Needs kms.key.sign on the project.

Source

pub async fn get_public_key( &self, request: GetPublicKeyRequest, ) -> Result<PublicKey, Error>

Returns a signing key version’s public key, to verify its signatures with. Answered for a disabled or deleted key too, until its material is destroyed. Refused with BAD_REQUEST for an key::Purpose::EncryptDecrypt key. Needs kms.key.get_public_key on the project.

Trait Implementations§

Source§

impl Clone for KeyClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyClient

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for KeyClient

§

impl !UnwindSafe for KeyClient

§

impl Forget for KeyClient

§

impl Freeze for KeyClient
where *const ArcInner<Inner> is !null: Freeze, PhantomData<ArcInner<Inner>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for KeyClient

§

impl Send for KeyClient
where Arc<Inner>: Send, RawVecInner: Send,

§

impl Sync for KeyClient
where Arc<Inner>: Sync, RawVecInner: Sync,

§

impl Unpin for KeyClient
where Arc<Inner>: Unpin, *const u8 is !null: Unpin,

§

impl UnsafeUnpin for KeyClient
where *const ArcInner<Inner> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin,

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> MaybeSend for T
where T: Send + ?Sized,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<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