Skip to content

Commit

Permalink
Made PgpKeyDetails.lastModified as nullable. Refactored code.| #372
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed May 27, 2021
1 parent 4980e51 commit 40768f9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ fun PGPKeyRing.toPgpKeyDetails(): PgpKeyDetails {
}

return PgpKeyDetails(
isFullyDecrypted = keyRingInfo.isFullyDecrypted,
isFullyEncrypted = keyRingInfo.isFullyEncrypted,
privateKey = privateKey,
publicKey = publicKey,
users = keyRingInfo.userIds,
ids = keyIdList,
created = keyRingInfo.creationDate.time,
lastModified = keyRingInfo.lastModified.time,
expiration = keyRingInfo.primaryKeyExpirationDate?.time,
algo = algo)
isFullyDecrypted = keyRingInfo.isFullyDecrypted,
isFullyEncrypted = keyRingInfo.isFullyEncrypted,
privateKey = privateKey,
publicKey = publicKey,
users = keyRingInfo.userIds,
ids = keyIdList,
created = keyRingInfo.creationDate.time,
lastModified = keyRingInfo.lastModified?.time,
expiration = keyRingInfo.primaryKeyExpirationDate?.time,
algo = algo
)
}

@Throws(IOException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ import javax.mail.internet.InternetAddress
* Time: 1:23 PM
* E-mail: [email protected]
*/
data class PgpKeyDetails constructor(@Expose val isFullyDecrypted: Boolean,
@Expose val isFullyEncrypted: Boolean,
@Expose @SerializedName("private") val privateKey: String?,
@Expose @SerializedName("public") val publicKey: String,
@Expose val users: List<String>,
@Expose val ids: List<KeyId>,
@Expose val created: Long,
@Expose val lastModified: Long,
@Expose val expiration: Long? = null,
@Expose val algo: Algo,
var tempPassphrase: CharArray? = null,
var passphraseType: KeyEntity.PassphraseType? = null) : Parcelable {
data class PgpKeyDetails constructor(
@Expose val isFullyDecrypted: Boolean,
@Expose val isFullyEncrypted: Boolean,
@Expose @SerializedName("private") val privateKey: String?,
@Expose @SerializedName("public") val publicKey: String,
@Expose val users: List<String>,
@Expose val ids: List<KeyId>,
@Expose val created: Long,
@Expose val lastModified: Long? = null,
@Expose val expiration: Long? = null,
@Expose val algo: Algo,
var tempPassphrase: CharArray? = null,
var passphraseType: KeyEntity.PassphraseType? = null
) : Parcelable {

val primaryPgpContact: PgpContact
get() = determinePrimaryPgpContact()
Expand All @@ -61,19 +63,20 @@ data class PgpKeyDetails constructor(@Expose val isFullyDecrypted: Boolean,
}

constructor(source: Parcel) : this(
source.readValue(Boolean::class.java.classLoader) as Boolean,
source.readValue(Boolean::class.java.classLoader) as Boolean,
source.readString(),
source.readString() ?: throw IllegalArgumentException("pubkey can't be null"),
source.createStringArrayList() ?: throw NullPointerException(),
source.createTypedArrayList(KeyId.CREATOR) ?: throw NullPointerException(),
source.readLong(),
source.readLong(),
source.readValue(Long::class.java.classLoader) as Long?,
source.readParcelable<Algo>(Algo::class.java.classLoader) ?: throw NullPointerException(),
source.createCharArray(),
source.readParcelable<KeyEntity.PassphraseType>(
KeyEntity.PassphraseType::class.java.classLoader)
source.readValue(Boolean::class.java.classLoader) as Boolean,
source.readValue(Boolean::class.java.classLoader) as Boolean,
source.readString(),
source.readString() ?: throw IllegalArgumentException("pubkey can't be null"),
source.createStringArrayList() ?: throw NullPointerException(),
source.createTypedArrayList(KeyId.CREATOR) ?: throw NullPointerException(),
source.readLong(),
source.readValue(Long::class.java.classLoader) as Long?,
source.readValue(Long::class.java.classLoader) as Long?,
source.readParcelable<Algo>(Algo::class.java.classLoader) ?: throw NullPointerException(),
source.createCharArray(),
source.readParcelable<KeyEntity.PassphraseType>(
KeyEntity.PassphraseType::class.java.classLoader
)
)

override fun describeContents() = 0
Expand All @@ -86,7 +89,7 @@ data class PgpKeyDetails constructor(@Expose val isFullyDecrypted: Boolean,
writeStringList(users)
writeTypedList(ids)
writeLong(created)
writeLong(lastModified)
writeValue(lastModified)
writeValue(expiration)
writeParcelable(algo, flags)
writeCharArray(tempPassphrase)
Expand Down Expand Up @@ -208,7 +211,7 @@ data class PgpKeyDetails constructor(@Expose val isFullyDecrypted: Boolean,
result = 31 * result + users.hashCode()
result = 31 * result + ids.hashCode()
result = 31 * result + created.hashCode()
result = 31 * result + lastModified.hashCode()
result = 31 * result + (lastModified?.hashCode() ?: 0)
result = 31 * result + (expiration?.hashCode() ?: 0)
result = 31 * result + algo.hashCode()
result = 31 * result + (tempPassphrase?.contentHashCode() ?: 0)
Expand Down

1 comment on commit 40768f9

@DenBond7
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actual ref is #1260

Please sign in to comment.