1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! Get information about an object
//!
//! <https://developers.yubico.com/YubiHSM2/Commands/Get_Object_Info.html>
//!
use super::{Command, Response};
use {Adapter, CommandType, ObjectHandle, ObjectId, ObjectInfo, ObjectType, Session, SessionError};

/// Get information about an object
pub fn get_object_info<A: Adapter>(
    session: &mut Session<A>,
    object_id: ObjectId,
    object_type: ObjectType,
) -> Result<ObjectInfo, SessionError> {
    session
        .send_command(GetObjectInfoCommand(ObjectHandle::new(
            object_id,
            object_type,
        ))).map(|response| response.0)
}

/// Request parameters for `command::get_object_info`
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct GetObjectInfoCommand(pub(crate) ObjectHandle);

impl Command for GetObjectInfoCommand {
    type ResponseType = GetObjectInfoResponse;
}

/// Response from `command::get_object_info`
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct GetObjectInfoResponse(pub(crate) ObjectInfo);

impl Response for GetObjectInfoResponse {
    const COMMAND_TYPE: CommandType = CommandType::GetObjectInfo;
}