This commit is contained in:
Neeraj Gupta
2025-07-03 11:41:14 +05:30
parent 1b41d81839
commit 2d386c769b
4 changed files with 10 additions and 12 deletions

View File

@@ -19,8 +19,7 @@ class LivePhotoService {
_logger.severe(errMsg);
throw InvalidFileError(errMsg, InvalidReason.livePhotoVideoMissing);
}
final videoHash =
CryptoUtil.bin2base64(await CryptoUtil.getHash(liveVideo));
final videoHash = await CryptoUtil.getHash(liveVideo);
return (liveVideo, videoHash);
}

View File

@@ -22,12 +22,11 @@ class LocalMetadataService {
final TimeLogger t = TimeLogger(context: "getDroidMetadata");
final AssetEntity asset = await AssetEntityService.fromIDWithRetry(id);
final sourceFile = await AssetEntityService.sourceFromAsset(asset);
final String hash =
CryptoUtil.bin2base64(await CryptoUtil.getHash(sourceFile));
final String hash = await CryptoUtil.getHash(sourceFile);
final latLng = await asset.latlngAsync();
Location location =
Location(latitude: latLng.latitude, longitude: latLng.longitude);
final int size = sourceFile.lengthSync();
final int size = sourceFile.lengthSync();
final Map<String, IfdTag>? exifData = await tryExifFromFile(sourceFile);
final int? mviIndex = asset.type != AssetType.image
? null

View File

@@ -83,7 +83,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
}
}
fileHash = CryptoUtil.bin2base64(await CryptoUtil.getHash(sourceFile));
fileHash = await CryptoUtil.getHash(sourceFile);
if (file.fileType == FileType.livePhoto && Platform.isIOS) {
final (videoUrl, videoHash) =
await LivePhotoService.liveVideoAndHash(file.lAsset!.id);
@@ -98,7 +98,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
sourceFile = File(zippedPath);
// imgHash:vidHash
fileHash = '$fileHash$kHashSeprator$videoHash';
zipHash = CryptoUtil.bin2base64(await CryptoUtil.getHash(sourceFile));
zipHash = await CryptoUtil.getHash(sourceFile);
}
isDeleted = !(await asset.exists);
@@ -271,8 +271,7 @@ Future<MediaUploadData> _getSharedMediaUploadData(EnteFile file) async {
file.localID!,
file.isVideo,
);
final fileHash =
CryptoUtil.bin2base64(await CryptoUtil.getHash(sourceFile));
final fileHash = await CryptoUtil.getHash(sourceFile);
ui.Image? decodedImage;
if (file.fileType == FileType.image) {
decodedImage = await decodeImageInIsolate(localPath);

View File

@@ -52,7 +52,7 @@ Uint8List cryptoKdfDeriveFromKey(
}
// Returns the hash for a given file
Future<Uint8List> cryptoGenericHash(Map<String, dynamic> args) async {
Future<String> cryptoGenericHash(Map<String, dynamic> args) async {
final file = File(args["sourceFilePath"]);
final state =
Sodium.cryptoGenerichashInit(null, Sodium.cryptoGenerichashBytesMax);
@@ -63,7 +63,8 @@ Future<Uint8List> cryptoGenericHash(Map<String, dynamic> args) async {
Sodium.cryptoGenerichashUpdate(state, Uint8List.fromList(chunk));
}
}
return Sodium.cryptoGenerichashFinal(state, Sodium.cryptoGenerichashBytesMax);
final hash = Sodium.cryptoGenerichashFinal(state, Sodium.cryptoGenerichashBytesMax);
return Sodium.bin2base64(hash, variant: Sodium.base64VariantOriginal);
}
EncryptionResult chachaEncryptData(Map<String, dynamic> args) {
@@ -503,7 +504,7 @@ class CryptoUtil {
}
// Computes and returns the hash of the source file
static Future<Uint8List> getHash(File source) {
static Future<String> getHash(File source) {
return _computer.compute(
cryptoGenericHash,
param: {