use of org.thoughtcrime.securesms.crypto.MasterCipher in project Signal-Android by WhisperSystems.
the class ConversationActivity method saveDraft.
protected ListenableFuture<Long> saveDraft() {
final SettableFuture<Long> future = new SettableFuture<>();
if (this.recipients == null || this.recipients.isEmpty()) {
future.set(threadId);
return future;
}
final Drafts drafts = getDraftsForCurrentState();
final long thisThreadId = this.threadId;
final MasterSecret thisMasterSecret = this.masterSecret.parcelClone();
final int thisDistributionType = this.distributionType;
new AsyncTask<Long, Void, Long>() {
@Override
protected Long doInBackground(Long... params) {
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(ConversationActivity.this);
DraftDatabase draftDatabase = DatabaseFactory.getDraftDatabase(ConversationActivity.this);
long threadId = params[0];
if (drafts.size() > 0) {
if (threadId == -1)
threadId = threadDatabase.getThreadIdFor(getRecipients(), thisDistributionType);
draftDatabase.insertDrafts(new MasterCipher(thisMasterSecret), threadId, drafts);
threadDatabase.updateSnippet(threadId, drafts.getSnippet(ConversationActivity.this), drafts.getUriSnippet(ConversationActivity.this), System.currentTimeMillis(), Types.BASE_DRAFT_TYPE, true);
} else if (threadId > 0) {
threadDatabase.update(threadId, false);
}
return threadId;
}
@Override
protected void onPostExecute(Long result) {
future.set(result);
}
}.execute(thisThreadId);
return future;
}
use of org.thoughtcrime.securesms.crypto.MasterCipher in project Signal-Android by WhisperSystems.
the class EncryptingJobSerializer method serialize.
@Override
public String serialize(Job job) throws IOException {
String plaintext = delegate.serialize(job);
if (job.getEncryptionKeys() != null) {
MasterSecret masterSecret = ParcelUtil.deserialize(job.getEncryptionKeys().getEncoded(), MasterSecret.CREATOR);
MasterCipher masterCipher = new MasterCipher(masterSecret);
return masterCipher.encryptBody(plaintext);
} else {
return plaintext;
}
}
use of org.thoughtcrime.securesms.crypto.MasterCipher in project Signal-Android by WhisperSystems.
the class EncryptingJobSerializer method deserialize.
@Override
public Job deserialize(EncryptionKeys keys, boolean encrypted, String serialized) throws IOException {
try {
String plaintext;
if (encrypted) {
MasterSecret masterSecret = ParcelUtil.deserialize(keys.getEncoded(), MasterSecret.CREATOR);
MasterCipher masterCipher = new MasterCipher(masterSecret);
plaintext = masterCipher.decryptBody(serialized);
} else {
plaintext = serialized;
}
return delegate.deserialize(keys, encrypted, plaintext);
} catch (InvalidMessageException e) {
throw new IOException(e);
}
}
use of org.thoughtcrime.securesms.crypto.MasterCipher in project Signal-Android by WhisperSystems.
the class DirectShareService method onGetChooserTargets.
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
List<ChooserTarget> results = new LinkedList<>();
MasterSecret masterSecret = KeyCachingService.getMasterSecret(this);
if (masterSecret == null) {
return results;
}
ComponentName componentName = new ComponentName(this, ShareActivity.class);
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(this);
Cursor cursor = threadDatabase.getDirectShareList();
try {
ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor, new MasterCipher(masterSecret));
ThreadRecord record;
while ((record = reader.getNext()) != null && results.size() < 10) {
Recipients recipients = RecipientFactory.getRecipientsForIds(this, record.getRecipients().getIds(), false);
String name = recipients.toShortString();
Drawable drawable = recipients.getContactPhoto().asDrawable(this, recipients.getColor().toConversationColor(this));
Bitmap avatar = BitmapUtil.createFromDrawable(drawable, 500, 500);
Bundle bundle = new Bundle();
bundle.putLong(ShareActivity.EXTRA_THREAD_ID, record.getThreadId());
bundle.putLongArray(ShareActivity.EXTRA_RECIPIENT_IDS, recipients.getIds());
bundle.putInt(ShareActivity.EXTRA_DISTRIBUTION_TYPE, record.getDistributionType());
results.add(new ChooserTarget(name, Icon.createWithBitmap(avatar), 1.0f, componentName, bundle));
}
return results;
} finally {
if (cursor != null)
cursor.close();
}
}
Aggregations