[x509] Encode EC_KEY as SubjectPublicKeyInfo

This cl adds bssl wrappers that enable the encoding of bssl::EC_KEY
objects as SubjectPublicKeyInfo. This will facilitate the econding
of the public key in the client VM's CSR in the x509 certificate
later.

Test: atest libbssl_avf_nostd.test
Bug: 309441500
Change-Id: I374a4a9d7e9ff5408cd176dfca09b670da507e11
diff --git a/libs/bssl/tests/eckey_test.rs b/libs/bssl/tests/eckey_test.rs
index 3dd243c..968af63 100644
--- a/libs/bssl/tests/eckey_test.rs
+++ b/libs/bssl/tests/eckey_test.rs
@@ -12,8 +12,18 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-use bssl_avf::{sha256, ApiName, EcKey, EcdsaError, Error, Result};
+use bssl_avf::{sha256, ApiName, EcKey, EcdsaError, Error, EvpPKey, Result};
 use coset::CborSerializable;
+use spki::{
+    der::{AnyRef, Decode},
+    AlgorithmIdentifier, ObjectIdentifier, SubjectPublicKeyInfo,
+};
+
+/// OID value for general-use NIST EC keys held in PKCS#8 and X.509; see RFC 5480 s2.1.1.
+const X509_NIST_OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.10045.2.1");
+
+/// OID value in `AlgorithmIdentifier.parameters` for P-256; see RFC 5480 s2.1.1.1.
+const ALGO_PARAM_P256_OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.10045.3.1.7");
 
 const MESSAGE1: &[u8] = b"test message 1";
 const MESSAGE2: &[u8] = b"test message 2";
@@ -30,6 +40,23 @@
 }
 
 #[test]
+fn subject_public_key_info_serialization() -> Result<()> {
+    let mut ec_key = EcKey::new_p256()?;
+    ec_key.generate_key()?;
+    let pkey: EvpPKey = ec_key.try_into()?;
+    let subject_public_key_info = pkey.subject_public_key_info()?;
+
+    let subject_public_key_info = SubjectPublicKeyInfo::from_der(&subject_public_key_info).unwrap();
+    let expected_algorithm = AlgorithmIdentifier {
+        oid: X509_NIST_OID,
+        parameters: Some(AnyRef::from(&ALGO_PARAM_P256_OID)),
+    };
+    assert_eq!(expected_algorithm, subject_public_key_info.algorithm);
+    assert!(!subject_public_key_info.subject_public_key.to_vec().is_empty());
+    Ok(())
+}
+
+#[test]
 fn cose_public_key_serialization() -> Result<()> {
     let mut ec_key = EcKey::new_p256()?;
     ec_key.generate_key()?;