fn node_ids_to_pubkeys(
    registry: Arc<dyn RegistryClient>,
    nodes: BTreeSet<NodeId>,
    key_purpose: KeyPurpose,
    registry_version: RegistryVersion,
) -> CryptoResult<(Vec<CspPublicKey>, AlgorithmId)> {
    let mut algorithm_set = BTreeSet::<AlgorithmId>::new();
    let csp_pubkeys = {
        let csp_pubkeys: CryptoResult<Vec<CspPublicKey>> = nodes
            .iter()
            .map(|node_id| {
                let pk_proto = key_from_registry(
                    Arc::clone(&registry),
                    node_id.to_owned(),
                    key_purpose,
                    registry_version,
                )?;
                let algorithm_id = AlgorithmId::from(pk_proto.algorithm);
                algorithm_set.insert(algorithm_id);
                CspPublicKey::try_from(pk_proto)
            })
            .collect();
        // Using ? directly on collect() does not have the intended effect, so it is
        // applied to the result below. Alternatively, the ? could be applied further
        // below, but then algorithm inconsistency errors would take priority over
        // missing/invalid keys from the registry.
        csp_pubkeys?
    };

    let algorithm = {
        if algorithm_set.len() != 1 {
            return Err(CryptoError::InconsistentAlgorithms {
                algorithms: algorithm_set,
                key_purpose,
                registry_version,
            });
        }
        *algorithm_set
            .iter()
            .next()
            .expect("Set was unexpectedly empty")
    };

    Ok((csp_pubkeys, algorithm))
}
/// This helper method performs the following two tasks:
/// 1. maps node IDs to CSP public keys by querying the registry
/// 2. ensures that the public keys' algorithm IDs are all equal
///
/// Returns the public keys as well as the unique algorithm ID.
///
/// Returns an error if
/// - a node's public key is not found in the registry
/// - one of the public keys fetched from the registry is invalid
/// - the public key's algorithms are not all equal
This helper method performs the following two tasks:
1. maps node IDs to CSP public keys by querying the registry
2. ensures that the public keys' algorithm IDs are all equal

Returns the public keys as well as the unique algorithm ID.

Returns an error if
a node's public key is not found in the registry
one of the public keys fetched from the registry is invalid
the public key's algorithms are not all equal
This helper method performs the following two tasks : 1 . maps node IDs to CSP public keys by querying the registry 2 . ensures that the public keys ' algorithm IDs are all equal Returns the public keys as well as the unique algorithm ID . Returns an error if a node ' s public key is not found in the registry one of the public keys fetched from the registry is invalid the public key ' s algorithms are not all equal
fn node_ids_to_pubkeys(
    registry: Arc<dyn RegistryClient>,
    nodes: BTreeSet<NodeId>,
    key_purpose: KeyPurpose,
    registry_version: RegistryVersion,
) -> CryptoResult<(Vec<CspPublicKey>, AlgorithmId)> {
    let mut algorithm_set = BTreeSet::<AlgorithmId>::new();
    let csp_pubkeys = {
        let csp_pubkeys: CryptoResult<Vec<CspPublicKey>> = nodes
            .iter()
            .map(|node_id| {
                let pk_proto = key_from_registry(
                    Arc::clone(&registry),
                    node_id.to_owned(),
                    key_purpose,
                    registry_version,
                )?;
                let algorithm_id = AlgorithmId::from(pk_proto.algorithm);
                algorithm_set.insert(algorithm_id);
                CspPublicKey::try_from(pk_proto)
            })
            .collect();
        // Using ? directly on collect() does not have the intended effect, so it is
        // applied to the result below. Alternatively, the ? could be applied further
        // below, but then algorithm inconsistency errors would take priority over
        // missing/invalid keys from the registry.
        csp_pubkeys?
    };
    let algorithm = {
        if algorithm_set.len() != 1 {
            return Err(CryptoError::InconsistentAlgorithms {
                algorithms: algorithm_set,
                key_purpose,
                registry_version,
            });
        }
        *algorithm_set
            .iter()
            .next()
            .expect("Set was unexpectedly empty")
    };
    Ok((csp_pubkeys, algorithm))
}
fn node_ids_to_pubkeys ( registry : Arc < dyn RegistryClient > , nodes : BTreeSet < NodeId > , key_purpose : KeyPurpose , registry_version : RegistryVersion , ) -> CryptoResult < ( Vec < CspPublicKey > , AlgorithmId ) > { let mut algorithm_set = BTreeSet :: < AlgorithmId > :: new ( ) ; let csp_pubkeys = { let csp_pubkeys : CryptoResult < Vec < CspPublicKey > > = nodes . iter ( ) . map ( | node_id | { let pk_proto = key_from_registry ( Arc :: clone ( & registry ) , node_id . to_owned ( ) , key_purpose , registry_version , ) ? ; let algorithm_id = AlgorithmId :: from ( pk_proto . algorithm ) ; algorithm_set . insert ( algorithm_id ) ; CspPublicKey :: try_from ( pk_proto ) } ) . collect ( ) ; // Using ? directly on collect() does not have the intended effect, so it is // applied to the result below. Alternatively, the ? could be applied further // below, but then algorithm inconsistency errors would take priority over // missing/invalid keys from the registry. csp_pubkeys ? } ; let algorithm = { if algorithm_set . len ( ) != 1 { return Err ( CryptoError :: InconsistentAlgorithms { algorithms : algorithm_set , key_purpose , registry_version , } ) ; } * algorithm_set . iter ( ) . next ( ) . expect ( " " ) } ; Ok ( ( csp_pubkeys , algorithm ) ) }
This helper method performs the following two tasks:
1. maps node IDs to CSP public keys by querying the registry
2. ensures that the public keys' algorithm IDs are all equal
This helper method performs the following two tasks : 1 . maps node IDs to CSP public keys by querying the registry 2 . ensures that the public keys ' algorithm IDs are all equal
registry
Arc<dyn RegistryClient>
nodes
BTreeSet<NodeId>
key_purpose
KeyPurpose
registry_version
RegistryVersion
registry
Arc<dyn RegistryClient>
nodes
BTreeSet<NodeId>
key_purpose
KeyPurpose
registry_version
RegistryVersion