FsCrypt update: support fscrypt policies v1 and v2

This patchset introduces support decryption for Android 11.

In this update we deprecate ext4crypt. To specify the
policy version to use, use TW_USE_FSCRYPT_POLICY := 1 or
TW_USE_FSCRYPT_POLICY := 2. By default policy version will
be set to 2 if this variable is omitted.

Change-Id: I62a29c1bef36c259ec4b11259f71be613d20a112
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index ff04e92..50511ce 100755
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -1333,7 +1333,12 @@
 	}
 }
 
-bool TWFunc::Get_Encryption_Policy(fscrypt_encryption_policy &policy, std::string path) {
+#ifdef TW_INCLUDE_CRYPTO
+#ifdef USE_FSCRYPT_POLICY_V1
+bool TWFunc::Get_Encryption_Policy(struct fscrypt_policy_v1 &policy, std::string path) {
+#else
+bool TWFunc::Get_Encryption_Policy(struct fscrypt_policy_v2 &policy, std::string path) {
+#endif
 	if (!TWFunc::Path_Exists(path)) {
 		LOGERR("Unable to find %s to get policy\n", path.c_str());
 		return false;
@@ -1345,20 +1350,25 @@
 	return true;
 }
 
-bool TWFunc::Set_Encryption_Policy(std::string path, const fscrypt_encryption_policy &policy) {
+#ifdef USE_FSCRYPT_POLICY_V1
+bool TWFunc::Set_Encryption_Policy(std::string path, struct fscrypt_policy_v1 &policy) {
+#else
+bool TWFunc::Set_Encryption_Policy(std::string path, struct fscrypt_policy_v2 &policy) {
+#endif
 	if (!TWFunc::Path_Exists(path)) {
 		LOGERR("unable to find %s to set policy\n", path.c_str());
 		return false;
 	}
 	uint8_t binary_policy[FS_KEY_DESCRIPTOR_SIZE];
-	char policy_hex[FS_KEY_DESCRIPTOR_SIZE_HEX];
-	policy_to_hex(binary_policy, policy_hex);
+	char policy_hex[FSCRYPT_KEY_IDENTIFIER_HEX_SIZE];
+	bytes_to_hex(binary_policy, FS_KEY_DESCRIPTOR_SIZE, policy_hex);
 	if (!fscrypt_policy_set_struct(path.c_str(), &policy)) {
 		LOGERR("unable to set policy for path: %s\n", path.c_str());
 		return false;
 	}
 	return true;
 }
+#endif
 
 string TWFunc::Check_For_TwrpFolder() {
 	string oldFolder = "";