pub(super) fn find_key(
        &self,
        session: CK_SESSION_HANDLE,
        key_id: [u8; 4],
        key_type: KeyPairType,
    ) -> Result<CK_OBJECT_HANDLE> {
        let mut template = vec![CK_ATTRIBUTE::new(pkcs11::types::CKA_ID).with_bytes(&key_id)];
        match key_type {
            KeyPairType::PublicKey => template.push(
                CK_ATTRIBUTE::new(pkcs11::types::CKA_CLASS)
                    .with_ck_ulong(&pkcs11::types::CKO_PUBLIC_KEY),
            ),
            KeyPairType::PrivateKey => template.push(
                CK_ATTRIBUTE::new(pkcs11::types::CKA_CLASS)
                    .with_ck_ulong(&pkcs11::types::CKO_PRIVATE_KEY),
            ),
            KeyPairType::Any => (),
        }

        trace!("FindObjectsInit command");
        if let Err(e) = self.backend.find_objects_init(session, &template) {
            format_error!("Object enumeration init failed", e);
            Err(utils::to_response_status(e))
        } else {
            trace!("FindObjects command");
            match self.backend.find_objects(session, 1) {
                Ok(objects) => {
                    trace!("FindObjectsFinal command");
                    if let Err(e) = self.backend.find_objects_final(session) {
                        format_error!("Object enumeration final failed", e);
                        Err(utils::to_response_status(e))
                    } else if objects.is_empty() {
                        Err(ResponseStatus::PsaErrorDoesNotExist)
                    } else {
                        Ok(objects[0])
                    }
                }
                Err(e) => {
                    format_error!("Finding objects failed", e);
                    Err(utils::to_response_status(e))
                }
            }
        }
    }
/// Find the PKCS 11 object handle corresponding to the key ID and the key type (public,
/// private or any key type) given as parameters for the current session.
Find the PKCS 11 object handle corresponding to the key ID and the key type (public,
private or any key type) given as parameters for the current session.
Find the PKCS 11 object handle corresponding to the key ID and the key type ( public private or any key type ) given as parameters for the current session .
pub(super) fn find_key(
        &self,
        session: CK_SESSION_HANDLE,
        key_id: [u8; 4],
        key_type: KeyPairType,
    ) -> Result<CK_OBJECT_HANDLE> {
        let mut template = vec![CK_ATTRIBUTE::new(pkcs11::types::CKA_ID).with_bytes(&key_id)];
        match key_type {
            KeyPairType::PublicKey => template.push(
                CK_ATTRIBUTE::new(pkcs11::types::CKA_CLASS)
                    .with_ck_ulong(&pkcs11::types::CKO_PUBLIC_KEY),
            ),
            KeyPairType::PrivateKey => template.push(
                CK_ATTRIBUTE::new(pkcs11::types::CKA_CLASS)
                    .with_ck_ulong(&pkcs11::types::CKO_PRIVATE_KEY),
            ),
            KeyPairType::Any => (),
        }
        trace!("FindObjectsInit command");
        if let Err(e) = self.backend.find_objects_init(session, &template) {
            format_error!("Object enumeration init failed", e);
            Err(utils::to_response_status(e))
        } else {
            trace!("FindObjects command");
            match self.backend.find_objects(session, 1) {
                Ok(objects) => {
                    trace!("FindObjectsFinal command");
                    if let Err(e) = self.backend.find_objects_final(session) {
                        format_error!("Object enumeration final failed", e);
                        Err(utils::to_response_status(e))
                    } else if objects.is_empty() {
                        Err(ResponseStatus::PsaErrorDoesNotExist)
                    } else {
                        Ok(objects[0])
                    }
                }
                Err(e) => {
                    format_error!("Finding objects failed", e);
                    Err(utils::to_response_status(e))
                }
            }
        }
    }
pub ( super ) fn find_key ( & self , session : CK_SESSION_HANDLE , key_id : [ u8 ; 4 ] , key_type : KeyPairType , ) -> Result < CK_OBJECT_HANDLE > { let mut template = vec ! [ CK_ATTRIBUTE new ( pkcs11 types CKA_ID ) with_bytes ( key_id ) ] ; match key_type { KeyPairType :: PublicKey => template . push ( CK_ATTRIBUTE :: new ( pkcs11 :: types :: CKA_CLASS ) . with_ck_ulong ( & pkcs11 :: types :: CKO_PUBLIC_KEY ) , ) , KeyPairType :: PrivateKey => template . push ( CK_ATTRIBUTE :: new ( pkcs11 :: types :: CKA_CLASS ) . with_ck_ulong ( & pkcs11 :: types :: CKO_PRIVATE_KEY ) , ) , KeyPairType :: Any => ( ) , } trace ! ( " " ) ; if let Err ( e ) = self . backend . find_objects_init ( session , & template ) { format_error ! ( " " e ) ; Err ( utils :: to_response_status ( e ) ) } else { trace ! ( " " ) ; match self . backend . find_objects ( session , 1 ) { Ok ( objects ) => { trace ! ( " " ) ; if let Err ( e ) = self . backend . find_objects_final ( session ) { format_error ! ( " " e ) ; Err ( utils :: to_response_status ( e ) ) } else if objects . is_empty ( ) { Err ( ResponseStatus :: PsaErrorDoesNotExist ) } else { Ok ( objects [ 0 ] ) } } Err ( e ) => { format_error ! ( " " e ) ; Err ( utils :: to_response_status ( e ) ) } } } }
Find the PKCS 11 object handle corresponding to the key ID and the key type (public,
private or any key type) given as parameters for the current session.
Find the PKCS 11 object handle corresponding to the key ID and the key type ( public private or any key type ) given as parameters for the current session .
&self
session
CK_SESSION_HANDLE
key_id
[u8; 4]
key_type
KeyPairType
&self
session
CK_SESSION_HANDLE
key_id
[u8; 4]
key_type
KeyPairType