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
impl KeyClient
Sourcepub fn new(client: &Client) -> Self
pub fn new(client: &Client) -> Self
Returns a client of KeyService that sends its calls through client.
Sourcepub fn service(&self) -> &Service
pub fn service(&self) -> &Service
The endpoint the client sends its calls to, which also serves the operations its methods answer with.
Sourcepub fn with_options(&self, options: CallOptions) -> Self
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.
Sourcepub async fn get_key(&self, request: GetKeyRequest) -> Result<Key, Error>
pub async fn get_key(&self, request: GetKeyRequest) -> Result<Key, Error>
Returns a key, deleted or not. Needs kms.key.get on the project.
Sourcepub async fn list_keys(
&self,
request: ListKeysRequest,
) -> Result<ListKeysResponse, Error>
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.
Sourcepub fn all_keys(&self, request: ListKeysRequest) -> Pages<Key>
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.
Sourcepub async fn create_key(&self, request: CreateKeyRequest) -> Result<Key, Error>
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.
Sourcepub async fn update_key(&self, request: UpdateKeyRequest) -> Result<Key, Error>
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.
Sourcepub async fn delete_key(&self, request: DeleteKeyRequest) -> Result<Key, Error>
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.
Sourcepub async fn undelete_key(
&self,
request: UndeleteKeyRequest,
) -> Result<Key, Error>
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.delete on
the project.
Sourcepub async fn rotate_key(&self, request: RotateKeyRequest) -> Result<Key, Error>
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.
Sourcepub async fn encrypt(
&self,
request: EncryptRequest,
) -> Result<EncryptResponse, Error>
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, and with BAD_REQUEST for a signing key. Needs
kms.key.encrypt on the project.
Sourcepub async fn decrypt(
&self,
request: DecryptRequest,
) -> Result<DecryptResponse, Error>
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, and with
CONFLICT for a key that isn’t enabled. Needs kms.key.decrypt on the
project.
Sourcepub async fn generate_data_key(
&self,
request: GenerateDataKeyRequest,
) -> Result<GenerateDataKeyResponse, Error>
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. Needs
kms.key.generate_data_key on the project.
Sourcepub async fn sign(&self, request: SignRequest) -> Result<SignResponse, Error>
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.
Sourcepub async fn get_public_key(
&self,
request: GetPublicKeyRequest,
) -> Result<PublicKey, Error>
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.