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 => (),
        }

        if let Err(e) = self.backend.find_objects_init(session, &template) {
            error!("Object enumeration init failed with {}", e);
            Err(utils::to_response_status(e))
        } else {
            match self.backend.find_objects(session, 1) {
                Ok(objects) => {
                    if let Err(e) = self.backend.find_objects_final(session) {
                        error!("Object enumeration final failed with {}", e);
                        Err(utils::to_response_status(e))
                    } else if objects.is_empty() {
                        Err(ResponseStatus::PsaErrorDoesNotExist)
                    } else {
                        Ok(objects[0])
                    }
                }
                Err(e) => {
                    error!("Finding objects failed with {}", e);
                    Err(utils::to_response_status(e))
                }
            }
        }
    }
/// Find the PKCS 11 object handle corresponding to the key ID and the key type (public or
/// private key) given as parameters for the current session.
Find the PKCS 11 object handle corresponding to the key ID and the key type (public or
private key) given as parameters for the current session.
Find the PKCS 11 object handle corresponding to the key ID and the key type ( public or private key ) given as parameters for the current session .
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 => (),
        }
        if let Err(e) = self.backend.find_objects_init(session, &template) {
            error!("Object enumeration init failed with {}", e);
            Err(utils::to_response_status(e))
        } else {
            match self.backend.find_objects(session, 1) {
                Ok(objects) => {
                    if let Err(e) = self.backend.find_objects_final(session) {
                        error!("Object enumeration final failed with {}", e);
                        Err(utils::to_response_status(e))
                    } else if objects.is_empty() {
                        Err(ResponseStatus::PsaErrorDoesNotExist)
                    } else {
                        Ok(objects[0])
                    }
                }
                Err(e) => {
                    error!("Finding objects failed with {}", e);
                    Err(utils::to_response_status(e))
                }
            }
        }
    }
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 => ( ) , } if let Err ( e ) = self . backend . find_objects_init ( session , & template ) { error ! ( " " e ) ; Err ( utils :: to_response_status ( e ) ) } else { match self . backend . find_objects ( session , 1 ) { Ok ( objects ) => { if let Err ( e ) = self . backend . find_objects_final ( session ) { error ! ( " " e ) ; Err ( utils :: to_response_status ( e ) ) } else if objects . is_empty ( ) { Err ( ResponseStatus :: PsaErrorDoesNotExist ) } else { Ok ( objects [ 0 ] ) } } Err ( e ) => { error ! ( " " e ) ; Err ( utils :: to_response_status ( e ) ) } } } }
Find the PKCS 11 object handle corresponding to the key ID and the key type (public or
private key) given as parameters for the current session.
Find the PKCS 11 object handle corresponding to the key ID and the key type ( public or private key ) 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