use of org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations in project Signal-Android by WhisperSystems.
the class AvatarGroupsV2DownloadJob method downloadGroupAvatarBytes.
@Nullable
public static byte[] downloadGroupAvatarBytes(@NonNull Context context, @NonNull GroupMasterKey groupMasterKey, @NonNull String cdnKey) throws IOException {
if (cdnKey.length() == 0) {
return null;
}
GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
File attachment = File.createTempFile("avatar", "gv2", context.getCacheDir());
attachment.deleteOnExit();
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
byte[] encryptedData;
try (FileInputStream inputStream = receiver.retrieveGroupsV2ProfileAvatar(cdnKey, attachment, AVATAR_DOWNLOAD_FAIL_SAFE_MAX_SIZE)) {
encryptedData = new byte[(int) attachment.length()];
StreamUtil.readFully(inputStream, encryptedData);
GroupsV2Operations operations = ApplicationDependencies.getGroupsV2Operations();
GroupsV2Operations.GroupOperations groupOperations = operations.forGroup(groupSecretParams);
return groupOperations.decryptAvatar(encryptedData);
} finally {
if (attachment.exists())
if (!attachment.delete()) {
Log.w(TAG, "Unable to delete temp avatar file");
}
}
}
use of org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations in project Signal-Android by signalapp.
the class AvatarGroupsV2DownloadJob method downloadGroupAvatarBytes.
@Nullable
public static byte[] downloadGroupAvatarBytes(@NonNull Context context, @NonNull GroupMasterKey groupMasterKey, @NonNull String cdnKey) throws IOException {
if (cdnKey.length() == 0) {
return null;
}
GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
File attachment = File.createTempFile("avatar", "gv2", context.getCacheDir());
attachment.deleteOnExit();
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
byte[] encryptedData;
try (FileInputStream inputStream = receiver.retrieveGroupsV2ProfileAvatar(cdnKey, attachment, AVATAR_DOWNLOAD_FAIL_SAFE_MAX_SIZE)) {
encryptedData = new byte[(int) attachment.length()];
StreamUtil.readFully(inputStream, encryptedData);
GroupsV2Operations operations = ApplicationDependencies.getGroupsV2Operations();
GroupsV2Operations.GroupOperations groupOperations = operations.forGroup(groupSecretParams);
return groupOperations.decryptAvatar(encryptedData);
} finally {
if (attachment.exists())
if (!attachment.delete()) {
Log.w(TAG, "Unable to delete temp avatar file");
}
}
}
Aggregations