@Test public void testExportUnencrypted() throws Exception { ContentResolver mockResolver = mock(ContentResolver.class); Uri fakeOutputUri = Uri.parse("content: ByteArrayOutputStream outStream1 = new ByteArrayOutputStream(); when(mockResolver.openOutputStream(fakeOutputUri)).thenReturn(outStream1); Application spyApplication = spy(RuntimeEnvironment.application); when(spyApplication.getContentResolver()).thenReturn(mockResolver); BackupOperation op = new BackupOperation(spyApplication, KeyWritableRepository.create(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = BackupKeyringParcel.create( new long[] { mStaticRing1.getMasterKeyId() }, false, false, true, fakeOutputUri); ExportResult result = op.execute(parcel, null); verify(mockResolver).openOutputStream(fakeOutputUri); assertTrue("export must succeed", result.success()); TestingUtils.assertArrayEqualsPrefix("exported data must start with ascii armor header", "-----BEGIN PGP PUBLIC KEY BLOCK-----\n".getBytes(), outStream1.toByteArray()); TestingUtils.assertArrayEqualsSuffix("exported data must end with ascii armor header", "-----END PGP PUBLIC KEY BLOCK-----\n".getBytes(), outStream1.toByteArray()); { IteratorWithIOThrow<UncachedKeyRing> unc = UncachedKeyRing.fromStream(new ByteArrayInputStream(outStream1.toByteArray())); assertTrue("export must have one key", unc.hasNext()); UncachedKeyRing ring = unc.next(); Assert.assertEquals("exported key has correct masterkeyid", mStaticRing1.getMasterKeyId(), ring.getMasterKeyId()); assertFalse("export must have exactly one key", unc.hasNext()); } }
@NonNull public ExportResult execute(@NonNull BackupKeyringParcel backupInput, @Nullable CryptoInputParcel cryptoInput) { return execute(backupInput, cryptoInput, null); }
BackupOperation extends BaseOperation<BackupKeyringParcel> { @NonNull public ExportResult execute(@NonNull BackupKeyringParcel backupInput, @Nullable CryptoInputParcel cryptoInput) { return execute(backupInput, cryptoInput, null); } }
BackupOperation extends BaseOperation<BackupKeyringParcel> { @NonNull public ExportResult execute(@NonNull BackupKeyringParcel backupInput, @Nullable CryptoInputParcel cryptoInput) { return execute(backupInput, cryptoInput, null); } BackupOperation(Context context, KeyRepository keyRepository, Progressable
            progressable);  BackupOperation(Context context, KeyRepository keyRepository,
                           Progressable progressable, AtomicBoolean cancelled); }
BackupOperation extends BaseOperation<BackupKeyringParcel> { @NonNull public ExportResult execute(@NonNull BackupKeyringParcel backupInput, @Nullable CryptoInputParcel cryptoInput) { return execute(backupInput, cryptoInput, null); } BackupOperation(Context context, KeyRepository keyRepository, Progressable
            progressable);  BackupOperation(Context context, KeyRepository keyRepository,
                           Progressable progressable, AtomicBoolean cancelled); @NonNull ExportResult execute(@NonNull BackupKeyringParcel backupInput, @Nullable CryptoInputParcel cryptoInput); @NonNull ExportResult execute(@NonNull BackupKeyringParcel backupInput, @Nullable CryptoInputParcel cryptoInput,
                                OutputStream outputStream); }
BackupOperation extends BaseOperation<BackupKeyringParcel> { @NonNull public ExportResult execute(@NonNull BackupKeyringParcel backupInput, @Nullable CryptoInputParcel cryptoInput) { return execute(backupInput, cryptoInput, null); } BackupOperation(Context context, KeyRepository keyRepository, Progressable
            progressable);  BackupOperation(Context context, KeyRepository keyRepository,
                           Progressable progressable, AtomicBoolean cancelled); @NonNull ExportResult execute(@NonNull BackupKeyringParcel backupInput, @Nullable CryptoInputParcel cryptoInput); @NonNull ExportResult execute(@NonNull BackupKeyringParcel backupInput, @Nullable CryptoInputParcel cryptoInput,
                                OutputStream outputStream);  }