Use libhex to encode hex string in libs/apkverify/

Bug: 239413416
Test: libapkverify.test, libapkverify.integration_test
Change-Id: I21285b1528f6eb8806a594f53b7b1045255af3b5
Signed-off-by: Tanmoy Mollik <triploblastic@google.com>
This commit is contained in:
Tanmoy Mollik 2022-11-25 15:00:04 +00:00
parent e0945ad0e4
commit 40ff803624
3 changed files with 6 additions and 11 deletions

View File

@ -12,6 +12,7 @@ rust_defaults {
"libanyhow",
"libbyteorder",
"libbytes",
"libhex",
"liblog_rust",
"libnum_traits",
"libopenssl",
@ -33,7 +34,6 @@ rust_test {
name: "libapkverify.test",
defaults: ["libapkverify.defaults"],
test_suites: ["general-tests"],
rustlibs: ["libhex"],
data: ["tests/data/*"],
}

View File

@ -235,7 +235,7 @@ mod tests {
use std::fs::File;
use std::mem::size_of_val;
use crate::v3::{to_hex_string, APK_SIGNATURE_SCHEME_V3_BLOCK_ID};
use crate::v3::APK_SIGNATURE_SCHEME_V3_BLOCK_ID;
const CENTRAL_DIRECTORY_HEADER_SIGNATURE: u32 = 0x02014b50;
@ -276,8 +276,8 @@ mod tests {
let mut apk_sections = ApkSections::new(apk_file).unwrap();
let digest = apk_sections.compute_digest(SignatureAlgorithmID::DsaWithSha256).unwrap();
assert_eq!(
"0DF2426EA33AEDAF495D88E5BE0C6A1663FF0A81C5ED12D5B2929AE4B4300F2F",
to_hex_string(&digest[..])
"0df2426ea33aedaf495d88e5be0c6a1663ff0a81c5ed12d5b2929ae4b4300f2f",
hex::encode(&digest[..])
);
}

View File

@ -196,8 +196,8 @@ impl Signer {
ensure!(
computed == digest.digest.as_ref(),
"Digest mismatch: computed={:?} vs expected={:?}",
to_hex_string(&computed),
to_hex_string(&digest.digest),
hex::encode(&computed),
hex::encode(digest.digest.as_ref()),
);
// 7. Verify that public key of the first certificate of certificates is identical
@ -261,8 +261,3 @@ impl ReadFromBytes for PKey<pkey::Public> {
Ok(PKey::public_key_from_der(raw_public_key.as_ref())?)
}
}
#[inline]
pub(crate) fn to_hex_string(buf: &[u8]) -> String {
buf.iter().map(|b| format!("{:02X}", b)).collect()
}