fn check_computed_public_key()

in aws-lc-rs/src/agreement/ephemeral.rs [354:395]


    fn check_computed_public_key(
        algorithm: &AlgorithmID,
        expected_format: &str,
        expected_public_key_bytes: &[u8],
        computed_public: &PublicKey,
    ) {
        match (algorithm, expected_format) {
            (_, "X509") => {
                let der = AsDer::<PublicKeyX509Der>::as_der(computed_public)
                    .expect("serialize to uncompressed format");
                assert_eq!(
                    expected_public_key_bytes,
                    der.as_ref(),
                    "hex: {:x?}",
                    der.as_ref()
                );
            }
            (
                AlgorithmID::ECDH_P256 | AlgorithmID::ECDH_P384 | AlgorithmID::ECDH_P521,
                "COMPRESSED",
            ) => {
                let bin = AsBigEndian::<EcPublicKeyCompressedBin>::as_be_bytes(computed_public)
                    .expect("serialize to compressed format");
                assert_eq!(expected_public_key_bytes, bin.as_ref());
            }
            (
                AlgorithmID::ECDH_P256 | AlgorithmID::ECDH_P384 | AlgorithmID::ECDH_P521,
                "UNCOMPRESSED" | "",
            ) => {
                let bin = AsBigEndian::<EcPublicKeyUncompressedBin>::as_be_bytes(computed_public)
                    .expect("serialize to uncompressed format");
                assert_eq!(expected_public_key_bytes, bin.as_ref());
                assert_eq!(expected_public_key_bytes, computed_public.as_ref());
            }
            (AlgorithmID::X25519, "") => {
                assert_eq!(expected_public_key_bytes, computed_public.as_ref());
            }
            (ai, pf) => {
                panic!("Unexpected PeerFormat={pf:?} for {ai:?}")
            }
        }
    }