本文整理汇总了Java中org.openintents.openpgp.util.OpenPgpApi类的典型用法代码示例。如果您正苦于以下问题:Java OpenPgpApi类的具体用法?Java OpenPgpApi怎么用?Java OpenPgpApi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OpenPgpApi类属于org.openintents.openpgp.util包,在下文中一共展示了OpenPgpApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mimeBuildSignedMessage
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
private void mimeBuildSignedMessage(@NonNull BodyPart signedBodyPart, Intent result) throws MessagingException {
if (!cryptoStatus.isSigningEnabled()) {
throw new IllegalStateException("call to mimeBuildSignedMessage while signing isn't enabled!");
}
byte[] signedData = result.getByteArrayExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE);
if (signedData == null) {
throw new MessagingException("didn't find expected RESULT_DETACHED_SIGNATURE in api call result");
}
MimeMultipart multipartSigned = createMimeMultipart();
multipartSigned.setSubType("signed");
multipartSigned.addBodyPart(signedBodyPart);
multipartSigned.addBodyPart(
new MimeBodyPart(new BinaryMemoryBody(signedData, MimeUtil.ENC_7BIT),
"application/pgp-signature; name=\"signature.asc\""));
MimeMessageHelper.setBody(currentProcessedMimeMessage, multipartSigned);
String contentType = String.format(
"multipart/signed; boundary=\"%s\";\r\n protocol=\"application/pgp-signature\"",
multipartSigned.getBoundary());
if (result.hasExtra(OpenPgpApi.RESULT_SIGNATURE_MICALG)) {
String micAlgParameter = result.getStringExtra(OpenPgpApi.RESULT_SIGNATURE_MICALG);
contentType += String.format("; micalg=\"%s\"", micAlgParameter);
} else {
Timber.e("missing micalg parameter for pgp multipart/signed!");
}
currentProcessedMimeMessage.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
}
示例2: getOpenPgpDecryptVerifyIntent
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
@NonNull
private Intent getOpenPgpDecryptVerifyIntent() {
Intent decryptIntent = new Intent(OpenPgpApi.ACTION_DECRYPT_VERIFY);
Address[] from = currentMessage.getFrom();
if (from.length > 0) {
decryptIntent.putExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS, from[0].getAddress());
// we add this here independently of the autocrypt peer update, to allow picking up signing keys as gossip
decryptIntent.putExtra(OpenPgpApi.EXTRA_AUTOCRYPT_PEER_ID, from[0].getAddress());
}
autocryptOperations.addAutocryptPeerUpdateToIntentIfPresent(currentMessage, decryptIntent);
decryptIntent.putExtra(OpenPgpApi.EXTRA_SUPPORT_OVERRIDE_CRYPTO_WARNING, true);
decryptIntent.putExtra(OpenPgpApi.EXTRA_DECRYPTION_RESULT, cachedOpenPgpDecryptionResult);
return decryptIntent;
}
示例3: processAutocryptHeaderForCurrentPart
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
private void processAutocryptHeaderForCurrentPart() {
Intent intent = new Intent(OpenPgpApi.ACTION_UPDATE_AUTOCRYPT_PEER);
boolean hasInlineKeyData = autocryptOperations.addAutocryptPeerUpdateToIntentIfPresent(
(Message) currentCryptoPart.part, intent);
if (hasInlineKeyData) {
Timber.d("Passing autocrypt data from plain mail to OpenPGP API");
// We don't care about the result here, so we just call this fire-and-forget wait to minimize delay
openPgpApi.executeApiAsync(intent, null, null, new IOpenPgpCallback() {
@Override
public void onReturn(Intent result) {
Timber.d("Autocrypt update OK!");
}
});
}
onCryptoFinished();
}
示例4: handleOpenPgpOperationResult
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
private void handleOpenPgpOperationResult(MimeBodyPart outputPart) {
int resultCode = currentCryptoResult.getIntExtra(OpenPgpApi.RESULT_CODE, INVALID_OPENPGP_RESULT_CODE);
Timber.d("OpenPGP API decryptVerify result code: %d", resultCode);
switch (resultCode) {
case INVALID_OPENPGP_RESULT_CODE: {
Timber.e("Internal error: no result code!");
break;
}
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: {
handleOpenPgpUserInteractionRequest();
break;
}
case OpenPgpApi.RESULT_CODE_ERROR: {
handleOpenPgpOperationError();
break;
}
case OpenPgpApi.RESULT_CODE_SUCCESS: {
handleOpenPgpOperationSuccess(outputPart);
break;
}
}
}
示例5: addAutocryptPeerUpdateToIntentIfPresent
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
public boolean addAutocryptPeerUpdateToIntentIfPresent(Message currentMessage, Intent intent) {
AutocryptHeader autocryptHeader = autocryptHeaderParser.getValidAutocryptHeader(currentMessage);
if (autocryptHeader == null) {
return false;
}
String messageFromAddress = currentMessage.getFrom()[0].getAddress();
if (!autocryptHeader.addr.equalsIgnoreCase(messageFromAddress)) {
return false;
}
Date messageDate = currentMessage.getSentDate();
Date internalDate = currentMessage.getInternalDate();
Date effectiveDate = messageDate.before(internalDate) ? messageDate : internalDate;
AutocryptPeerUpdate data = AutocryptPeerUpdate.create(
autocryptHeader.keyData, effectiveDate, autocryptHeader.isPreferEncryptMutual);
intent.putExtra(OpenPgpApi.EXTRA_AUTOCRYPT_PEER_ID, messageFromAddress);
intent.putExtra(OpenPgpApi.EXTRA_AUTOCRYPT_PEER_UPDATE, data);
return true;
}
示例6: buildSign__withNoDetachedSignatureInResult__shouldThrow
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
@Test
public void buildSign__withNoDetachedSignatureInResult__shouldThrow() throws MessagingException {
cryptoStatusBuilder.setCryptoMode(CryptoMode.SIGN_ONLY);
pgpMessageBuilder.setCryptoStatus(cryptoStatusBuilder.build());
Intent returnIntent = new Intent();
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class)))
.thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
verify(mockCallback).onMessageBuildException(any(MessagingException.class));
verifyNoMoreInteractions(mockCallback);
}
示例7: buildSign__withUserInteractionResult__shouldReturnUserInteraction
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
@Test
public void buildSign__withUserInteractionResult__shouldReturnUserInteraction() throws MessagingException {
cryptoStatusBuilder.setCryptoMode(CryptoMode.SIGN_ONLY);
pgpMessageBuilder.setCryptoStatus(cryptoStatusBuilder.build());
Intent returnIntent = mock(Intent.class);
when(returnIntent.getIntExtra(eq(OpenPgpApi.RESULT_CODE), anyInt()))
.thenReturn(OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
final PendingIntent mockPendingIntent = mock(PendingIntent.class);
when(returnIntent.getParcelableExtra(eq(OpenPgpApi.RESULT_INTENT)))
.thenReturn(mockPendingIntent);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class)))
.thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
ArgumentCaptor<PendingIntent> captor = ArgumentCaptor.forClass(PendingIntent.class);
verify(mockCallback).onMessageBuildReturnPendingIntent(captor.capture(), anyInt());
verifyNoMoreInteractions(mockCallback);
PendingIntent pendingIntent = captor.getValue();
Assert.assertSame(pendingIntent, mockPendingIntent);
}
示例8: buildEncrypt__withoutRecipients__shouldThrow
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
@Test
public void buildEncrypt__withoutRecipients__shouldThrow() throws MessagingException {
cryptoStatusBuilder
.setCryptoMode(CryptoMode.CHOICE_ENABLED)
.setRecipients(new ArrayList<Recipient>());
pgpMessageBuilder.setCryptoStatus(cryptoStatusBuilder.build());
Intent returnIntent = spy(new Intent());
returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class)))
.thenReturn(returnIntent);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
verify(mockCallback).onMessageBuildException(any(MessagingException.class));
verifyNoMoreInteractions(mockCallback);
}
示例9: buildSign__withNoDetachedSignatureExtra__shouldFail
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
@Test
public void buildSign__withNoDetachedSignatureExtra__shouldFail() throws MessagingException {
ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder
.setCryptoMode(CryptoMode.SIGN_ONLY)
.build();
pgpMessageBuilder.setCryptoStatus(cryptoStatus);
Intent returnIntentSigned = new Intent();
returnIntentSigned.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
// no OpenPgpApi.EXTRA_DETACHED_SIGNATURE!
when(openPgpApi.executeApi(any(Intent.class), any(OpenPgpDataSource.class), any(OutputStream.class)))
.thenReturn(returnIntentSigned);
Callback mockCallback = mock(Callback.class);
pgpMessageBuilder.buildAsync(mockCallback);
verify(mockCallback).onMessageBuildException(any(MessagingException.class));
verifyNoMoreInteractions(mockCallback);
}
示例10: multipartSignedOpenPgp_withOpenPgpApi__shouldCallOpenPgpApiAsync
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
@Test
public void multipartSignedOpenPgp_withOpenPgpApi__shouldCallOpenPgpApiAsync() throws Exception {
setUpWithOpenPgpApi();
BodyPart signedBodyPart = spy(bodypart("text/plain", "content"));
Message message = messageFromBody(
multipart("signed", "protocol=\"application/pgp-signature\"",
signedBodyPart,
bodypart("application/pgp-signature", "content")
)
);
message.setFrom(Address.parse("Test <[email protected]>")[0]);
OutputStream outputStream = mock(OutputStream.class);
processOpenPgpSignedMessageAndCaptureMocks(message, signedBodyPart, outputStream);
assertEquals(OpenPgpApi.ACTION_DECRYPT_VERIFY, capturedApiIntent.getAction());
assertEquals("[email protected]", capturedApiIntent.getStringExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS));
verify(autocryptOperations).addAutocryptPeerUpdateToIntentIfPresent(message, capturedApiIntent);
verifyNoMoreInteractions(autocryptOperations);
}
示例11: setupCryptoProvider
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
private void setupCryptoProvider(RecipientAutocryptStatus autocryptStatusResult) throws android.os.RemoteException {
Account account = mock(Account.class);
OpenPgpServiceConnection openPgpServiceConnection = mock(OpenPgpServiceConnection.class);
IOpenPgpService2 openPgpService2 = mock(IOpenPgpService2.class);
Intent permissionPingIntent = new Intent();
when(autocryptStatusInteractor.retrieveCryptoProviderRecipientStatus(
any(OpenPgpApi.class), any(String[].class))).thenReturn(autocryptStatusResult);
QMail.setOpenPgpProvider(CRYPTO_PROVIDER);
permissionPingIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
when(account.getCryptoKey()).thenReturn(CRYPTO_KEY_ID);
when(openPgpServiceConnection.isBound()).thenReturn(true);
when(openPgpServiceConnection.getService()).thenReturn(openPgpService2);
when(openPgpService2.execute(any(Intent.class), any(ParcelFileDescriptor.class), any(Integer.class)))
.thenReturn(permissionPingIntent);
recipientPresenter.setOpenPgpServiceConnection(openPgpServiceConnection, CRYPTO_PROVIDER);
recipientPresenter.onSwitchAccount(account);
// one for the permission ping, one for the async status update
runBackgroundTask();
runBackgroundTask();
}
示例12: chooseKey
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
public void chooseKey(final Account account, final UiCallback<Account> callback) {
Intent p = new Intent();
p.setAction(OpenPgpApi.ACTION_GET_SIGN_KEY_ID);
api.executeApiAsync(p, null, null, new IOpenPgpCallback() {
@Override
public void onReturn(Intent result) {
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, 0)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
callback.success(account);
return;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
callback.userInputRequried((PendingIntent) result
.getParcelableExtra(OpenPgpApi.RESULT_INTENT),
account);
return;
case OpenPgpApi.RESULT_CODE_ERROR:
logError(account, (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
callback.error(R.string.openpgp_error, account);
}
}
});
}
示例13: hasKey
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
public void hasKey(final Contact contact, final UiCallback<Contact> callback) {
Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_GET_KEY);
params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId());
api.executeApiAsync(params, null, null, new IOpenPgpCallback() {
@Override
public void onReturn(Intent result) {
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, 0)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
callback.success(contact);
return;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
callback.userInputRequried((PendingIntent) result
.getParcelableExtra(OpenPgpApi.RESULT_INTENT),
contact);
return;
case OpenPgpApi.RESULT_CODE_ERROR:
logError(contact.getAccount(), (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
callback.error(R.string.openpgp_error, contact);
}
}
});
}
示例14: onActivityResult
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (xmppConnectionServiceBound) {
if (requestCode == REQUEST_CHOOSE_PGP_ID) {
if (data.getExtras().containsKey(OpenPgpApi.EXTRA_SIGN_KEY_ID)) {
selectedAccount.setPgpSignId(data.getExtras().getLong(OpenPgpApi.EXTRA_SIGN_KEY_ID));
announcePgp(selectedAccount, null, onOpenPGPKeyPublished);
} else {
choosePgpSignId(selectedAccount);
}
} else if (requestCode == REQUEST_ANNOUNCE_PGP) {
announcePgp(selectedAccount, null, onOpenPGPKeyPublished);
}
this.mPostponedActivityResult = null;
} else {
this.mPostponedActivityResult = new Pair<>(requestCode, data);
}
}
}
示例15: init
import org.openintents.openpgp.util.OpenPgpApi; //导入依赖的package包/类
public static synchronized void init(final Context ctx) {
if (mCtx == null) {
mCtx = ctx.getApplicationContext();
mServiceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder service) {
Ln.w("OKCS: Service Connected!");
mService = IOpenPgpService2.Stub.asInterface(service);
mApi = new OpenPgpApi(mCtx, mService);
}
public void onServiceDisconnected(ComponentName name) {
Ln.w("OKCS: Service Disconnected!");
mService = null;
mApi = null;
}
};
}
bindToService(mCtx);
}