pub struct Client<T: ReadWrite> { /* private fields */ }Expand description
A client for serializing KMIP requests and deserializing KMIP responses to/from an established read/write stream.
Use the crate::net::ClientBuilder to build a Client instance to work with.
Implementations§
Source§impl<T: ReadWrite> Client<T>
impl<T: ReadWrite> Client<T>
Sourcepub fn query(&mut self) -> NetResult<QueryResponsePayload>
pub fn query(&mut self) -> NetResult<QueryResponsePayload>
Serialize a KMIP 1.0 Query request.
See also: do_request()
Sourcepub fn create_rsa_key_pair(
&mut self,
key_length: i32,
private_key_name: String,
public_key_name: String,
) -> NetResult<(String, String)>
pub fn create_rsa_key_pair( &mut self, key_length: i32, private_key_name: String, public_key_name: String, ) -> NetResult<(String, String)>
Serialize a KMIP 1.0 Create Key Pair request to create an RSA key pair.
See also: do_request()
Creates an RSA key pair.
To create keys of other types or with other parameters you must compose the Create Key Pair request manually and pass it to do_request() directly.
Sourcepub fn rng_retrieve(&mut self, num_bytes: i32) -> NetResult<Vec<u8>>
pub fn rng_retrieve(&mut self, num_bytes: i32) -> NetResult<Vec<u8>>
Serialize a KMIP 1.2 Rng Retrieve operation to retrieve a number of random bytes.
See also: do_request()
Sourcepub fn sign(
&mut self,
private_key_id: &str,
in_bytes: &[u8],
) -> NetResult<Vec<u8>>
pub fn sign( &mut self, private_key_id: &str, in_bytes: &[u8], ) -> NetResult<Vec<u8>>
Serialize a KMIP 1.2 Sign operation to sign the given bytes with the given private key ID.
See also: do_request()
Sourcepub fn activate_key(&mut self, private_key_id: &str) -> NetResult<()>
pub fn activate_key(&mut self, private_key_id: &str) -> NetResult<()>
Serialize a KMIP 1.0 Activate operation to activate a given private key ID.
See also: do_request()
To activate other kinds of managed object you must compose the Activate request manually and pass it to do_request() directly.
Sourcepub fn revoke_key(&mut self, private_key_id: &str) -> NetResult<()>
pub fn revoke_key(&mut self, private_key_id: &str) -> NetResult<()>
Serialize a KMIP 1.0 Revoke operation to deactivate a given private key ID.
See also: do_request()
To deactivate other kinds of managed object you must compose the Revoke request manually and pass it to do_request() directly.
Sourcepub fn destroy_key(&mut self, key_id: &str) -> NetResult<()>
pub fn destroy_key(&mut self, key_id: &str) -> NetResult<()>
Serialize a KMIP 1.0 Destroy operation to destroy a given private key ID.
See also: do_request()
To destroy other kinds of managed object you must compose the Destroy request manually and pass it to do_request() directly.
Sourcepub fn rename_key(&mut self, key_id: &str, new_name: String) -> NetResult<()>
pub fn rename_key(&mut self, key_id: &str, new_name: String) -> NetResult<()>
Serialize a KMIP 1.0 ModifyAttribute operation to rename a given key ID.
See also: do_request()
To modify other attributes of managed objects you must compose the Modify Attribute request manually and pass it to do_request() directly.
Sourcepub fn get_key(&mut self, key_id: &str) -> NetResult<GetResponsePayload>
pub fn get_key(&mut self, key_id: &str) -> NetResult<GetResponsePayload>
Serialize a KMIP 1.0 Get operation to get the details of a given key ID.
See also: do_request()
Source§impl<T: ReadWrite> Client<T>
impl<T: ReadWrite> Client<T>
Sourcepub fn do_request(
&mut self,
request: RequestMessage,
) -> NetResult<Vec<NetResult<BatchItem>>>
pub fn do_request( &mut self, request: RequestMessage, ) -> NetResult<Vec<NetResult<BatchItem>>>
Write request bytes to the given stream and read, deserialize and sanity check the response.
Tip: For cases when the response is expected to consist of only a
single batch item,TryInto can be used to simplify handling of the
result, e.g.:
// Setup the request.
let wanted_info = vec![
QueryFunction::QueryOperations,
QueryFunction::QueryObjects,
QueryFunction::QueryServerInformation,
];
let request = RequestPayload::Query(wanted_info);
// Execute the request and capture the response.
let res = client.do_request_payload(request).await?.try_into()?;
let ResponsePayload::Query(payload) = res else {
return Err(NetError::UnexpectedData(format!(
"Expected Query payload but response has {res}"
)));
};Note: Enforcing a timeout on this operation is the responsibility of the caller.
Sourcepub fn do_request_payload(
&mut self,
payload: RequestPayload,
) -> NetResult<Vec<NetResult<BatchItem>>>
pub fn do_request_payload( &mut self, payload: RequestPayload, ) -> NetResult<Vec<NetResult<BatchItem>>>
Serialize the given request to the stream and deserialize the response.
Automatically constructs the request message wrapper around the payload including the crate::types::request::RequestHeader and crate::types::request::BatchItem.
Only supports a single batch item.
Sets the request operation to RequestPayload::operation().
§Errors
Will fail if there is a problem serializing the request, writing to or reading from the stream, deserializing the response or if the response does not indicate operation success or contains more than one batch item.
pub fn do_request_batch( &mut self, batch_items: Vec<BatchItem>, ) -> NetResult<Vec<NetResult<BatchItem>>>
Source§impl<T: ReadWrite> Client<T>
impl<T: ReadWrite> Client<T>
Sourcepub fn auth(&self) -> Option<&Authentication>
pub fn auth(&self) -> Option<&Authentication>
Get the authentication settings used by this client.
Sourcepub fn max_message_size(&self) -> i32
pub fn max_message_size(&self) -> i32
Get the maximum message size in bytes permitted by this client.
Sourcepub fn connection_error_count(&self) -> usize
pub fn connection_error_count(&self) -> usize
Get the count of connection errors experienced by this Client.