本文整理汇总了Java中org.kontalk.crypto.Coder类的典型用法代码示例。如果您正苦于以下问题:Java Coder类的具体用法?Java Coder怎么用?Java Coder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Coder类属于org.kontalk.crypto包,在下文中一共展示了Coder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LegacyAbstractMessage
import org.kontalk.crypto.Coder; //导入依赖的package包/类
public LegacyAbstractMessage(Context context, String id, long timestamp, String sender, boolean encrypted) {
this.mContext = context;
this.id = id;
this.sender = sender;
this.recipients = new ArrayList<String>();
// will be updated if necessary
this.timestamp = System.currentTimeMillis();
this.serverTimestamp = timestamp;
if (encrypted) {
this.encrypted = encrypted;
// only basic encryption for now
this.security = Coder.SECURITY_BASIC;
}
}
示例2: startDownload
import org.kontalk.crypto.Coder; //导入依赖的package包/类
private void startDownload(CompositeMessage msg) {
AttachmentComponent attachment = msg
.getComponent(AttachmentComponent.class);
if (attachment != null && attachment.getFetchUrl() != null) {
DownloadService.start(getContext(), msg.getDatabaseId(),
msg.getSender(), attachment.getMime(), msg.getTimestamp(),
attachment.getSecurityFlags() != Coder.SECURITY_CLEARTEXT,
attachment.getFetchUrl());
}
else {
// corrupted message :(
Toast.makeText(getActivity(), R.string.err_attachment_corrupted,
Toast.LENGTH_LONG).show();
}
}
示例3: createGroup
import org.kontalk.crypto.Coder; //导入依赖的package包/类
public static Uri createGroup(Context context, long threadId,
String groupJid, String[] members, String msgId, boolean encrypted) {
ContentValues values = new ContentValues();
values.put(MyMessages.Messages.THREAD_ID, threadId);
values.put(MyMessages.Messages.MESSAGE_ID, msgId);
values.put(MyMessages.Messages.PEER, groupJid);
values.put(MyMessages.Messages.BODY_MIME, GroupCommandComponent.MIME_TYPE);
values.put(MyMessages.Messages.BODY_CONTENT, GroupCommandComponent.getCreateBodyContent(members).getBytes());
values.put(MyMessages.Messages.BODY_LENGTH, 0);
values.put(MyMessages.Messages.UNREAD, false);
values.put(MyMessages.Messages.DIRECTION, MyMessages.Messages.DIRECTION_OUT);
values.put(MyMessages.Messages.TIMESTAMP, System.currentTimeMillis());
values.put(MyMessages.Messages.STATUS, MyMessages.Messages.STATUS_SENDING);
// of course outgoing messages are not encrypted in database
values.put(MyMessages.Messages.ENCRYPTED, false);
values.put(MyMessages.Messages.SECURITY_FLAGS, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT);
return context.getContentResolver().insert(MyMessages.Messages.CONTENT_URI, values);
}
示例4: addGroupMembers
import org.kontalk.crypto.Coder; //导入依赖的package包/类
public static Uri addGroupMembers(Context context, long threadId, String groupJid, String[] members, String msgId, boolean encrypted) {
ContentValues values = new ContentValues();
values.put(MyMessages.Messages.THREAD_ID, threadId);
values.put(MyMessages.Messages.MESSAGE_ID, msgId);
values.put(MyMessages.Messages.PEER, groupJid);
values.put(MyMessages.Messages.BODY_MIME, GroupCommandComponent.MIME_TYPE);
values.put(MyMessages.Messages.BODY_CONTENT, GroupCommandComponent.getAddMembersBodyContent(members).getBytes());
values.put(MyMessages.Messages.BODY_LENGTH, 0);
values.put(MyMessages.Messages.UNREAD, false);
values.put(MyMessages.Messages.DIRECTION, MyMessages.Messages.DIRECTION_OUT);
values.put(MyMessages.Messages.TIMESTAMP, System.currentTimeMillis());
values.put(MyMessages.Messages.STATUS, MyMessages.Messages.STATUS_SENDING);
// of course outgoing messages are not encrypted in database
values.put(MyMessages.Messages.ENCRYPTED, false);
values.put(MyMessages.Messages.SECURITY_FLAGS, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT);
return context.getContentResolver().insert(MyMessages.Messages.CONTENT_URI, values);
}
示例5: removeGroupMembers
import org.kontalk.crypto.Coder; //导入依赖的package包/类
public static Uri removeGroupMembers(Context context, long threadId, String groupJid, String[] members, String msgId, boolean encrypted) {
ContentValues values = new ContentValues();
values.put(MyMessages.Messages.THREAD_ID, threadId);
values.put(MyMessages.Messages.MESSAGE_ID, msgId);
values.put(MyMessages.Messages.PEER, groupJid);
values.put(MyMessages.Messages.BODY_MIME, GroupCommandComponent.MIME_TYPE);
values.put(MyMessages.Messages.BODY_CONTENT, GroupCommandComponent.getRemoveMembersBodyContent(members).getBytes());
values.put(MyMessages.Messages.BODY_LENGTH, 0);
values.put(MyMessages.Messages.UNREAD, false);
values.put(MyMessages.Messages.DIRECTION, MyMessages.Messages.DIRECTION_OUT);
values.put(MyMessages.Messages.TIMESTAMP, System.currentTimeMillis());
values.put(MyMessages.Messages.STATUS, MyMessages.Messages.STATUS_SENDING);
// of course outgoing messages are not encrypted in database
values.put(MyMessages.Messages.ENCRYPTED, false);
values.put(MyMessages.Messages.SECURITY_FLAGS, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT);
return context.getContentResolver().insert(MyMessages.Messages.CONTENT_URI, values);
}
示例6: setGroupSubject
import org.kontalk.crypto.Coder; //导入依赖的package包/类
public static Uri setGroupSubject(Context context, long threadId, String groupJid, String subject, String msgId, boolean encrypted, boolean fakeSend) {
ContentValues values = new ContentValues();
values.put(MyMessages.Messages.THREAD_ID, threadId);
values.put(MyMessages.Messages.MESSAGE_ID, msgId);
values.put(MyMessages.Messages.PEER, groupJid);
values.put(MyMessages.Messages.BODY_MIME, GroupCommandComponent.MIME_TYPE);
values.put(MyMessages.Messages.BODY_CONTENT, GroupCommandComponent.getSetSubjectCommandBodyContent(subject).getBytes());
values.put(MyMessages.Messages.BODY_LENGTH, 0);
values.put(MyMessages.Messages.UNREAD, false);
values.put(MyMessages.Messages.DIRECTION, MyMessages.Messages.DIRECTION_OUT);
values.put(MyMessages.Messages.TIMESTAMP, System.currentTimeMillis());
values.put(MyMessages.Messages.STATUS, fakeSend ? MyMessages.Messages.STATUS_SENT : MyMessages.Messages.STATUS_SENDING);
// of course outgoing messages are not encrypted in database
values.put(MyMessages.Messages.ENCRYPTED, false);
values.put(MyMessages.Messages.SECURITY_FLAGS, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT);
return context.getContentResolver().insert(MyMessages.Messages.CONTENT_URI, values);
}
示例7: leaveGroup
import org.kontalk.crypto.Coder; //导入依赖的package包/类
public static Uri leaveGroup(Context context, long threadId, String groupJid, String msgId, boolean encrypted, boolean fakeSend) {
ContentValues values = new ContentValues();
values.put(MyMessages.Messages.THREAD_ID, threadId);
values.put(MyMessages.Messages.MESSAGE_ID, msgId);
values.put(MyMessages.Messages.PEER, groupJid);
values.put(MyMessages.Messages.BODY_MIME, GroupCommandComponent.MIME_TYPE);
values.put(MyMessages.Messages.BODY_CONTENT, GroupCommandComponent.getLeaveCommandBodyContent().getBytes());
values.put(MyMessages.Messages.BODY_LENGTH, 0);
values.put(MyMessages.Messages.UNREAD, false);
values.put(MyMessages.Messages.DIRECTION, MyMessages.Messages.DIRECTION_OUT);
values.put(MyMessages.Messages.TIMESTAMP, System.currentTimeMillis());
values.put(MyMessages.Messages.STATUS, fakeSend ? MyMessages.Messages.STATUS_SENT : MyMessages.Messages.STATUS_SENDING);
// of course outgoing messages are not encrypted in database
values.put(MyMessages.Messages.ENCRYPTED, false);
values.put(MyMessages.Messages.SECURITY_FLAGS, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT);
return context.getContentResolver().insert(MyMessages.Messages.CONTENT_URI, values);
}
示例8: newOutgoingMessage
import org.kontalk.crypto.Coder; //导入依赖的package包/类
/** Inserts a new outgoing text message. */
public static Uri newOutgoingMessage(Context context, String msgId, String userId,
String text, boolean encrypted, long inReplyTo) {
byte[] bytes = text.getBytes();
ContentValues values = new ContentValues(11);
// must supply a message ID...
values.put(Messages.MESSAGE_ID, msgId);
values.put(Messages.PEER, userId);
values.put(Messages.BODY_MIME, TextComponent.MIME_TYPE);
values.put(Messages.BODY_CONTENT, bytes);
values.put(Messages.BODY_LENGTH, bytes.length);
values.put(Messages.UNREAD, false);
values.put(Messages.DIRECTION, Messages.DIRECTION_OUT);
values.put(Messages.TIMESTAMP, System.currentTimeMillis());
values.put(Messages.STATUS, Messages.STATUS_SENDING);
// of course outgoing messages are not encrypted in database
values.put(Messages.ENCRYPTED, false);
values.put(Threads.ENCRYPTION, encrypted);
values.put(Messages.SECURITY_FLAGS, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT);
if (inReplyTo > 0)
values.put(Messages.IN_REPLY_TO, inReplyTo);
return context.getContentResolver().insert(
Messages.CONTENT_URI, values);
}
示例9: getEncryptCoder
import org.kontalk.crypto.Coder; //导入依赖的package包/类
/** Returns a {@link Coder} instance for encrypting data. */
public static Coder getEncryptCoder(Context context, EndpointServer server, PersonalKey key, String[] recipients) {
// get recipients public keys from users database
PGPPublicKey keys[] = new PGPPublicKey[recipients.length];
for (int i = 0; i < recipients.length; i++) {
String rcpt = StringUtils.parseName(recipients[i]);
PGPPublicKeyRing ring = getPublicKey(context, rcpt);
if (ring == null)
throw new IllegalArgumentException("public key not found for user " + rcpt);
keys[i] = PGP.getEncryptionKey(ring);
if (keys[i] == null)
throw new IllegalArgumentException("public key not found for user " + rcpt);
}
return new PGPCoder(server, key, keys);
}
示例10: decrypt
import org.kontalk.crypto.Coder; //导入依赖的package包/类
@Override
public void decrypt(Coder coder) throws GeneralSecurityException {
/*
if (isEncrypted()) {
// FIXME ehm :)
StringBuilder clearText = new StringBuilder();
coder.decryptText(content, true, clearText, null, null);
content = clearText.toString().getBytes();
length = content.length;
encrypted = false;
}
*/
}
示例11: checkDriftedDelay
import org.kontalk.crypto.Coder; //导入依赖的package包/类
private static boolean checkDriftedDelay(Message m, Date expected) {
Date stamp = XMPPUtils.getStanzaDelay(m);
if (stamp != null) {
long time = stamp.getTime();
long now = expected.getTime();
long diff = Math.abs(now - time);
return (diff < Coder.TIMEDIFF_THRESHOLD);
}
// no timestamp found
return true;
}
示例12: setSecurityFlags
import org.kontalk.crypto.Coder; //导入依赖的package包/类
@Override
public void setSecurityFlags(int securityFlags) {
if (Coder.isError(securityFlags)) {
mWarningIcon.setImageResource(R.drawable.ic_msg_security);
mWarningIcon.setVisibility(View.VISIBLE);
}
else {
mWarningIcon.setImageResource(R.drawable.ic_msg_warning);
mWarningIcon.setVisibility((securityFlags != Coder.SECURITY_CLEARTEXT) ?
View.GONE : View.VISIBLE);
}
}
示例13: getEncryptCoder
import org.kontalk.crypto.Coder; //导入依赖的package包/类
/** Returns a {@link Coder} instance for encrypting data. */
public static Coder getEncryptCoder(Context context, EndpointServer server, PersonalKey key, String[] recipients) {
// get recipients public keys from users database
PGPPublicKeyRing keys[] = new PGPPublicKeyRing[recipients.length];
for (int i = 0; i < recipients.length; i++) {
PGPPublicKeyRing ring = getPublicKey(context, recipients[i], MyUsers.Keys.TRUST_IGNORED);
if (ring == null)
throw new IllegalArgumentException("public key not found for user " + recipients[i]);
keys[i] = ring;
}
return new PGPCoder(server, key, keys);
}
示例14: retryMessage
import org.kontalk.crypto.Coder; //导入依赖的package包/类
/** Marks the given message as SENDING, regardless of its current status. */
public static int retryMessage(Context context, Uri uri, boolean encrypted) {
ContentValues values = new ContentValues(2);
values.put(Messages.STATUS, Messages.STATUS_SENDING);
values.put(Messages.SECURITY_FLAGS, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT);
return context.getContentResolver().update(uri, values, null, null);
}
示例15: retryAllMessages
import org.kontalk.crypto.Coder; //导入依赖的package包/类
/** Marks all pending messages as SENDING. */
public static int retryAllMessages(Context context) {
boolean encrypted = Preferences.getEncryptionEnabled(context);
ContentValues values = new ContentValues(2);
values.put(Messages.STATUS, Messages.STATUS_SENDING);
values.put(Messages.SECURITY_FLAGS, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT);
return context.getContentResolver().update(Messages.CONTENT_URI, values,
Messages.STATUS + "=" + Messages.STATUS_PENDING,
null);
}