mirror of https://github.com/NekoX-Dev/NekoX
23 changed files with 2171 additions and 59 deletions
@ -0,0 +1,75 @@ |
|||
package tw.nekomimi.nekogram.utils |
|||
|
|||
import org.openintents.openpgp.IOpenPgpService2 |
|||
import org.openintents.openpgp.util.OpenPgpApi |
|||
import org.openintents.openpgp.util.OpenPgpServiceConnection |
|||
import org.telegram.messenger.ApplicationLoader |
|||
import org.telegram.messenger.FileLog |
|||
import tw.nekomimi.nekogram.NekoConfig |
|||
|
|||
object PGPUtil { |
|||
|
|||
lateinit var serviceConnection: OpenPgpServiceConnection |
|||
lateinit var api: OpenPgpApi |
|||
|
|||
@JvmStatic |
|||
fun recreateConnection() { |
|||
|
|||
if (::serviceConnection.isInitialized) { |
|||
|
|||
runCatching { |
|||
|
|||
serviceConnection.unbindFromService() |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
serviceConnection = OpenPgpServiceConnection( |
|||
ApplicationLoader.applicationContext, |
|||
NekoConfig.openPGPApp |
|||
) |
|||
|
|||
|
|||
} |
|||
|
|||
@JvmStatic |
|||
fun post(runnable: Runnable) { |
|||
|
|||
if (!::serviceConnection.isInitialized) { |
|||
|
|||
recreateConnection() |
|||
|
|||
} |
|||
|
|||
if (!serviceConnection.isBound) { |
|||
|
|||
serviceConnection.bindToService(object : OpenPgpServiceConnection.OnBound { |
|||
|
|||
override fun onBound(service: IOpenPgpService2) { |
|||
|
|||
api = OpenPgpApi(ApplicationLoader.applicationContext, service) |
|||
|
|||
runnable.run() |
|||
|
|||
} |
|||
|
|||
override fun onError(e: Exception) { |
|||
|
|||
FileLog.e(e) |
|||
|
|||
AlertUtil.showToast(e) |
|||
|
|||
} |
|||
|
|||
}) |
|||
|
|||
} else { |
|||
|
|||
runnable.run() |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
#Android specific |
|||
bin |
|||
gen |
|||
obj |
|||
lint.xml |
|||
local.properties |
|||
release.properties |
|||
ant.properties |
|||
*.class |
|||
*.apk |
|||
|
|||
#Gradle |
|||
.gradle |
|||
build |
|||
gradle.properties |
|||
|
|||
#Maven |
|||
target |
|||
pom.xml.* |
|||
|
|||
#Eclipse |
|||
.project |
|||
.classpath |
|||
.settings |
|||
.metadata |
|||
|
|||
#IntelliJ IDEA |
|||
.idea |
|||
*.iml |
|||
|
|||
#Lint output |
|||
lint-report.html |
|||
lint-report_files/* |
@ -0,0 +1,16 @@ |
|||
apply plugin: 'com.android.library' |
|||
|
|||
android { |
|||
compileSdkVersion 28 |
|||
|
|||
defaultConfig { |
|||
versionCode 9 |
|||
versionName '13.0' // API-Version . minor |
|||
minSdkVersion 9 |
|||
targetSdkVersion 28 |
|||
} |
|||
|
|||
lintOptions { |
|||
abortOnError false |
|||
} |
|||
} |
@ -0,0 +1,7 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
|||
package="org.openintents.openpgp"> |
|||
|
|||
<application/> |
|||
|
|||
</manifest> |
@ -0,0 +1,27 @@ |
|||
/* |
|||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de> |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.openintents.openpgp; |
|||
|
|||
interface IOpenPgpService { |
|||
|
|||
/** |
|||
* do NOT use this, data returned from the service through "output" may be truncated |
|||
* @deprecated |
|||
*/ |
|||
Intent execute(in Intent data, in ParcelFileDescriptor input, in ParcelFileDescriptor output); |
|||
|
|||
} |
@ -0,0 +1,30 @@ |
|||
/* |
|||
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de> |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.openintents.openpgp; |
|||
|
|||
interface IOpenPgpService2 { |
|||
|
|||
/** |
|||
* see org.openintents.openpgp.util.OpenPgpApi for documentation |
|||
*/ |
|||
ParcelFileDescriptor createOutputPipe(in int pipeId); |
|||
|
|||
/** |
|||
* see org.openintents.openpgp.util.OpenPgpApi for documentation |
|||
*/ |
|||
Intent execute(in Intent data, in ParcelFileDescriptor input, int pipeId); |
|||
} |
@ -0,0 +1,131 @@ |
|||
/* |
|||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de> |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.openintents.openpgp; |
|||
|
|||
|
|||
import java.util.Date; |
|||
|
|||
import android.os.Parcel; |
|||
import android.os.Parcelable; |
|||
|
|||
|
|||
@SuppressWarnings("unused") |
|||
public class AutocryptPeerUpdate implements Parcelable { |
|||
/** |
|||
* Since there might be a case where new versions of the client using the library getting |
|||
* old versions of the protocol (and thus old versions of this class), we need a versioning |
|||
* system for the parcels sent between the clients and the providers. |
|||
*/ |
|||
private static final int PARCELABLE_VERSION = 1; |
|||
|
|||
|
|||
private final byte[] keyData; |
|||
private final Date effectiveDate; |
|||
private final PreferEncrypt preferEncrypt; |
|||
|
|||
|
|||
private AutocryptPeerUpdate(byte[] keyData, Date effectiveDate, PreferEncrypt preferEncrypt) { |
|||
this.keyData = keyData; |
|||
this.effectiveDate = effectiveDate; |
|||
this.preferEncrypt = preferEncrypt; |
|||
} |
|||
|
|||
private AutocryptPeerUpdate(Parcel source, int version) { |
|||
this.keyData = source.createByteArray(); |
|||
this.effectiveDate = source.readInt() != 0 ? new Date(source.readLong()) : null; |
|||
this.preferEncrypt = PreferEncrypt.values()[source.readInt()]; |
|||
} |
|||
|
|||
|
|||
public static AutocryptPeerUpdate createAutocryptPeerUpdate(byte[] keyData, Date timestamp) { |
|||
return new AutocryptPeerUpdate(keyData, timestamp, PreferEncrypt.NOPREFERENCE); |
|||
} |
|||
|
|||
public byte[] getKeyData() { |
|||
return keyData; |
|||
} |
|||
|
|||
public boolean hasKeyData() { |
|||
return keyData != null; |
|||
} |
|||
|
|||
public Date getEffectiveDate() { |
|||
return effectiveDate; |
|||
} |
|||
|
|||
public PreferEncrypt getPreferEncrypt() { |
|||
return preferEncrypt; |
|||
} |
|||
|
|||
|
|||
public int describeContents() { |
|||
return 0; |
|||
} |
|||
|
|||
public void writeToParcel(Parcel dest, int flags) { |
|||
/* |
|||
NOTE: When adding fields in the process of updating this API, make sure to bump |
|||
{@link #PARCELABLE_VERSION}. |
|||
*/ |
|||
dest.writeInt(PARCELABLE_VERSION); |
|||
// Inject a placeholder that will store the parcel size from this point on
|
|||
// (not including the size itself).
|
|||
int sizePosition = dest.dataPosition(); |
|||
dest.writeInt(0); |
|||
int startPosition = dest.dataPosition(); |
|||
|
|||
// version 1
|
|||
dest.writeByteArray(keyData); |
|||
if (effectiveDate != null) { |
|||
dest.writeInt(1); |
|||
dest.writeLong(effectiveDate.getTime()); |
|||
} else { |
|||
dest.writeInt(0); |
|||
} |
|||
|
|||
dest.writeInt(preferEncrypt.ordinal()); |
|||
|
|||
// Go back and write the size
|
|||
int parcelableSize = dest.dataPosition() - startPosition; |
|||
dest.setDataPosition(sizePosition); |
|||
dest.writeInt(parcelableSize); |
|||
dest.setDataPosition(startPosition + parcelableSize); |
|||
} |
|||
|
|||
public static final Creator<AutocryptPeerUpdate> CREATOR = new Creator<AutocryptPeerUpdate>() { |
|||
public AutocryptPeerUpdate createFromParcel(final Parcel source) { |
|||
int version = source.readInt(); // parcelableVersion
|
|||
int parcelableSize = source.readInt(); |
|||
int startPosition = source.dataPosition(); |
|||
|
|||
AutocryptPeerUpdate vr = new AutocryptPeerUpdate(source, version); |
|||
|
|||
// skip over all fields added in future versions of this parcel
|
|||
source.setDataPosition(startPosition + parcelableSize); |
|||
|
|||
return vr; |
|||
} |
|||
|
|||
public AutocryptPeerUpdate[] newArray(final int size) { |
|||
return new AutocryptPeerUpdate[size]; |
|||
} |
|||
}; |
|||
|
|||
public enum PreferEncrypt { |
|||
NOPREFERENCE, MUTUAL |
|||
} |
|||
} |
@ -0,0 +1,135 @@ |
|||
/* |
|||
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de> |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.openintents.openpgp; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
import android.os.Parcel; |
|||
import android.os.Parcelable; |
|||
|
|||
public class OpenPgpDecryptionResult implements Parcelable { |
|||
/** |
|||
* Since there might be a case where new versions of the client using the library getting |
|||
* old versions of the protocol (and thus old versions of this class), we need a versioning |
|||
* system for the parcels sent between the clients and the providers. |
|||
*/ |
|||
public static final int PARCELABLE_VERSION = 2; |
|||
|
|||
// content not encrypted
|
|||
public static final int RESULT_NOT_ENCRYPTED = -1; |
|||
// insecure!
|
|||
public static final int RESULT_INSECURE = 0; |
|||
// encrypted
|
|||
public static final int RESULT_ENCRYPTED = 1; |
|||
|
|||
private final int result; |
|||
private final byte[] sessionKey; |
|||
private final byte[] decryptedSessionKey; |
|||
|
|||
public OpenPgpDecryptionResult(int result) { |
|||
this.result = result; |
|||
this.sessionKey = null; |
|||
this.decryptedSessionKey = null; |
|||
} |
|||
|
|||
public OpenPgpDecryptionResult(int result, byte[] sessionKey, byte[] decryptedSessionKey) { |
|||
this.result = result; |
|||
if ((sessionKey == null) != (decryptedSessionKey == null)) { |
|||
throw new AssertionError("sessionkey must be null iff decryptedSessionKey is null"); |
|||
} |
|||
this.sessionKey = sessionKey; |
|||
this.decryptedSessionKey = decryptedSessionKey; |
|||
} |
|||
|
|||
public int getResult() { |
|||
return result; |
|||
} |
|||
|
|||
public boolean hasDecryptedSessionKey() { |
|||
return sessionKey != null; |
|||
} |
|||
|
|||
public byte[] getSessionKey() { |
|||
if (sessionKey == null) { |
|||
return null; |
|||
} |
|||
return Arrays.copyOf(sessionKey, sessionKey.length); |
|||
} |
|||
|
|||
public byte[] getDecryptedSessionKey() { |
|||
if (sessionKey == null || decryptedSessionKey == null) { |
|||
return null; |
|||
} |
|||
return Arrays.copyOf(decryptedSessionKey, decryptedSessionKey.length); |
|||
} |
|||
|
|||
public int describeContents() { |
|||
return 0; |
|||
} |
|||
|
|||
public void writeToParcel(Parcel dest, int flags) { |
|||
/* |
|||
NOTE: When adding fields in the process of updating this API, make sure to bump |
|||
{@link #PARCELABLE_VERSION}. |
|||
*/ |
|||
dest.writeInt(PARCELABLE_VERSION); |
|||
// Inject a placeholder that will store the parcel size from this point on
|
|||
// (not including the size itself).
|
|||
int sizePosition = dest.dataPosition(); |
|||
dest.writeInt(0); |
|||
int startPosition = dest.dataPosition(); |
|||
// version 1
|
|||
dest.writeInt(result); |
|||
// version 2
|
|||
dest.writeByteArray(sessionKey); |
|||
dest.writeByteArray(decryptedSessionKey); |
|||
// Go back and write the size
|
|||
int parcelableSize = dest.dataPosition() - startPosition; |
|||
dest.setDataPosition(sizePosition); |
|||
dest.writeInt(parcelableSize); |
|||
dest.setDataPosition(startPosition + parcelableSize); |
|||
} |
|||
|
|||
public static final Creator<OpenPgpDecryptionResult> CREATOR = new Creator<OpenPgpDecryptionResult>() { |
|||
public OpenPgpDecryptionResult createFromParcel(final Parcel source) { |
|||
int version = source.readInt(); // parcelableVersion
|
|||
int parcelableSize = source.readInt(); |
|||
int startPosition = source.dataPosition(); |
|||
|
|||
int result = source.readInt(); |
|||
byte[] sessionKey = version > 1 ? source.createByteArray() : null; |
|||
byte[] decryptedSessionKey = version > 1 ? source.createByteArray() : null; |
|||
|
|||
OpenPgpDecryptionResult vr = new OpenPgpDecryptionResult(result, sessionKey, decryptedSessionKey); |
|||
|
|||
// skip over all fields added in future versions of this parcel
|
|||
source.setDataPosition(startPosition + parcelableSize); |
|||
|
|||
return vr; |
|||
} |
|||
|
|||
public OpenPgpDecryptionResult[] newArray(final int size) { |
|||
return new OpenPgpDecryptionResult[size]; |
|||
} |
|||
}; |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "\nresult: " + result; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,116 @@ |
|||
/* |
|||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de> |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.openintents.openpgp; |
|||
|
|||
import android.os.Parcel; |
|||
import android.os.Parcelable; |
|||
|
|||
public class OpenPgpError implements Parcelable { |
|||
/** |
|||
* Since there might be a case where new versions of the client using the library getting |
|||
* old versions of the protocol (and thus old versions of this class), we need a versioning |
|||
* system for the parcels sent between the clients and the providers. |
|||
*/ |
|||
public static final int PARCELABLE_VERSION = 1; |
|||
|
|||
// possible values for errorId
|
|||
public static final int CLIENT_SIDE_ERROR = -1; |
|||
public static final int GENERIC_ERROR = 0; |
|||
public static final int INCOMPATIBLE_API_VERSIONS = 1; |
|||
public static final int NO_OR_WRONG_PASSPHRASE = 2; |
|||
public static final int NO_USER_IDS = 3; |
|||
public static final int OPPORTUNISTIC_MISSING_KEYS = 4; |
|||
|
|||
|
|||
int errorId; |
|||
String message; |
|||
|
|||
public OpenPgpError() { |
|||
} |
|||
|
|||
public OpenPgpError(int errorId, String message) { |
|||
this.errorId = errorId; |
|||
this.message = message; |
|||
} |
|||
|
|||
public OpenPgpError(OpenPgpError b) { |
|||
this.errorId = b.errorId; |
|||
this.message = b.message; |
|||
} |
|||
|
|||
public int getErrorId() { |
|||
return errorId; |
|||
} |
|||
|
|||
public void setErrorId(int errorId) { |
|||
this.errorId = errorId; |
|||
} |
|||
|
|||
public String getMessage() { |
|||
return message; |
|||
} |
|||
|
|||
public void setMessage(String message) { |
|||
this.message = message; |
|||
} |
|||
|
|||
public int describeContents() { |
|||
return 0; |
|||
} |
|||
|
|||
public void writeToParcel(Parcel dest, int flags) { |
|||
/* |
|||
NOTE: When adding fields in the process of updating this API, make sure to bump |
|||
{@link #PARCELABLE_VERSION}. |
|||
*/ |
|||
dest.writeInt(PARCELABLE_VERSION); |
|||
// Inject a placeholder that will store the parcel size from this point on
|
|||
// (not including the size itself).
|
|||
int sizePosition = dest.dataPosition(); |
|||
dest.writeInt(0); |
|||
int startPosition = dest.dataPosition(); |
|||
// version 1
|
|||
dest.writeInt(errorId); |
|||
dest.writeString(message); |
|||
// Go back and write the size
|
|||
int parcelableSize = dest.dataPosition() - startPosition; |
|||
dest.setDataPosition(sizePosition); |
|||
dest.writeInt(parcelableSize); |
|||
dest.setDataPosition(startPosition + parcelableSize); |
|||
} |
|||
|
|||
public static final Creator<OpenPgpError> CREATOR = new Creator<OpenPgpError>() { |
|||
public OpenPgpError createFromParcel(final Parcel source) { |
|||
source.readInt(); // parcelableVersion
|
|||
int parcelableSize = source.readInt(); |
|||
int startPosition = source.dataPosition(); |
|||
|
|||
OpenPgpError error = new OpenPgpError(); |
|||
error.errorId = source.readInt(); |
|||
error.message = source.readString(); |
|||
|
|||
// skip over all fields added in future versions of this parcel
|
|||
source.setDataPosition(startPosition + parcelableSize); |
|||
|
|||
return error; |
|||
} |
|||
|
|||
public OpenPgpError[] newArray(final int size) { |
|||
return new OpenPgpError[size]; |
|||
} |
|||
}; |
|||
} |
@ -0,0 +1,148 @@ |
|||
/* |
|||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de> |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.openintents.openpgp; |
|||
|
|||
import android.os.Parcel; |
|||
import android.os.Parcelable; |
|||
|
|||
public class OpenPgpMetadata implements Parcelable { |
|||
/** |
|||
* Since there might be a case where new versions of the client using the library getting |
|||
* old versions of the protocol (and thus old versions of this class), we need a versioning |
|||
* system for the parcels sent between the clients and the providers. |
|||
*/ |
|||
public static final int PARCELABLE_VERSION = 2; |
|||
|
|||
String filename; |
|||
String mimeType; |
|||
String charset; |
|||
long modificationTime; |
|||
long originalSize; |
|||
|
|||
public String getFilename() { |
|||
return filename; |
|||
} |
|||
|
|||
public String getMimeType() { |
|||
return mimeType; |
|||
} |
|||
|
|||
public long getModificationTime() { |
|||
return modificationTime; |
|||
} |
|||
|
|||
public long getOriginalSize() { |
|||
return originalSize; |
|||
} |
|||
|
|||
public String getCharset() { |
|||
return charset; |
|||
} |
|||
|
|||
public OpenPgpMetadata() { |
|||
} |
|||
|
|||
public OpenPgpMetadata(String filename, String mimeType, long modificationTime, |
|||
long originalSize, String charset) { |
|||
this.filename = filename; |
|||
this.mimeType = mimeType; |
|||
this.modificationTime = modificationTime; |
|||
this.originalSize = originalSize; |
|||
this.charset = charset; |
|||
} |
|||
|
|||
public OpenPgpMetadata(String filename, String mimeType, long modificationTime, |
|||
long originalSize) { |
|||
this.filename = filename; |
|||
this.mimeType = mimeType; |
|||
this.modificationTime = modificationTime; |
|||
this.originalSize = originalSize; |
|||
} |
|||
|
|||
public OpenPgpMetadata(OpenPgpMetadata b) { |
|||
this.filename = b.filename; |
|||
this.mimeType = b.mimeType; |
|||
this.modificationTime = b.modificationTime; |
|||
this.originalSize = b.originalSize; |
|||
} |
|||
|
|||
public int describeContents() { |
|||
return 0; |
|||
} |
|||
|
|||
public void writeToParcel(Parcel dest, int flags) { |
|||
/* |
|||
* NOTE: When adding fields in the process of updating this API, make sure to bump |
|||
* {@link #PARCELABLE_VERSION}. |
|||
*/ |
|||
dest.writeInt(PARCELABLE_VERSION); |
|||
// Inject a placeholder that will store the parcel size from this point on
|
|||
// (not including the size itself).
|
|||
int sizePosition = dest.dataPosition(); |
|||
dest.writeInt(0); |
|||
int startPosition = dest.dataPosition(); |
|||
// version 1
|
|||
dest.writeString(filename); |
|||
dest.writeString(mimeType); |
|||
dest.writeLong(modificationTime); |
|||
dest.writeLong(originalSize); |
|||
// version 2
|
|||
dest.writeString(charset); |
|||
// Go back and write the size
|
|||
int parcelableSize = dest.dataPosition() - startPosition; |
|||
dest.setDataPosition(sizePosition); |
|||
dest.writeInt(parcelableSize); |
|||
dest.setDataPosition(startPosition + parcelableSize); |
|||
} |
|||
|
|||
public static final Creator<OpenPgpMetadata> CREATOR = new Creator<OpenPgpMetadata>() { |
|||
public OpenPgpMetadata createFromParcel(final Parcel source) { |
|||
int version = source.readInt(); // parcelableVersion
|
|||
int parcelableSize = source.readInt(); |
|||
int startPosition = source.dataPosition(); |
|||
|
|||
OpenPgpMetadata vr = new OpenPgpMetadata(); |
|||
vr.filename = source.readString(); |
|||
vr.mimeType = source.readString(); |
|||
vr.modificationTime = source.readLong(); |
|||
vr.originalSize = source.readLong(); |
|||
if (version >= 2) { |
|||
vr.charset = source.readString(); |
|||
} |
|||
|
|||
// skip over all fields added in future versions of this parcel
|
|||
source.setDataPosition(startPosition + parcelableSize); |
|||
|
|||
return vr; |
|||
} |
|||
|
|||
public OpenPgpMetadata[] newArray(final int size) { |
|||
return new OpenPgpMetadata[size]; |
|||
} |
|||
}; |
|||
|
|||
@Override |
|||
public String toString() { |
|||
String out = "\nfilename: " + filename; |
|||
out += "\nmimeType: " + mimeType; |
|||
out += "\nmodificationTime: " + modificationTime; |
|||
out += "\noriginalSize: " + originalSize; |
|||
out += "\ncharset: " + charset; |
|||
return out; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,275 @@ |
|||
/* |
|||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de> |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.openintents.openpgp; |
|||
|
|||
|
|||
import java.util.Collections; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
import android.os.Parcel; |
|||
import android.os.Parcelable; |
|||
|
|||
import org.openintents.openpgp.util.OpenPgpUtils; |
|||
|
|||
@SuppressWarnings("unused") |
|||
public class OpenPgpSignatureResult implements Parcelable { |
|||
/** |
|||
* Since there might be a case where new versions of the client using the library getting |
|||
* old versions of the protocol (and thus old versions of this class), we need a versioning |
|||
* system for the parcels sent between the clients and the providers. |
|||
*/ |
|||
private static final int PARCELABLE_VERSION = 5; |
|||
|
|||
// content not signed
|
|||
public static final int RESULT_NO_SIGNATURE = -1; |
|||
// invalid signature!
|
|||
public static final int RESULT_INVALID_SIGNATURE = 0; |
|||
// successfully verified signature, with confirmed key
|
|||
public static final int RESULT_VALID_KEY_CONFIRMED = 1; |
|||