Search in sources :

Example 1 with GroupsV2Operations

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");
            }
    }
}
Also used : GroupsV2Operations(org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations) GroupSecretParams(org.signal.zkgroup.groups.GroupSecretParams) SignalServiceMessageReceiver(org.whispersystems.signalservice.api.SignalServiceMessageReceiver) File(java.io.File) FileInputStream(java.io.FileInputStream) Nullable(androidx.annotation.Nullable)

Example 2 with GroupsV2Operations

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");
            }
    }
}
Also used : GroupsV2Operations(org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations) GroupSecretParams(org.signal.zkgroup.groups.GroupSecretParams) SignalServiceMessageReceiver(org.whispersystems.signalservice.api.SignalServiceMessageReceiver) File(java.io.File) FileInputStream(java.io.FileInputStream) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 GroupSecretParams (org.signal.zkgroup.groups.GroupSecretParams)2 SignalServiceMessageReceiver (org.whispersystems.signalservice.api.SignalServiceMessageReceiver)2 GroupsV2Operations (org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations)2