[apkverify] Move HashAlgorithm to algorithms

Bug: 248999133
Test: libapkverify.test libapkverify.integration_test
Change-Id: I4b0b3f640187f8d6b1d0565678a84053250e6be9
diff --git a/libs/apkverify/src/v4.rs b/libs/apkverify/src/v4.rs
index 33e666f..715f742 100644
--- a/libs/apkverify/src/v4.rs
+++ b/libs/apkverify/src/v4.rs
@@ -26,7 +26,7 @@
 use std::io::{copy, Cursor, Read, Seek, SeekFrom, Write};
 use std::path::Path;
 
-use crate::algorithms::SignatureAlgorithmID;
+use crate::algorithms::{HashAlgorithm, SignatureAlgorithmID};
 use crate::hashtree::*;
 use crate::v3::extract_signer_and_apk_sections;
 
@@ -123,26 +123,6 @@
     }
 }
 
-/// Hash algorithm that can be used for idsig file.
-#[derive(Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
-#[repr(u32)]
-pub enum HashAlgorithm {
-    /// SHA2-256
-    SHA256 = 1,
-}
-
-impl HashAlgorithm {
-    fn from(val: u32) -> Result<HashAlgorithm> {
-        Self::from_u32(val).ok_or_else(|| anyhow!("{} is an unsupported hash algorithm", val))
-    }
-}
-
-impl Default for HashAlgorithm {
-    fn default() -> Self {
-        HashAlgorithm::SHA256
-    }
-}
-
 impl V4Signature<fs::File> {
     /// Creates a `V4Signature` struct from the given idsig path.
     pub fn from_idsig_path<P: AsRef<Path>>(idsig_path: P) -> Result<Self> {
@@ -239,7 +219,7 @@
         // fields in the struct are also length encoded.
         r.read_u32::<LittleEndian>()?;
         Ok(HashingInfo {
-            hash_algorithm: HashAlgorithm::from(r.read_u32::<LittleEndian>()?)?,
+            hash_algorithm: HashAlgorithm::from_read(&mut r)?,
             log2_blocksize: r.read_u8()?,
             salt: read_sized_array(&mut r)?,
             raw_root_hash: read_sized_array(&mut r)?,