aboutsummaryrefslogtreecommitdiffstats
path: root/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/AutocryptPeerUpdate.kt
diff options
context:
space:
mode:
Diffstat (limited to 'openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/AutocryptPeerUpdate.kt')
-rw-r--r--openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/AutocryptPeerUpdate.kt174
1 files changed, 84 insertions, 90 deletions
diff --git a/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/AutocryptPeerUpdate.kt b/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/AutocryptPeerUpdate.kt
index 2f610b3e..e6a189b9 100644
--- a/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/AutocryptPeerUpdate.kt
+++ b/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/AutocryptPeerUpdate.kt
@@ -11,99 +11,93 @@ import java.util.Date
public class AutocryptPeerUpdate() : Parcelable {
- private var keyData: ByteArray? = null
- private var effectiveDate: Date? = null
- private lateinit var preferEncrypt: PreferEncrypt
-
- internal constructor(
- keyData: ByteArray?,
- effectiveDate: Date?,
- preferEncrypt: PreferEncrypt
- ) : this() {
- this.keyData = keyData
- this.effectiveDate = effectiveDate
- this.preferEncrypt = preferEncrypt
+ private var keyData: ByteArray? = null
+ private var effectiveDate: Date? = null
+ private lateinit var preferEncrypt: PreferEncrypt
+
+ internal constructor(keyData: ByteArray?, effectiveDate: Date?, preferEncrypt: PreferEncrypt) : this() {
+ this.keyData = keyData
+ this.effectiveDate = effectiveDate
+ this.preferEncrypt = preferEncrypt
+ }
+
+ private constructor(source: Parcel, version: Int) : this() {
+ keyData = source.createByteArray()
+ effectiveDate = if (source.readInt() != 0) Date(source.readLong()) else null
+ preferEncrypt = PreferEncrypt.values()[source.readInt()]
+ }
+
+ public fun createAutocryptPeerUpdate(keyData: ByteArray?, timestamp: Date?): AutocryptPeerUpdate {
+ return AutocryptPeerUpdate(keyData, timestamp, PreferEncrypt.NOPREFERENCE)
+ }
+
+ public fun getKeyData(): ByteArray? {
+ return keyData
+ }
+
+ public fun hasKeyData(): Boolean {
+ return keyData != null
+ }
+
+ public fun getEffectiveDate(): Date? {
+ return effectiveDate
+ }
+
+ public fun getPreferEncrypt(): PreferEncrypt? {
+ return preferEncrypt
+ }
+
+ override fun describeContents(): Int {
+ return 0
+ }
+
+ override fun writeToParcel(dest: Parcel, flags: Int) {
+ /**
+ * NOTE: When adding fields in the process of updating this API, make sure to bump
+ * [.PARCELABLE_VERSION].
+ */
+ dest.writeInt(PARCELABLE_VERSION)
+ // Inject a placeholder that will store the parcel size from this point on
+ // (not including the size itself).
+ val sizePosition = dest.dataPosition()
+ dest.writeInt(0)
+ val startPosition = dest.dataPosition()
+ // version 1
+ dest.writeByteArray(keyData)
+ if (effectiveDate != null) {
+ dest.writeInt(1)
+ dest.writeLong(effectiveDate!!.time)
+ } else {
+ dest.writeInt(0)
}
-
- private constructor(source: Parcel, version: Int) : this() {
- keyData = source.createByteArray()
- effectiveDate = if (source.readInt() != 0) Date(source.readLong()) else null
- preferEncrypt = PreferEncrypt.values()[source.readInt()]
- }
-
- public fun createAutocryptPeerUpdate(
- keyData: ByteArray?,
- timestamp: Date?
- ): AutocryptPeerUpdate {
- return AutocryptPeerUpdate(keyData, timestamp, PreferEncrypt.NOPREFERENCE)
- }
-
- public fun getKeyData(): ByteArray? {
- return keyData
- }
-
- public fun hasKeyData(): Boolean {
- return keyData != null
- }
-
- public fun getEffectiveDate(): Date? {
- return effectiveDate
- }
-
- public fun getPreferEncrypt(): PreferEncrypt? {
- return preferEncrypt
- }
-
- override fun describeContents(): Int {
- return 0
- }
-
- override fun writeToParcel(dest: Parcel, flags: Int) {
- /**
- * NOTE: When adding fields in the process of updating this API, make sure to bump
- * [.PARCELABLE_VERSION].
- */
- dest.writeInt(PARCELABLE_VERSION)
- // Inject a placeholder that will store the parcel size from this point on
- // (not including the size itself).
- val sizePosition = dest.dataPosition()
- dest.writeInt(0)
- val startPosition = dest.dataPosition()
- // version 1
- dest.writeByteArray(keyData)
- if (effectiveDate != null) {
- dest.writeInt(1)
- dest.writeLong(effectiveDate!!.time)
- } else {
- dest.writeInt(0)
- }
- dest.writeInt(preferEncrypt.ordinal)
- // Go back and write the size
- val parcelableSize = dest.dataPosition() - startPosition
- dest.setDataPosition(sizePosition)
- dest.writeInt(parcelableSize)
- dest.setDataPosition(startPosition + parcelableSize)
+ dest.writeInt(preferEncrypt.ordinal)
+ // Go back and write the size
+ val parcelableSize = dest.dataPosition() - startPosition
+ dest.setDataPosition(sizePosition)
+ dest.writeInt(parcelableSize)
+ dest.setDataPosition(startPosition + parcelableSize)
+ }
+
+ public companion object CREATOR : Creator<AutocryptPeerUpdate> {
+
+ private const val PARCELABLE_VERSION = 1
+ override fun createFromParcel(source: Parcel): AutocryptPeerUpdate? {
+ val version = source.readInt() // parcelableVersion
+ val parcelableSize = source.readInt()
+ val startPosition = source.dataPosition()
+ val vr = AutocryptPeerUpdate(source, version)
+ // skip over all fields added in future versions of this parcel
+ source.setDataPosition(startPosition + parcelableSize)
+ return vr
}
- public companion object CREATOR : Creator<AutocryptPeerUpdate> {
-
- private const val PARCELABLE_VERSION = 1
- override fun createFromParcel(source: Parcel): AutocryptPeerUpdate? {
- val version = source.readInt() // parcelableVersion
- val parcelableSize = source.readInt()
- val startPosition = source.dataPosition()
- val vr = AutocryptPeerUpdate(source, version)
- // skip over all fields added in future versions of this parcel
- source.setDataPosition(startPosition + parcelableSize)
- return vr
- }
-
- override fun newArray(size: Int): Array<AutocryptPeerUpdate?>? {
- return arrayOfNulls(size)
- }
+ override fun newArray(size: Int): Array<AutocryptPeerUpdate?>? {
+ return arrayOfNulls(size)
}
+ }
- public enum class PreferEncrypt {
- NOPREFERENCE, MUTUAL
- }
+ public enum class PreferEncrypt {
+ NOPREFERENCE,
+ MUTUAL
+ }
}