fn verify_paths(
    state_reader: &dyn StateReader<State = ReplicatedState>,
    user: &UserId,
    paths: &[Path],
    targets: &CanisterIdSet,
) -> Result<(), VerifyPathsError> {
    let state = state_reader.get_latest_state().take();
    let mut num_request_ids = 0;

    // Convert the paths to slices to make it easier to match below.
    let paths: Vec<Vec<&[u8]>> = paths
        .iter()
        .map(|path| path.iter().map(|label| label.as_bytes()).collect())
        .collect();

    for path in paths {
        match path.as_slice() {
            [b"time"] => {}
            [b"canister", _canister_id, b"controller"] => {}
            [b"canister", _canister_id, b"module_hash"] => {}
            [b"subnet", _subnet_id, b"public_key"] => {}
            [b"request_status", request_id] | [b"request_status", request_id, ..] => {
                num_request_ids += 1;

                if num_request_ids > MAX_READ_STATE_REQUEST_IDS {
                    return Err(VerifyPathsError::TooManyRequests);
                }

                // Verify that the request was signed by the same user.
                if let Ok(message_id) = MessageId::try_from(*request_id) {
                    let ingress_status = state.get_ingress_status(&message_id);

                    if let Some(ingress_user_id) = ingress_status.user_id() {
                        if let Some(receiver) = ingress_status.receiver() {
                            if ingress_user_id != *user || !targets.contains(&receiver) {
                                return Err(VerifyPathsError::UnauthorizedRequestId);
                            }
                        }
                    }
                } else {
                    return Err(VerifyPathsError::InvalidRequestId);
                }
            }
            _ => {
                // All other paths are unsupported.
                return Err(VerifyPathsError::InvalidPath);
            }
        }
    }

    Ok(())
}
// Verifies that the `user` is authorized to retrieve the `paths` requested.
Verifies that the `user` is authorized to retrieve the `paths` requested.
Verifies that the ` user ` is authorized to retrieve the ` paths ` requested .
fn verify_paths(
    state_reader: &dyn StateReader<State = ReplicatedState>,
    user: &UserId,
    paths: &[Path],
    targets: &CanisterIdSet,
) -> Result<(), VerifyPathsError> {
    let state = state_reader.get_latest_state().take();
    let mut num_request_ids = 0;
    // Convert the paths to slices to make it easier to match below.
    let paths: Vec<Vec<&[u8]>> = paths
        .iter()
        .map(|path| path.iter().map(|label| label.as_bytes()).collect())
        .collect();
    for path in paths {
        match path.as_slice() {
            [b"time"] => {}
            [b"canister", _canister_id, b"controller"] => {}
            [b"canister", _canister_id, b"module_hash"] => {}
            [b"subnet", _subnet_id, b"public_key"] => {}
            [b"request_status", request_id] | [b"request_status", request_id, ..] => {
                num_request_ids += 1;
                if num_request_ids > MAX_READ_STATE_REQUEST_IDS {
                    return Err(VerifyPathsError::TooManyRequests);
                }
                // Verify that the request was signed by the same user.
                if let Ok(message_id) = MessageId::try_from(*request_id) {
                    let ingress_status = state.get_ingress_status(&message_id);
                    if let Some(ingress_user_id) = ingress_status.user_id() {
                        if let Some(receiver) = ingress_status.receiver() {
                            if ingress_user_id != *user || !targets.contains(&receiver) {
                                return Err(VerifyPathsError::UnauthorizedRequestId);
                            }
                        }
                    }
                } else {
                    return Err(VerifyPathsError::InvalidRequestId);
                }
            }
            _ => {
                // All other paths are unsupported.
                return Err(VerifyPathsError::InvalidPath);
            }
        }
    }
    Ok(())
}
fn verify_paths ( state_reader : & dyn StateReader < State = ReplicatedState > , user : & UserId , paths : & [ Path ] , targets : & CanisterIdSet , ) -> Result < ( ) , VerifyPathsError > { let state = state_reader . get_latest_state ( ) . take ( ) ; let mut num_request_ids = 0 ; // Convert the paths to slices to make it easier to match below. let paths : Vec < Vec < & [ u8 ] > > = paths . iter ( ) . map ( | path | path . iter ( ) . map ( | label | label . as_bytes ( ) ) . collect ( ) ) . collect ( ) ; for path in paths { match path . as_slice ( ) { [ b" " ] => { } [ b" " , _canister_id , b" " ] => { } [ b" " , _canister_id , b" " ] => { } [ b" " , _subnet_id , b" " ] => { } [ b" " , request_id ] | [ b" " , request_id , .. ] => { num_request_ids += 1 ; if num_request_ids > MAX_READ_STATE_REQUEST_IDS { return Err ( VerifyPathsError :: TooManyRequests ) ; } // Verify that the request was signed by the same user. if let Ok ( message_id ) = MessageId :: try_from ( * request_id ) { let ingress_status = state . get_ingress_status ( & message_id ) ; if let Some ( ingress_user_id ) = ingress_status . user_id ( ) { if let Some ( receiver ) = ingress_status . receiver ( ) { if ingress_user_id != * user || ! targets . contains ( & receiver ) { return Err ( VerifyPathsError :: UnauthorizedRequestId ) ; } } } } else { return Err ( VerifyPathsError :: InvalidRequestId ) ; } } _ => { // All other paths are unsupported. return Err ( VerifyPathsError :: InvalidPath ) ; } } } Ok ( ( ) ) }
Verifies that the `user` is authorized to retrieve the `paths` requested.
Verifies that the ` user ` is authorized to retrieve the ` paths ` requested .
state_reader
&dyn StateReader<State = ReplicatedState>
user
&UserId
paths
&[Path]
targets
&CanisterIdSet
state_reader
&dyn StateReader<State = ReplicatedState>
user
&UserId
paths
&[Path]
targets
&CanisterIdSet