Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Fix inMemoryDecryption
Browse files Browse the repository at this point in the history
  • Loading branch information
Boehrsi committed Jun 2, 2020
1 parent 4b8b189 commit b3feaad
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@


import android.content.Context;
import android.util.Log;

import com.b44t.messenger.DcChat;
import com.b44t.messenger.DcContact;
Expand Down Expand Up @@ -123,7 +122,6 @@ public DeltaChatCorePlugin() {

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
Log.d("dboehrs" + this.hashCode(), "onAttachedToEngine:");
logEventAndDelegate(eventChannelHandler, INFO, TAG, "Attaching plugin via v2 embedding");
context = binding.getApplicationContext();
messenger = binding.getBinaryMessenger();
Expand All @@ -133,7 +131,6 @@ public void onAttachedToEngine(FlutterPluginBinding binding) {

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
Log.d("dboehrs" + this.hashCode(), "onDetachedFromEngine: ");
logEventAndDelegate(eventChannelHandler, INFO, TAG, "Detaching plugin via v2 embedding");
context = null;
messenger = null;
Expand Down Expand Up @@ -240,7 +237,6 @@ private void init(MethodCall methodCall, Result result) {

private void tearDown(Result result) {
logEventAndDelegate(eventChannelHandler, INFO, TAG, "Teardown started");
Log.d("dboehrs" + this.hashCode(), "tearDown: ");
nativeInteractionManager.tearDown();
nativeInteractionManager = null;
contextCallHandler = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

package com.openxchange.deltachatcore.handlers;

import android.util.Log;

import com.b44t.messenger.ChatIdWrapper;
import com.b44t.messenger.DcChat;
import com.b44t.messenger.DcChatlist;
Expand All @@ -54,6 +52,8 @@
import com.openxchange.deltachatcore.IdCache;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand Down Expand Up @@ -1203,7 +1203,6 @@ private void retrySendingPendingMessages(MethodChannel.Result result) {
}

private void decryptMessageInMemory(MethodCall methodCall, MethodChannel.Result result) {
Log.d("dboehrs", "decryptMessageInMemory: started");
if (!hasArgumentKeys(methodCall, ARGUMENT_CONTENT_TYPE, ARGUMENT_CONTENT, ARGUMENT_ADDRESS)) {
resultErrorArgumentMissing(result);
return;
Expand All @@ -1225,7 +1224,7 @@ private void decryptMessageInMemory(MethodCall methodCall, MethodChannel.Result
}
ChatIdWrapper chatIdWrapper = new ChatIdWrapper();
String plainText = dcContext.decryptMessageInMemory(contentType, content, senderAddress, chatIdWrapper);
Log.d("dboehrs", "decryptMessageInMemory: finished with" + chatIdWrapper.chatId);
result.success(plainText);
List<Object> data = Arrays.asList(chatIdWrapper.chatId, plainText);
result.success(data);
}
}
1 change: 1 addition & 0 deletions lib/delta_chat_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import 'package:logging/logging.dart';
export 'package:delta_chat_core/src/types/chat_summary.dart';
export 'package:delta_chat_core/src/types/event.dart';
export 'package:delta_chat_core/src/types/qrcode_result.dart';
export 'package:delta_chat_core/src/types/decrypted_chat_message.dart';

export 'src/base.dart';
export 'src/chat.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class Context {
return await core.invokeMethod(methodGetNextMedia, getNextMediaArguments(messageId, dir, messageTypeOne, messageTypeTwo, messageTypeThree));
}

Future<String> decryptInMemory(String contentType, String content, String senderAddress) async {
Future<List<dynamic>> decryptInMemory(String contentType, String content, String senderAddress) async {
return await core.invokeMethod(methodDecryptInMemory, getDecryptInMemoryArguments(contentType, content, senderAddress));
}

Expand Down
57 changes: 57 additions & 0 deletions lib/src/types/decrypted_chat_message.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* OPEN-XCHANGE legal information
*
* All intellectual property rights in the Software are protected by
* international copyright laws.
*
*
* In some countries OX, OX Open-Xchange and open xchange
* as well as the corresponding Logos OX Open-Xchange and OX are registered
* trademarks of the OX Software GmbH group of companies.
* The use of the Logos is not covered by the Mozilla Public License 2.0 (MPL 2.0).
* Instead, you are allowed to use these Logos according to the terms and
* conditions of the Creative Commons License, Version 2.5, Attribution,
* Non-commercial, ShareAlike, and the interpretation of the term
* Non-commercial applicable to the aforementioned license is published
* on the web site https://www.open-xchange.com/terms-and-conditions/.
*
* Please make sure that third-party modules and libraries are used
* according to their respective licenses.
*
* Any modifications to this package must retain all copyright notices
* of the original copyright holder(s) for the original code used.
*
* After any such modifications, the original and derivative code shall remain
* under the copyright of the copyright holder(s) and/or original author(s) as stated here:
* https://www.open-xchange.com/legal/. The contributing author shall be
* given Attribution for the derivative code and a license granting use.
*
* Copyright (C) 2016-2020 OX Software GmbH
* Mail: [email protected]
*
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Mozilla Public License 2.0
* for more details.
*/

const indexChatId = 0;
const indexContent = 1;

class DecryptedChatMessage {
int chatId;
String content;

DecryptedChatMessage.fromMethodChannel(List<dynamic> data) {
if (data is! List) {
throw ArgumentError("Given data is no List, can't create DecryptedPushMessage object");
}
chatId = data[indexChatId];
content = data[indexContent];
}
}

0 comments on commit b3feaad

Please sign in to comment.