fn authenticated_peer(
    client_cert_chain_from_handshake: &CspCertificateChain,
    allowed_client_certs: &HashSet<TlsPublicKeyCert>,
    trusted_node_certs: &BTreeMap<NodeId, TlsPublicKeyCert>,
) -> Result<AuthenticatedPeer, TlsServerHandshakeError> {
    let authenticated_node = check_cert_and_get_authenticated_client_node_id(
        trusted_node_certs,
        client_cert_chain_from_handshake.leaf(),
    );
    match authenticated_node {
        Ok(authenticated_node) => Ok(AuthenticatedPeer::Node(authenticated_node)),
        Err(node_authentication_error) => {
            if allowed_client_certs.contains(client_cert_chain_from_handshake.root()) {
                Ok(AuthenticatedPeer::Cert(
                    client_cert_chain_from_handshake.leaf().clone(),
                ))
            } else {
                Err(node_authentication_error)
            }
        }
    }
}
/// Determines the authenticated peer from the client's certificate chain.
///
/// To do so, the following steps are taken:
/// 1. Determine the peer's node ID N_claimed from the _subject name_ of
///    the certificate C_handshake that the peer presented during the
///    handshake (and for which the peer therefore knows the private key).
///    If N_claimed is contained in `trusted_node_certs`, determine the
///    certificate C_registry by querying the registry for the TLS certificate
///    of node with ID N_claimed, and if C_registry is equal to C_handshake,
///    then the peer successfully authenticated as node N_claimed. Otherwise,
///    step 2 is taken.
/// 2. Compare the root of the certificate chain that the peer presented during
///    the handshake (and for which the peer therefore knows the private key of
///    the chain's leaf certificate) to all the certificates in
///    `allowed_client_certs`. If there is a match, then the peer represented by
///    the chain's leaf certificate successfully authenticated.
///
/// If neither an authenticated node nor an authenticated certificate can be
/// determined, then the error produced when trying to authenticate a node is
/// returned.
Determines the authenticated peer from the client's certificate chain.
To do so, the following steps are taken:
1. Determine the peer's node ID N_claimed from the _subject name_ of
the certificate C_handshake that the peer presented during the
handshake (and for which the peer therefore knows the private key).
If N_claimed is contained in `trusted_node_certs`, determine the
certificate C_registry by querying the registry for the TLS certificate
of node with ID N_claimed, and if C_registry is equal to C_handshake,
then the peer successfully authenticated as node N_claimed. Otherwise,
step 2 is taken.
2. Compare the root of the certificate chain that the peer presented during
the handshake (and for which the peer therefore knows the private key of
the chain's leaf certificate) to all the certificates in
`allowed_client_certs`. If there is a match, then the peer represented by
the chain's leaf certificate successfully authenticated.

If neither an authenticated node nor an authenticated certificate can be
determined, then the error produced when trying to authenticate a node is
returned.
Determines the authenticated peer from the client ' s certificate chain . To do so the following steps are taken : 1 . Determine the peer ' s node ID N_claimed from the _subject name_ of the certificate C_handshake that the peer presented during the handshake ( and for which the peer therefore knows the private key ) . If N_claimed is contained in ` trusted_node_certs ` determine the certificate C_registry by querying the registry for the TLS certificate of node with ID N_claimed and if C_registry is equal to C_handshake then the peer successfully authenticated as node N_claimed . Otherwise step 2 is taken . 2 . Compare the root of the certificate chain that the peer presented during the handshake ( and for which the peer therefore knows the private key of the chain ' s leaf certificate ) to all the certificates in ` allowed_client_certs ` . If there is a match then the peer represented by the chain ' s leaf certificate successfully authenticated . If neither an authenticated node nor an authenticated certificate can be determined then the error produced when trying to authenticate a node is returned .
fn authenticated_peer(
    client_cert_chain_from_handshake: &CspCertificateChain,
    allowed_client_certs: &HashSet<TlsPublicKeyCert>,
    trusted_node_certs: &BTreeMap<NodeId, TlsPublicKeyCert>,
) -> Result<AuthenticatedPeer, TlsServerHandshakeError> {
    let authenticated_node = check_cert_and_get_authenticated_client_node_id(
        trusted_node_certs,
        client_cert_chain_from_handshake.leaf(),
    );
    match authenticated_node {
        Ok(authenticated_node) => Ok(AuthenticatedPeer::Node(authenticated_node)),
        Err(node_authentication_error) => {
            if allowed_client_certs.contains(client_cert_chain_from_handshake.root()) {
                Ok(AuthenticatedPeer::Cert(
                    client_cert_chain_from_handshake.leaf().clone(),
                ))
            } else {
                Err(node_authentication_error)
            }
        }
    }
}
fn authenticated_peer ( client_cert_chain_from_handshake : & CspCertificateChain , allowed_client_certs : & HashSet < TlsPublicKeyCert > , trusted_node_certs : & BTreeMap < NodeId , TlsPublicKeyCert > , ) -> Result < AuthenticatedPeer , TlsServerHandshakeError > { let authenticated_node = check_cert_and_get_authenticated_client_node_id ( trusted_node_certs , client_cert_chain_from_handshake . leaf ( ) , ) ; match authenticated_node { Ok ( authenticated_node ) => Ok ( AuthenticatedPeer :: Node ( authenticated_node ) ) , Err ( node_authentication_error ) => { if allowed_client_certs . contains ( client_cert_chain_from_handshake . root ( ) ) { Ok ( AuthenticatedPeer :: Cert ( client_cert_chain_from_handshake . leaf ( ) . clone ( ) , ) ) } else { Err ( node_authentication_error ) } } } }
Determines the authenticated peer from the client's certificate chain.
Determines the authenticated peer from the client ' s certificate chain .
client_cert_chain_from_handshake
&CspCertificateChain
allowed_client_certs
&HashSet<TlsPublicKeyCert>
trusted_node_certs
&BTreeMap<NodeId, TlsPublicKeyCert>
client_cert_chain_from_handshake
&CspCertificateChain
allowed_client_certs
&HashSet<TlsPublicKeyCert>
trusted_node_certs
&BTreeMap<NodeId, TlsPublicKeyCert>